Skip to content

Update README.md

Update README.md #11

Workflow file for this run

name: Initialize README to Step 0
on:
push:
branches:
- main
# Only run on the very first commit (when the repo is created from the template)
# This works because the first commit after template creation is always the initial commit
# Optionally, you can add a path filter if you want to be even more specific
permissions:
contents: write
jobs:
init_readme:
runs-on: ubuntu-latest
if: ${{ github.event.head_commit.message == 'Initial commit' && !github.event.repository.is_template }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check if README already contains Step 0
id: check_readme
run: |
if grep -q "Welcome to the JS AI Build-a-thon" README.md; then
echo "already_step0=true" >> $GITHUB_OUTPUT
else
echo "already_step0=false" >> $GITHUB_OUTPUT
fi
- name: Prepare personalized welcome and badge links
if: steps.check_readme.outputs.already_step0 == 'false'
run: |
OWNER="$(echo "${GITHUB_REPOSITORY}" | cut -d'/' -f1)"
REPO="$(echo "${GITHUB_REPOSITORY}" | cut -d'/' -f2)"
OWNER_REPO="${GITHUB_REPOSITORY}"
cp .github/steps/0-welcome.md 0-welcome-tmp.md
sed -i "s/^## Welcome to the JS AI Build-a-thon!/## Welcome ${OWNER}, to the JS AI Build-a-thon!/" 0-welcome-tmp.md
sed -i "s#(\/issues/new?#(https://github.com/${OWNER_REPO}/issues/new?#g" 0-welcome-tmp.md
- name: Copy personalized step 0 to README.md
if: steps.check_readme.outputs.already_step0 == 'false'
run: cp 0-welcome-tmp.md README.md
- name: Rewrite badge links in README.md to absolute URLs
if: steps.check_readme.outputs.already_step0 == 'false'
run: |
OWNER_REPO="${GITHUB_REPOSITORY}"
# Use pipe as delimiter and target the specific pattern ](/issues/new?
# This replaces relative issue links like ](/issues/new?...) with absolute ones
sed -i 's|](/issues/new?|](https://github.com/'"${OWNER_REPO}"'/issues/new?|g' README.md
- name: Commit and push README update
if: steps.check_readme.outputs.already_step0 == 'false'
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add README.md
git commit -m "Initialize README with personalized step 0 instructions"
git push