Repository navigation
feat: add push retry and commit SHA outputs (STS-2383) #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
Merged
whyvez
merged 6 commits into
main
from
feature/STS-2383/add-push-retry-and-commit-sha-outputs
Nov 19, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
32af72e
chore: add Trunk lint config (STS-2383)
whyvez ea98e65
feat: add push retry, sha/base_sha outputs, env-safe inputs (STS-2383)
whyvez 5d7f947
test: add concurrent push workflow (STS-2383)
whyvez ded52ad
docs: document inputs, outputs and concurrency (STS-2383)
whyvez f4f5e52
ci: add lint workflow for required check (STS-2383)
whyvez 836318d
fix: pin yq version to avoid GitHub API rate limit (STS-2383)
whyvez 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,29 @@ | ||
| name: lint | ||
|
|
||
| on: | ||
| pull_request: | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| permissions: {} | ||
|
|
||
| jobs: | ||
| # The job name must stay `lint`: the Default ruleset requires a check with that exact name. | ||
| lint: | ||
| name: lint | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| actions: read # for trunk-action | ||
| checks: write # for trunk-action | ||
| contents: read # for checkout + trunk-action | ||
| steps: | ||
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
| with: | ||
| # Trunk needs the merge-base to lint only the PR diff. | ||
| fetch-depth: 0 | ||
| persist-credentials: false | ||
|
|
||
| - name: Trunk Check | ||
| uses: trunk-io/trunk-action@04ba50e7658c81db7356da96657e6e77f220bfa3 # v1.3.1 |
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,80 @@ | ||
| name: test | ||
|
|
||
| on: | ||
| pull_request: | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: write | ||
|
|
||
| env: | ||
| BRANCH: test/gitops-${{ github.run_id }}-${{ github.run_attempt }} | ||
| FIXTURE: test/fixtures/values.yaml | ||
|
|
||
| jobs: | ||
| setup: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
|
|
||
| - name: Create scratch branch | ||
| run: git push origin "HEAD:refs/heads/${BRANCH}" | ||
|
|
||
| update: | ||
| needs: setup | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| job: [a, b] | ||
| steps: | ||
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
|
|
||
| - name: GitOps Update | ||
| id: gitops | ||
| uses: ./ | ||
| with: | ||
| new_value: ${{ github.run_id }}-${{ matrix.job }} | ||
| yaml_key_paths: .${{ matrix.job }}.tag | ||
| yaml_file_path: ${{ env.FIXTURE }} | ||
| commit_message: 'test ${{ matrix.job }} "quoted" $(echo pwned)' | ||
| target_branch: ${{ env.BRANCH }} | ||
|
|
||
| - name: Check outputs | ||
| env: | ||
| SHA: ${{ steps.gitops.outputs.sha }} | ||
| BASE_SHA: ${{ steps.gitops.outputs.base_sha }} | ||
| EXPECTED_MESSAGE: 'ci(gitops): test ${{ matrix.job }} "quoted" $(echo pwned)' | ||
| run: | | ||
| git fetch --depth=2 origin "$SHA" | ||
| test "$(git rev-parse "${SHA}~1")" = "$BASE_SHA" | ||
| test "$(git log -1 --format=%s "$SHA")" = "$EXPECTED_MESSAGE" | ||
|
|
||
| verify: | ||
| needs: update | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| RUN_ID: ${{ github.run_id }} | ||
| steps: | ||
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
|
|
||
| - name: Check both commits landed | ||
| run: | | ||
| git fetch origin "$BRANCH" | ||
| git log --format=%s FETCH_HEAD | ||
| for job in a b; do | ||
| git log --format=%s FETCH_HEAD | grep -qxF "ci(gitops): test ${job} \"quoted\" \$(echo pwned)" | ||
| test "$(git show "FETCH_HEAD:${FIXTURE}" | yq ".${job}.tag")" = "${RUN_ID}-${job}" | ||
| done | ||
| # The blank line between keys must survive the yq edit. | ||
| test "$(git show "FETCH_HEAD:${FIXTURE}" | wc -l)" = "$(wc -l < "$FIXTURE")" | ||
|
|
||
| cleanup: | ||
| needs: [setup, verify] | ||
| if: always() && needs.setup.result == 'success' | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
|
|
||
| - name: Delete scratch branch | ||
| run: git push origin --delete "$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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| *out | ||
| *logs | ||
| *actions | ||
| *notifications | ||
| *tools | ||
| plugins | ||
| user_trunk.yaml | ||
| user.yaml | ||
| tmp |
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,2 @@ | ||
| # Prettier friendly markdownlint config (all formatting rules disabled) | ||
| extends: markdownlint/style/prettier |
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,7 @@ | ||
| enable=all | ||
| source-path=SCRIPTDIR | ||
| disable=SC2154 | ||
|
|
||
| # If you're having issues with shellcheck following source, disable the errors via: | ||
| # disable=SC1090 | ||
| # disable=SC1091 |
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,7 @@ | ||
| rules: | ||
| quoted-strings: | ||
| required: only-when-needed | ||
| extra-allowed: ["{|}"] | ||
| key-duplicates: {} | ||
| octal-values: | ||
| forbid-implicit-octal: true |
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,36 @@ | ||
| # This file controls the behavior of Trunk: https://docs.trunk.io/cli | ||
| # To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml | ||
| version: 0.1 | ||
| cli: | ||
| version: 1.29.0 | ||
| # Trunk provides extensibility via plugins. (https://docs.trunk.io/plugins) | ||
| plugins: | ||
| sources: | ||
| - id: trunk | ||
| ref: v1.11.0 | ||
| uri: https://github.com/trunk-io/plugins | ||
| # Many linters and tools depend on runtimes - configure them here. (https://docs.trunk.io/runtimes) | ||
| runtimes: | ||
| enabled: | ||
| - [email protected] | ||
| - [email protected] | ||
| # This is the section where you manage your linters. (https://docs.trunk.io/check/configuration) | ||
| lint: | ||
| enabled: | ||
| - [email protected] | ||
| - [email protected] | ||
| - [email protected] | ||
| - [email protected] | ||
| - [email protected] | ||
| - git-diff-check | ||
| - [email protected] | ||
| - [email protected] | ||
| - [email protected] | ||
| - [email protected] | ||
| actions: | ||
| disabled: | ||
| - trunk-announce | ||
| - trunk-check-pre-push | ||
| - trunk-fmt-pre-commit | ||
| enabled: | ||
| - trunk-upgrade-available |
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 |
|---|---|---|
| @@ -1,2 +1,57 @@ | ||
| # github-action-gitops-update | ||
| Reusable GitHub Action to update a YAML file and commit the result | ||
|
|
||
| Reusable GitHub Action to update a YAML file and commit the result. | ||
|
|
||
| It sets one or more YAML keys to a new value, commits the change as `ci(gitops): <commit_message>`, and pushes it to `target_branch`. If another run pushed to the branch first, it fetches the latest branch, re-applies the edit and tries again. | ||
|
|
||
| ## Usage | ||
|
|
||
| ```yaml | ||
| permissions: | ||
| contents: write | ||
|
|
||
| jobs: | ||
| gitops-update: | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| sha: ${{ steps.gitops.outputs.sha }} | ||
| steps: | ||
| - name: GitOps Update and Commit | ||
| id: gitops | ||
| uses: masterpointio/github-action-gitops-update@<commit-sha> # vX.Y.Z | ||
| with: | ||
| new_value: ${{ inputs.image_tag }} | ||
| yaml_key_paths: .components.terraform.my-app.vars.image_tag | ||
| yaml_file_path: stacks/org/dev/us-east-1.yaml | ||
| commit_message: "update my-app image_tag to ${{ inputs.image_tag }}" | ||
| ``` | ||
|
|
||
| ## Inputs | ||
|
|
||
| | Name | Required | Default | Description | | ||
| | ----------------- | -------- | ----------------------------------------------- | ---------------------------------------------------------------- | | ||
| | `new_value` | yes | | New value for the given YAML keys | | ||
| | `yaml_key_paths` | yes | | Comma-separated list of yq paths to update, e.g. `.a.tag,.b.tag` | | ||
| | `yaml_file_path` | yes | | Path to the YAML file to update | | ||
| | `commit_message` | yes | | Commit message, prefixed with `ci(gitops):` | | ||
| | `commit_username` | no | `github-actions` | Commit author name | | ||
| | `commit_email` | no | `[email protected]` | Commit author email | | ||
| | `target_branch` | no | `${{ github.event.repository.default_branch }}` | Branch to push to | | ||
| | `github_token` | no | `${{ github.token }}` | Token used to push (needed when the target branch is protected) | | ||
| | `max_attempts` | no | `5` | Number of times to retry the push when the target branch moved | | ||
|
|
||
| ## Outputs | ||
|
|
||
| | Name | Description | | ||
| | ---------- | --------------------------------------------------------------------- | | ||
| | `sha` | SHA of the pushed commit | | ||
| | `base_sha` | SHA of the pushed commit's parent (`target_branch` before the update) | | ||
|
|
||
| ## Concurrency | ||
|
|
||
| Runs that target the same branch at the same time are safe: each push that is rejected is retried on top of the latest branch, with a short random delay. Don't put callers in a shared `concurrency` group to serialize them, because GitHub cancels older pending runs in a group and those updates are lost. | ||
|
|
||
| ## Notes | ||
|
|
||
| - yq removes blank lines when it writes a file, so the action applies yq's output through `diff -B | patch` to keep them. A blank line directly next to an edited key can still be removed. | ||
| - If the value is unchanged, the action still pushes an empty commit. |
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,7 @@ | ||
| a: | ||
| tag: initial | ||
| name: a | ||
|
|
||
| b: | ||
| name: b | ||
| tag: initial |
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.