Repository navigation
feat(web3): pin the n8n task runners to the n8n version automatically #653
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| --- | ||
| # n8n's external task runners must run the same version as n8n. Renovate | ||
| # updates only the n8n image (renovate.json disables n8nio/runners), so this | ||
| # workflow pins n8nio/runners to the same tag on Renovate's n8n branch: | ||
| # | ||
| # 1. Renovate pushes renovate/n8n with a new n8n tag. Until this workflow | ||
| # has run, ci/n8n-versions-check.sh fails the required yamllint check, | ||
| # so neither a person nor Renovate's automerge can merge it. | ||
| # 2. This workflow runs ci/n8n-sync-runners.sh and pushes the result. Its | ||
| # commits are listed in renovate.json's gitIgnoredAuthors, so Renovate | ||
| # keeps managing the branch, and recreates the commit by triggering this | ||
| # workflow again whenever it rebases. | ||
| # 3. It pushes with the N8N_SYNC_TOKEN secret, not GITHUB_TOKEN: a push made | ||
| # with GITHUB_TOKEN starts no workflows, and a dispatched Validate run | ||
| # cannot satisfy the pull request's required checks. With this token the | ||
| # push runs Validate on pull_request as usual. It also runs this workflow | ||
| # once more, which finds nothing to change. | ||
| # | ||
| # N8N_SYNC_TOKEN is a fine-grained personal access token (or a GitHub App | ||
| # installation token) limited to this repository, with Contents: read and | ||
| # write. | ||
| # | ||
| # When the runners tag is not on Docker Hub yet, the sync fails and the pull | ||
| # request stays blocked; rerun this workflow once the tag exists. | ||
|
|
||
| name: Sync n8n task runners | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - renovate/n8n | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: n8n-sync-runners-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| sync: | ||
| name: Pin n8nio/runners to the n8n version | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 5 | ||
| steps: | ||
| - name: Require N8N_SYNC_TOKEN | ||
| env: | ||
| N8N_SYNC_TOKEN: ${{ secrets.N8N_SYNC_TOKEN }} | ||
| run: | | ||
| if [ -z "$N8N_SYNC_TOKEN" ]; then | ||
| echo "::error::The N8N_SYNC_TOKEN secret is not set; see the header of this workflow." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| token: ${{ secrets.N8N_SYNC_TOKEN }} | ||
| persist-credentials: true # the commit step pushes with this token | ||
|
|
||
| - name: Pin n8nio/runners | ||
| run: ci/n8n-sync-runners.sh | ||
|
|
||
| - name: Commit and push | ||
| env: | ||
| BRANCH: ${{ github.ref_name }} | ||
| run: | | ||
| if git diff --quiet; then | ||
| echo "n8nio/runners already matches n8n" | ||
| exit 0 | ||
| fi | ||
| git config user.name 'github-actions[bot]' | ||
| git config user.email '41898282+github-actions[bot]@users.noreply.github.com' | ||
| git commit -am "chore(deps): pin n8nio/runners to the n8n version" | ||
| git push origin "HEAD:$BRANCH" | ||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #!/usr/bin/env bash | ||
| # Pin n8nio/runners to the version of the n8n image, with the digest Docker Hub | ||
| # serves for that tag. Renovate updates only the n8n image; this is run on its | ||
| # branch by .github/workflows/n8n-sync-runners.yml, and by hand after editing | ||
| # the n8n tag. Fails without changing anything when the runners tag does not | ||
| # exist yet. | ||
| # | ||
| # Usage: ci/n8n-sync-runners.sh [COMPOSE_FILE] | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| compose="${1:-web3/containers/n8n/docker-compose.yml}" | ||
|
|
||
| version=$(sed -nE 's#^[[:space:]]*image:[[:space:]]*ghcr\.io/thundersquared/n8n:([^@[:space:]]+).*#\1#p' "$compose") | ||
| if [ -z "$version" ]; then | ||
| echo "$compose: no ghcr.io/thundersquared/n8n image found" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| token=$(curl -fsS "https://auth.docker.io/token?service=registry.docker.io&scope=repository:n8nio/runners:pull" | jq -r .token) | ||
| headers=$(curl -fsSI \ | ||
| -H "Authorization: Bearer $token" \ | ||
| -H 'Accept: application/vnd.oci.image.index.v1+json, application/vnd.docker.distribution.manifest.list.v2+json' \ | ||
| "https://registry-1.docker.io/v2/n8nio/runners/manifests/$version") || headers= | ||
| digest=$(printf '%s\n' "$headers" | tr -d '\r' | | ||
| sed -nE 's#^docker-content-digest:[[:space:]]*(sha256:[0-9a-f]{64})$#\1#Ip') | ||
| if [ -z "$digest" ]; then | ||
| echo "n8nio/runners:$version not found on Docker Hub" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| sed -i -E "s#^([[:space:]]*image:[[:space:]]*n8nio/runners:)[^[:space:]]+#\1$version@$digest#" "$compose" | ||
| echo "n8nio/runners pinned to $version@$digest" |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #!/usr/bin/env bash | ||
| # Fail unless n8n and its external task runners are pinned to the same | ||
| # version. The runners must run n8n's own version. Renovate updates only the | ||
| # n8n image, and .github/workflows/n8n-sync-runners.yml then pins the runners | ||
| # to match, so this check fails a pull request until that has happened. | ||
| # | ||
| # Usage: ci/n8n-versions-check.sh [COMPOSE_FILE...] | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| if [ "$#" -eq 0 ]; then | ||
| set -- web3/containers/n8n/docker-compose.yml | ||
| fi | ||
|
|
||
| # tag FILE IMAGE: the tag of IMAGE pinned in FILE, without the digest. | ||
| tag() { | ||
| sed -nE "s#^[[:space:]]*image:[[:space:]]*$2:([^@[:space:]]+).*#\1#p" "$1" | ||
| } | ||
|
|
||
| status=0 | ||
| for compose in "$@"; do | ||
| n8n=$(tag "$compose" 'ghcr\.io/thundersquared/n8n') | ||
| runners=$(tag "$compose" 'n8nio/runners') | ||
| if [ -z "$n8n" ] || [ -z "$runners" ]; then | ||
| echo "$compose: could not find both the n8n and the n8nio/runners image" >&2 | ||
| status=1 | ||
| elif [ "$n8n" != "$runners" ]; then | ||
| echo "$compose: n8n is $n8n but its task runners are $runners; run ci/n8n-sync-runners.sh" >&2 | ||
| status=1 | ||
| else | ||
| echo "$compose: n8n and task runners both at $n8n" | ||
| fi | ||
| done | ||
| exit "$status" |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.