Skip to content

Commit 7d627e7

Browse files
committed
PPNA-5781 Simplify all of that
1 parent 11c1f3e commit 7d627e7

2 files changed

Lines changed: 25 additions & 77 deletions

File tree

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -746,44 +746,44 @@ Main idea is to automate bumping explicit tmp images in stack repo to allow test
746746

747747
**How It Works:**
748748

749-
For **dev branch commits**: When a commit is pushed to the configured development branch, it generates a version string like `tmp-cf3ebd52` and triggers the `update-service-version.yaml` workflow in the target repository. Commits that contain a GitHub Actions skip directive such as `[skip ci]`, `[ci skip]`, `[no ci]`, `[skip actions]`, `[actions skip]`, or the `skip-checks: true` trailer are ignored, including when this action is called from a `workflow_run` workflow.
749+
For **dev branch commits**: When a commit is pushed to the configured development branch and the image build succeeds, it generates a version string like `tmp-cf3ebd52` and triggers the `update-service-version.yaml` workflow in the target repository.
750750

751-
For **tags**: When a tag is created, it extracts the tag name (e.g., `1.32.4`) and checks if the tagged commit exists in the configured development branch using `git merge-base --is-ancestor`. If the commit exists in that branch, it triggers the workflow with the tag name as version. If not, it skips triggering (assumes a hotfix released from `master` that has not been merged back yet). Tagged commits are also skipped if their commit message contains a GitHub Actions skip directive.
752-
753-
For **other branches**: The action skips version updates. This is useful when it is called from a `workflow_run` workflow that observes builds for every branch, but should only bump versions for the configured development branch and release tags.
751+
For **tags**: When a tag is created, it extracts the tag name (e.g., `1.32.4`) and checks if the tagged commit exists in the configured development branch using `git merge-base --is-ancestor`. If the commit exists in that branch, it triggers the workflow with the tag name as version. If not, it skips triggering (assumes a hotfix released from `master` that has not been merged back yet).
754752

755753
#### Usage
756754

