diff --git a/.github/workflows/upstream-sync.yml b/.github/workflows/upstream-sync.yml index 8519c95..b79cba2 100644 --- a/.github/workflows/upstream-sync.yml +++ b/.github/workflows/upstream-sync.yml @@ -40,7 +40,14 @@ jobs: - name: Pull the API spec and the screen catalog id: sync + env: + # The API repo is private; the default GITHUB_TOKEN can't read it. + GH_TOKEN: ${{ secrets.SYNC_TOKEN }} run: | + if [ -z "$GH_TOKEN" ]; then + echo "::error::SYNC_TOKEN is not set. Add a fine-grained token with Contents: read on CompositeCode/substratalapps.com (and Contents + Pull requests: write on this repo)." + exit 1 + fi api=$(scripts/sync-openapi.sh) ruby scripts/import-screens.rb https://specs.substratalapps.com/spec/ echo "api=$api" >> "$GITHUB_OUTPUT" diff --git a/scripts/sync-openapi.sh b/scripts/sync-openapi.sh index 1302f2c..505e3a7 100755 --- a/scripts/sync-openapi.sh +++ b/scripts/sync-openapi.sh @@ -8,6 +8,8 @@ # SOURCE is a path or URL to openapi.yaml. Default: the API repo's main branch, # which is what production runs (main deploys on merge). Writes # Packages/SubstratalKit/Sources/SubstratalAPI/openapi.yaml. +# The API repo is private: set GH_TOKEN (or GITHUB_TOKEN) to a token that can +# read it, or curl gets a 404. # Prints the spec's info.version. Exits 0 with "unchanged" when nothing moved, # so the scheduled workflow can decide whether to open a pull request. set -euo pipefail @@ -19,7 +21,10 @@ APP_COPY="$ROOT/Packages/SubstratalKit/Sources/SubstratalAPI/openapi.yaml" tmp="$(mktemp)" trap 'rm -f "$tmp"' EXIT if [[ "$SOURCE" =~ ^https?:// ]]; then - curl -fsSL "$SOURCE" -o "$tmp" + token="${GH_TOKEN:-${GITHUB_TOKEN:-}}" + auth=() + [[ -n "$token" && "$SOURCE" == https://raw.githubusercontent.com/* ]] && auth=(-H "Authorization: Bearer $token") + curl -fsSL "${auth[@]+"${auth[@]}"}" "$SOURCE" -o "$tmp" else cp "$SOURCE" "$tmp" fi