diff --git a/.github/workflows/commit_artifact.yml b/.github/workflows/commit_artifact.yml new file mode 100644 index 00000000..7371a65b --- /dev/null +++ b/.github/workflows/commit_artifact.yml @@ -0,0 +1,105 @@ +name: commit_artifact + +# Commits files that an earlier job of the calling run uploaded as an artifact, +# through bot-commit and the CI bot's app token. Lets the heavy work run on a +# free runner: only this job calls the GitHub API, which the org IP allow list +# permits from the static-IP runners alone. +# +# The artifact must keep each file's path from the repository root. An +# upload-artifact `path` that starts with a wildcard, such as +# `**/test/**/goldens/**/*.png`, does. +# +# commit: +# needs: render +# uses: GetStream/stream-core-flutter/.github/workflows/commit_artifact.yml@ +# with: +# artifact: goldens +# files: "**/test/**/goldens/**/*.png" +# message: "chore: update goldens" +# client-id: ${{ vars.FLUTTER_CI_BOT_CLIENT_ID }} +# secrets: +# private-key: ${{ secrets.FLUTTER_CI_BOT_PRIVATE_KEY }} + +on: + workflow_call: + inputs: + artifact: + description: The artifact of the calling run that holds the files. + type: string + required: true + files: + description: The files that may be committed, as bot-commit's `files`. + type: string + required: true + message: + description: The commit message; lines after the first become its body. + type: string + required: true + client-id: + description: The client ID of the GitHub App that commits. + type: string + required: true + branch: + description: The branch to commit to. Defaults to the pull request's head branch, or the run's branch. + type: string + required: false + default: "" + expected-head-sha: + description: The commit the files were made on; nothing is committed if the branch moved past it. + type: string + required: false + default: "" + secrets: + private-key: + description: The private key of the GitHub App that commits. + required: true + outputs: + changed: + description: "`true` when there was something to commit." + value: ${{ jobs.commit.outputs.changed }} + commit: + description: The new commit; empty when there was nothing to commit or the branch moved. + value: ${{ jobs.commit.outputs.commit }} + moved: + description: "`true` when the branch moved past `expected-head-sha`, so nothing was committed." + value: ${{ jobs.commit.outputs.moved }} + +permissions: + contents: read + +jobs: + commit: + name: Commit Files + runs-on: + group: github-public-amd64 + timeout-minutes: 5 + outputs: + changed: ${{ steps.commit.outputs.changed }} + commit: ${{ steps.commit.outputs.commit }} + moved: ${{ steps.commit.outputs.moved }} + steps: + - name: 🔑 Mint CI Bot Token + id: ci-bot-token + uses: actions/create-github-app-token@f418cff399f7aef4c2f0ad47e25ca7a6abbdd6fc # v3.4.0 + with: + client-id: ${{ inputs.client-id }} + private-key: ${{ secrets.private-key }} + # Only what bot-commit needs, whatever else the app may do. + permission-contents: write + + - name: 📥 Download Files + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + name: ${{ inputs.artifact }} + + # By repository path: `./` would resolve against the calling repository. + - name: 📤 Commit + id: commit + uses: GetStream/stream-core-flutter/.github/actions/bot-commit@ab35fa04fb78eabde311daabadc4ecccdbbd677e + with: + files: ${{ inputs.files }} + message: ${{ inputs.message }} + token: ${{ steps.ci-bot-token.outputs.token }} + branch: ${{ inputs.branch || github.head_ref || github.ref_name }} + expected-head-sha: ${{ inputs.expected-head-sha || github.event.pull_request.head.sha || github.sha }} + detect-changes: "false" diff --git a/.github/workflows/update_goldens.yml b/.github/workflows/update_goldens.yml index f2ac7b52..4750473a 100644 --- a/.github/workflows/update_goldens.yml +++ b/.github/workflows/update_goldens.yml @@ -5,14 +5,21 @@ on: workflow_dispatch permissions: contents: read +# A newer run on the same branch replaces an older one; the older one's commit +# would be refused anyway once the branch moves. +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: # Renders on a free runner, the one `test` in stream_core_flutter_workflow.yml # compares on; change both together. render: name: Render Goldens runs-on: ubuntu-latest + timeout-minutes: 20 steps: - - name: 📚 Checkout branch + - name: 📚 Checkout uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false @@ -28,7 +35,7 @@ jobs: - name: 📦 Install Tools run: flutter pub global activate melos - - name: 🔧 Bootstrap Workspace + - name: 🧩 Bootstrap Workspace run: melos bootstrap --verbose - name: 🖼️ Update Goldens @@ -43,37 +50,14 @@ jobs: if-no-files-found: error retention-days: 1 - # Committing calls the GitHub API, which the org IP allow list only permits - # from the static-IP runners. commit: name: Commit Goldens needs: render - runs-on: - group: github-public-amd64 - steps: - - name: 🔑 Mint CI Bot Token - id: ci-bot-token - uses: actions/create-github-app-token@f418cff399f7aef4c2f0ad47e25ca7a6abbdd6fc # v3.4.0 - with: - client-id: ${{ vars.FLUTTER_CI_BOT_CLIENT_ID }} - private-key: ${{ secrets.FLUTTER_CI_BOT_PRIVATE_KEY }} - - # Only for the local bot-commit action. - - name: 📚 Checkout actions - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - persist-credentials: false - sparse-checkout: .github/actions - - - name: 📥 Download Goldens - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 - with: - name: goldens - - - name: 📤 Commit Changes - uses: ./.github/actions/bot-commit - with: - files: "**/test/**/goldens/**/*.png" - message: "chore: Update Goldens" - token: ${{ steps.ci-bot-token.outputs.token }} - detect-changes: "false" + uses: ./.github/workflows/commit_artifact.yml + with: + artifact: goldens + files: "**/test/**/goldens/**/*.png" + message: "chore: Update Goldens" + client-id: ${{ vars.FLUTTER_CI_BOT_CLIENT_ID }} + secrets: + private-key: ${{ secrets.FLUTTER_CI_BOT_PRIVATE_KEY }} diff --git a/CLAUDE.md b/CLAUDE.md index f03c5f73..481c2feb 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -68,7 +68,7 @@ file-type assets. The `GetStream` organization has an IP allow list, and it refuses every GitHub API call made with a token from GitHub's standard runners (`ubuntu-latest`, `macos-latest`), reads included; pushing with git is refused too. Checking out (a git read) and OIDC sign-in (Codecov, the Google Cloud deploys) work there. So: - A job that only checks out, builds, tests or deploys outside GitHub runs on a free standard runner. -- A job that calls the GitHub API, or pushes, runs on the static-IP group (`runs-on: { group: github-public-amd64 }`), which is billed per minute. Keep it small: do the heavy work in a free job and hand the result over, as `update_goldens.yml` and `pr_web_build.yml` do. `bot-commit` and `flutter-web-pr-comment` are such calls. +- A job that calls the GitHub API, or pushes, runs on the static-IP group (`runs-on: { group: github-public-amd64 }`), which is billed per minute. Keep it small: do the heavy work in a free job and hand the result over, as `update_goldens.yml` and `pr_web_build.yml` do. `bot-commit` and `flutter-web-pr-comment` are such calls; to commit files a free job made, upload them as an artifact and call the reusable `commit_artifact.yml`. - To skip work for unrelated changes, use the reusable `detect_changes.yml`, which diffs with git, not `dorny/paths-filter`, which calls the API on pull requests. A gate's dependent job should still run when the gate fails, since a skipped required check passes; see the example in its header. Pin every action to a full commit SHA with its version in a comment; Dependabot (`.github/dependabot.yml`) bumps them weekly.