Skip to content

Build script catalog #5

Build script catalog

Build script catalog #5

Workflow file for this run

name: Build script catalog
# Manually regenerates index.json - the catalog PaletteShell's in-palette "Browse community
# scripts" page fetches - from whatever is actually under scripts/. Contributors never touch
# index.json themselves; run this workflow when the committed catalog should be refreshed.
on:
workflow_dispatch: {}
permissions:
contents: write
pull-requests: write
concurrency:
group: build-index-${{ github.ref }}
cancel-in-progress: true
jobs:
build-index:
runs-on: ubuntu-latest
steps:
# Full history (not the default shallow depth-1 clone) - Build-Index.ps1 runs `git log`
# per script to record each file's last-modified commit date, which needs the actual
# history to be present, not just the tip commit.
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
# Manual runs are restricted to codeowners (.github/CODEOWNERS).
- name: Restrict manual runs to codeowners
env:
ACTOR: ${{ github.actor }}
run: |
if ! grep -qiE "@${ACTOR}([[:space:]]|$)" .github/CODEOWNERS; then
echo "::error::Manual runs of this workflow are restricted to codeowners. '${ACTOR}' is not listed in .github/CODEOWNERS."
exit 1
fi
- name: Build index.json
shell: pwsh
run: ./tools/Build-Index.ps1
- name: Check for changes
id: diff
run: |
git add index.json
if git diff --cached --quiet; then
echo "changed=false" >> "$GITHUB_OUTPUT"
else
echo "changed=true" >> "$GITHUB_OUTPUT"
fi
- name: Open catalog update pull request
if: steps.diff.outputs.changed == 'true'
env:
GH_TOKEN: ${{ github.token }}
UPDATE_BRANCH: automation/update-index-json
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git switch -c "$UPDATE_BRANCH"
git commit -m "Update index.json"
git push --force-with-lease origin "$UPDATE_BRANCH"
existing_pr="$(gh pr list --base main --head "$UPDATE_BRANCH" --state open --json number --jq '.[0].number')"
if [ -z "$existing_pr" ]; then
gh pr create \
--base main \
--head "$UPDATE_BRANCH" \
--title "Update index.json" \
--body "Regenerates index.json from the current scripts catalog."
else
echo "Updated existing pull request #$existing_pr."
fi