757-
```yaml .github/workflows/version_update.yaml
758-
name: Trigger version update
755+
```yaml .github/workflows/build_and_push.yaml
756+
name: Build and push the image
759757
760758
on:
761-
workflow_run:
762-
# Name of the workflow that has to finish to trigger the version update
763-
workflows: ["Build and Test"]
764-
types:
765-
- completed
759+
push:
766760
767761
# explicitly limit action permissions
768762
permissions:
769763
contents: read
770764
771765
jobs:
772-
trigger-update:
766+
build-and-trigger:
773767
runs-on: ubuntu-latest
774-
if: ${{ github.event.workflow_run.conclusion == 'success' }}
775768
steps:
769+
- name: Check out repository code
770+
uses: actions/checkout@v4
771+
772+
- name: Build and push image
773+
run: ./build-and-push-image.sh
774+
776775
- name: Trigger version update
776+
if: ${{ github.ref_name == github.event.repository.default_branch || startsWith(github.ref, 'refs/tags/') }}
777777
uses: PiwikPRO/actions/version-update/trigger@master
778778
with:
779779
service-name: reporting
780-
dev-branch: develop
780+
dev-branch: ${{ github.event.repository.default_branch }}
781781
target-repo: Promil-stack-analytics
782782
# Requires fine-grained PAT with "Actions: Read and write" permission as WORKFLOW_TRIGGER_TOKEN
783783
workflow-token: ${{ secrets.WORKFLOW_TRIGGER_TOKEN }}
784784
```
785785

786-
This example works when `Build and Test` runs on every push, including tags. The action itself only triggers version updates for commits on the configured `dev-branch` and for tags whose commits are already present in that branch.
786+
Place the action after the step that builds and pushes the image. This way version updates are only triggered after a successful image build, and skipped workflows do not need any extra handling inside the action. In the calling workflow, gate the step so it only runs for the development branch and for tags.
787787

788788
#### Inputs
789789

version-update/trigger/action.yaml

Lines changed: 10 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -24,76 +24,34 @@ runs:
2424
- name: Checkout repository
2525
uses: actions/checkout@v6
2626
with:
27-
ref: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_sha || github.ref }}
2827
fetch-depth: 0 # Fetch all history for all branches and tags
2928

3029
- name: Determine version and validate tag
3130
id: version
3231
shell: bash
3332
run: |
34-
SOURCE_SHA="${{ github.sha }}"
35-
SOURCE_REF="${{ github.ref }}"
36-
SOURCE_BRANCH="${GITHUB_REF#refs/heads/}"
37-
38-
if [[ "${{ github.event_name }}" == "workflow_run" ]]; then
39-
SOURCE_SHA="${{ github.event.workflow_run.head_sha }}"
40-
SOURCE_BRANCH="${{ github.event.workflow_run.head_branch }}"
41-
42-
if [[ -n "$SOURCE_BRANCH" && "$SOURCE_BRANCH" == "${{ inputs.dev-branch }}" ]]; then
43-
SOURCE_REF="refs/heads/$SOURCE_BRANCH"
44-
else
45-
mapfile -t SOURCE_TAGS < <(git tag --points-at "$SOURCE_SHA")
46-
47-
if [[ ${#SOURCE_TAGS[@]} -gt 0 ]]; then
48-
SOURCE_REF="refs/tags/${SOURCE_TAGS[0]}"
49-
else
50-
SOURCE_REF="refs/heads/$SOURCE_BRANCH"
51-
fi
52-
fi
53-
fi
54-
55-
echo "source_sha=$SOURCE_SHA" >> "$GITHUB_OUTPUT"
56-
echo "source_ref=$SOURCE_REF" >> "$GITHUB_OUTPUT"
57-
echo "source_branch=$SOURCE_BRANCH" >> "$GITHUB_OUTPUT"
58-
59-
COMMIT_MESSAGE="$(git log -1 --pretty=%B "$SOURCE_SHA" 2>/dev/null || true)"
60-
61-
# Match all skip instructions recognized by GitHub Actions.
62-
if printf '%s\n' "$COMMIT_MESSAGE" | grep -Eiq '(^|[^[:alnum:]])\[(skip ci|ci skip|no ci|skip actions|actions skip)\]($|[^[:alnum:]])|(^|[[:space:]])skip-checks:[[:space:]]*true([[:space:]]|$)'; then
63-
echo "⚠️ Commit message contains a GitHub Actions skip directive"
64-
echo "Skipping version update trigger"
65-
echo "should_trigger=false" >> "$GITHUB_OUTPUT"
66-
echo "skip_reason=commit_message_skip_ci" >> "$GITHUB_OUTPUT"
67-
exit 0
68-
fi
69-
70-
if [[ "$SOURCE_REF" == refs/tags/* ]]; then
33+
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
7134
# Extract tag name
72-
TAG="${SOURCE_REF#refs/tags/}"
35+
TAG="${GITHUB_REF#refs/tags/}"
7336
echo "tag=$TAG" >> $GITHUB_OUTPUT
7437
7538
# Check if this tag's commit exists in dev branch
76-
if git merge-base --is-ancestor "$SOURCE_SHA" origin/${{ inputs.dev-branch }}; then
39+
if git merge-base --is-ancestor "${{ github.sha }}" origin/${{ inputs.dev-branch }}; then
7740
echo "✅ Tag $TAG points to a commit that exists in ${{ inputs.dev-branch }} branch"
7841
echo "version=$TAG" >> $GITHUB_OUTPUT
7942
echo "should_trigger=true" >> $GITHUB_OUTPUT
8043
else
8144
echo "⚠️ Tag $TAG does not exist in ${{ inputs.dev-branch }} branch (likely a hotfix tag from master)"
8245
echo "Skipping version update trigger"
8346
echo "should_trigger=false" >> $GITHUB_OUTPUT
84-
echo "skip_reason=tag_not_in_dev_branch" >> "$GITHUB_OUTPUT"
8547
fi
86-
elif [[ "$SOURCE_BRANCH" == "${{ inputs.dev-branch }}" ]]; then
48+
else
8749
# This is a push to the development branch.
88-
SHA=$(echo "$SOURCE_SHA" | cut -c1-7)
50+
SHA=$(echo "${{ github.sha }}" | cut -c1-7)
8951
echo "sha=$SHA" >> $GITHUB_OUTPUT
9052
echo "version=tmp-$SHA" >> $GITHUB_OUTPUT
9153
echo "should_trigger=true" >> $GITHUB_OUTPUT
9254
echo "Version will be: tmp-$SHA"
93-
else
94-
echo "Skipping version update trigger"
95-
echo "should_trigger=false" >> "$GITHUB_OUTPUT"
96-
echo "skip_reason=unsupported_source_ref" >> "$GITHUB_OUTPUT"
9755
fi
9856
9957
- name: Trigger workflow_dispatch in target repository
@@ -127,7 +85,7 @@ runs:
12785
echo "- Version: **${{ steps.version.outputs.version }}**" >> $GITHUB_STEP_SUMMARY
12886
echo "- Target: ${{ inputs.target-repo }}" >> $GITHUB_STEP_SUMMARY
12987
echo "- Triggered by: ${{ github.actor }}" >> $GITHUB_STEP_SUMMARY
130-
echo "- Source commit: \`${{ steps.version.outputs.source_sha }}\`" >> $GITHUB_STEP_SUMMARY
88+
echo "- Source commit: \`${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY
13189
echo "" >> $GITHUB_STEP_SUMMARY
13290
echo "[View workflow runs in target repo →](https://github.com/${{ github.repository_owner }}/${{ inputs.target-repo }}/actions/workflows/update-service-version.yaml)" >> $GITHUB_STEP_SUMMARY
13391
@@ -136,17 +94,7 @@ runs:
13694
shell: bash
13795
run: |
13896
echo "### Version Update Skipped" >> $GITHUB_STEP_SUMMARY
139-
if [[ "${{ steps.version.outputs.skip_reason }}" == "commit_message_skip_ci" ]]; then
140-
echo "⚠️ Source commit message contains a GitHub Actions skip directive." >> $GITHUB_STEP_SUMMARY
141-
echo "" >> $GITHUB_STEP_SUMMARY
142-
echo "Version updates are skipped to avoid bumping an image version when the source image build was intentionally skipped." >> $GITHUB_STEP_SUMMARY
143-
elif [[ "${{ steps.version.outputs.skip_reason }}" == "unsupported_source_ref" ]]; then
144-
echo "ℹ️ Source ref is not the configured development branch and is not a release tag." >> $GITHUB_STEP_SUMMARY
145-
echo "" >> $GITHUB_STEP_SUMMARY
146-
echo "Version updates only run for commits on **${{ inputs.dev-branch }}** or for tags that point to commits already present in that branch." >> $GITHUB_STEP_SUMMARY
147-
else
148-
echo "⚠️ Tag **${{ steps.version.outputs.tag }}** does not exist in ${{ inputs.dev-branch }} branch" >> $GITHUB_STEP_SUMMARY
149-
echo "" >> $GITHUB_STEP_SUMMARY
150-
echo "This is likely a hotfix tag released directly from master." >> $GITHUB_STEP_SUMMARY
151-
echo "Version updates are only triggered for tags that exist in the ${{ inputs.dev-branch }} branch." >> $GITHUB_STEP_SUMMARY
152-
fi
97+
echo "⚠️ Tag **${{ steps.version.outputs.tag }}** does not exist in ${{ inputs.dev-branch }} branch" >> $GITHUB_STEP_SUMMARY
98+
echo "" >> $GITHUB_STEP_SUMMARY
99+
echo "This is likely a hotfix tag released directly from master." >> $GITHUB_STEP_SUMMARY
100+
echo "Version updates are only triggered for tags that exist in the ${{ inputs.dev-branch }} branch." >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)