-
Notifications
You must be signed in to change notification settings - Fork 1
ci: persist dispatched LLGo pins before building #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,8 @@ on: | |
| - ci/llgo-size/publish-site.sh | ||
| - ci/llgo-size/prepare-pages-branch.sh | ||
| - .github/workflows/llgo-binary-size-pages.yml | ||
| # ci/llgo-size/llgo-version.env is intentionally not ignored: changing | ||
| # the committed LLGo pin must trigger a binary-size build. | ||
| pull_request: | ||
| paths-ignore: | ||
| - ci/llgo-size/site/** | ||
|
|
@@ -29,45 +31,79 @@ on: | |
|
|
||
| permissions: | ||
| contents: write | ||
| actions: write | ||
|
|
||
| concurrency: | ||
| group: llgo-binary-size-pages | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| binary-size: | ||
| update-pin: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| if: github.event_name == 'repository_dispatch' | ||
| runs-on: ubuntu-24.04 | ||
| timeout-minutes: 120 | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Read pinned toolchain versions | ||
| - name: Update the committed LLGo pin and start the build | ||
| env: | ||
| DISPATCH_SOURCE_REPOSITORY: ${{ github.event.client_payload.source_repository }} | ||
| DISPATCH_LLGO_REPOSITORY: ${{ github.event.client_payload.llgo_repository }} | ||
| DISPATCH_LLGO_COMMIT: ${{ github.event.client_payload.llgo_commit }} | ||
| GH_TOKEN: ${{ github.token }} | ||
| run: | | ||
| set -euo pipefail | ||
| if [[ "$DISPATCH_SOURCE_REPOSITORY" != "xgo-dev/llgo" || \ | ||
| "$DISPATCH_LLGO_REPOSITORY" != "xgo-dev/llgo" ]]; then | ||
| echo "refusing binary-size dispatch from ${DISPATCH_SOURCE_REPOSITORY:-unknown}" >&2 | ||
| exit 1 | ||
| fi | ||
| if [[ ! "$DISPATCH_LLGO_COMMIT" =~ ^[0-9a-f]{40}$ ]]; then | ||
| echo "invalid dispatched LLGo commit: ${DISPATCH_LLGO_COMMIT:-missing}" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| current_commit="$(awk -F= '$1 == "LLGO_COMMIT" { print $2 }' ci/llgo-size/llgo-version.env)" | ||
| if [[ "$current_commit" == "$DISPATCH_LLGO_COMMIT" ]]; then | ||
| echo "LLGo pin is already $DISPATCH_LLGO_COMMIT; no build needed" | ||
| exit 0 | ||
| fi | ||
|
|
||
| sed -i "s/^LLGO_COMMIT=.*/LLGO_COMMIT=${DISPATCH_LLGO_COMMIT}/" \ | ||
| ci/llgo-size/llgo-version.env | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
| git add ci/llgo-size/llgo-version.env | ||
| git commit -m "ci: pin LLGo ${DISPATCH_LLGO_COMMIT:0:12}" | ||
| git push origin HEAD:main | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Commit-then-dispatch is not atomic. The pin is committed and pushed to |
||
|
|
||
| payload="$(jq -cn \ | ||
| --arg ref main \ | ||
| --arg llgo_commit "$DISPATCH_LLGO_COMMIT" \ | ||
| '{ref: $ref, inputs: {llgo_commit: $llgo_commit}}')" | ||
| curl --fail-with-body --location --request POST \ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dispatch |
||
| --header 'Accept: application/vnd.github+json' \ | ||
| --header "Authorization: Bearer ${GH_TOKEN}" \ | ||
| --header 'X-GitHub-Api-Version: 2022-11-28' \ | ||
| "https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/workflows/llgo-binary-size.yml/dispatches" \ | ||
| --data "$payload" | ||
|
|
||
| binary-size: | ||
| if: github.event_name != 'repository_dispatch' | ||
| runs-on: ubuntu-24.04 | ||
| timeout-minutes: 120 | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Read pinned toolchain versions | ||
| env: | ||
| MANUAL_LLGO_COMMIT: ${{ inputs.llgo_commit }} | ||
| run: | | ||
| set -euo pipefail | ||
| set -a | ||
| source ci/llgo-size/llgo-version.env | ||
| set +a | ||
|
|
||
| # The dispatched SHA is the run's runtime pin and is retained in | ||
| # results.json / Pages. Restrict automatic events to official LLGo. | ||
| if [[ "$GITHUB_EVENT_NAME" == "repository_dispatch" ]]; then | ||
| if [[ "$DISPATCH_SOURCE_REPOSITORY" != "xgo-dev/llgo" || \ | ||
| "$DISPATCH_LLGO_REPOSITORY" != "xgo-dev/llgo" ]]; then | ||
| echo "refusing binary-size dispatch from ${DISPATCH_SOURCE_REPOSITORY:-unknown}" >&2 | ||
| exit 1 | ||
| fi | ||
| if [[ ! "$DISPATCH_LLGO_COMMIT" =~ ^[0-9a-f]{40}$ ]]; then | ||
| echo "invalid dispatched LLGo commit: ${DISPATCH_LLGO_COMMIT:-missing}" >&2 | ||
| exit 1 | ||
| fi | ||
| LLGO_REPOSITORY="$DISPATCH_LLGO_REPOSITORY" | ||
| LLGO_COMMIT="$DISPATCH_LLGO_COMMIT" | ||
| elif [[ -n "$MANUAL_LLGO_COMMIT" ]]; then | ||
| if [[ -n "$MANUAL_LLGO_COMMIT" ]]; then | ||
| if [[ ! "$MANUAL_LLGO_COMMIT" =~ ^[0-9a-f]{40}$ ]]; then | ||
| echo "manual LLGo commit must be a full 40-character SHA" >&2 | ||
| exit 1 | ||
|
|
@@ -173,7 +209,7 @@ jobs: | |
| if-no-files-found: error | ||
|
|
||
| - name: Publish binary-size history to Pages | ||
| if: github.event_name == 'repository_dispatch' || (github.event_name != 'pull_request' && github.ref == 'refs/heads/main') | ||
| if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main' | ||
| env: | ||
| PAGES_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
|
|
@@ -187,7 +223,7 @@ jobs: | |
| "$pages_dir" \ | ||
| ci/llgo-size/site | ||
| deploy-pages: | ||
| if: github.event_name == 'repository_dispatch' || (github.event_name != 'pull_request' && github.ref == 'refs/heads/main') | ||
| if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main' | ||
| needs: binary-size | ||
| runs-on: ubuntu-24.04 | ||
| permissions: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Least privilege: scope
actions: writeto the job that needs it. This is granted at the workflow level, so every job inherits it — includingbinary-size, which builds untrusted LLGo/Bent code onpull_requestevents. Onlyupdate-pinneedsactions: write(for theworkflow_dispatchAPI call). Consider dropping the workflow-level default to the minimum and adding a job-levelpermissions: { contents: write, actions: write }block onupdate-pinonly.