Merge pull request #44 from CU-ESIIL/codex/fix-bootstrap-workflow-yam… #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Bootstrap new repo | |
| on: | |
| push: | |
| branches: ["main"] | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| issues: write | |
| pages: write | |
| id-token: write | |
| jobs: | |
| bootstrap: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out | |
| uses: actions/checkout@v4 | |
| - name: Derive names | |
| id: names | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| REPO="${{ github.event.repository.name }}" | |
| OWNER="${{ github.repository_owner }}" | |
| # Humanize repo name -> Title Case | |
| TITLE="$(python -c 'import os,re; n=os.environ["REPO"]; n=re.sub(r"__", " ", n); n=re.sub(r"[-_]+", " ", n); print(" ".join(w.capitalize() for w in n.split()))')" | |
| # Extract group id (…__N or trailing digits) | |
| GROUP_ID="" | |
| if [[ "$REPO" =~ __([0-9]+)$ ]]; then | |
| GROUP_ID="${BASH_REMATCH[1]}" | |
| elif [[ "$REPO" =~ ([0-9]+)$ ]]; then | |
| GROUP_ID="${BASH_REMATCH[1]}" | |
| fi | |
| { | |
| echo "repo=$REPO" | |
| echo "owner=$OWNER" | |
| echo "title=$TITLE" | |
| echo "group_id=$GROUP_ID" | |
| echo "site_url=https://${OWNER}.github.io/${REPO}/" | |
| } >> "$GITHUB_OUTPUT" | |
| - name: Inject storage link (optional) | |
| id: storage | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| GROUP_ID="${{ steps.names.outputs.group_id }}" | |
| BASE="${{ secrets.COMMUNITY_STORAGE_BASE }}" | |
| if [[ -n "${BASE:-}" && -n "${GROUP_ID:-}" ]]; then | |
| mkdir -p docs/resources | |
| printf "# Shared Storage\n\n- Group folder: %s/%s\n" "$BASE" "$GROUP_ID" > docs/resources/storage.md | |
| echo "has_storage=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "has_storage=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Replace placeholders in mkdocs.yml and docs | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| TITLE='${{ steps.names.outputs.title }}' | |
| SITE_URL='${{ steps.names.outputs.site_url }}' | |
| REPO_URL="https://github.com/${{ github.repository }}" | |
| # mkdocs.yml | |
| if [[ -f mkdocs.yml ]]; then | |
| if grep -qE '^site_name:' mkdocs.yml; then | |
| sed -i.bak "s|^site_name:.*|site_name: \"${TITLE}\"|g" mkdocs.yml | |
| else | |
| printf "\nsite_name: \"%s\"\n" "$TITLE" >> mkdocs.yml | |
| fi | |
| if grep -qE '^site_url:' mkdocs.yml; then | |
| sed -i.bak "s|^site_url:.*|site_url: \"${SITE_URL}\"|g" mkdocs.yml | |
| else | |
| printf "site_url: \"%s\"\n" "$SITE_URL" >> mkdocs.yml | |
| fi | |
| fi | |
| # docs/index.md | |
| if [[ -f docs/index.md ]]; then | |
| awk 'NR==1{ if ($0 ~ /^# /) {$0="# '"${TITLE}"'"} else {print "# '"${TITLE}"'"; print} }1' docs/index.md > docs/index.md.tmp | |
| mv docs/index.md.tmp docs/index.md | |
| STORAGE_FLAG='${{ steps.storage.outputs.has_storage }}' | |
| if [[ "$STORAGE_FLAG" == "true" ]]; then | |
| perl -0777 -pe 's|<!--RESOURCES_START-->.*?<!--RESOURCES_END-->|<!--RESOURCES_START-->\n\n**Repo:** '"${REPO_URL}"' \\n**Shared storage:** See [resources/storage.md](resources/storage.md)\n\n<!--RESOURCES_END-->|s' -i docs/index.md \ | |
| || printf "\n\n<!--RESOURCES_START-->\n\n**Repo:** %s \\n**Shared storage:** See [resources/storage.md](resources/storage.md)\n\n<!--RESOURCES_END-->\n" "$REPO_URL" >> docs/index.md | |
| else | |
| perl -0777 -pe 's|<!--RESOURCES_START-->.*?<!--RESOURCES_END-->|<!--RESOURCES_START-->\n\n**Repo:** '"${REPO_URL}"'\n\n<!--RESOURCES_END-->|s' -i docs/index.md \ | |
| || printf "\n\n<!--RESOURCES_START-->\n\n**Repo:** %s\n\n<!--RESOURCES_END-->\n" "$REPO_URL" >> docs/index.md | |
| fi | |
| fi | |
| - name: Commit bootstrap changes | |
| uses: stefanzweifel/git-auto-commit-action@v5 | |
| with: | |
| commit_message: "chore(bootstrap): set site title/urls and resources" | |
| commit_user_name: "oasis-bot" | |
| commit_user_email: "oasis-bot@users.noreply.github.com" | |
| branch: main | |
| - name: Configure Pages | |
| uses: actions/configure-pages@v5 | |
| - name: Build site with MkDocs | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| pipx install mkdocs-material | |
| mkdocs build --strict --verbose | |
| env: | |
| PYTHONWARNINGS: ignore | |
| - name: Upload artifact | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: site | |
| - name: Deploy to Pages | |
| uses: actions/deploy-pages@v4 | |
| - name: Open a “Setup complete” issue | |
| if: always() | |
| uses: peter-evans/create-issue-from-file@v5 | |
| with: | |
| title: "✅ Repo bootstrap complete" | |
| content-filepath: .github/ISSUE_TEMPLATE/SETUP_COMPLETE.md | |
| labels: setup |