1+ name : Update Outpost Version in compose.yml
2+
3+ on :
4+ release :
5+ types : [published]
6+ workflow_dispatch :
7+
8+ jobs :
9+ update-version :
10+ runs-on : ubuntu-latest
11+ # Prevent running on forks for release trigger to avoid duplicate runs
12+ if : github.event_name == 'workflow_dispatch' || (github.event_name == 'release' && !github.event.release.prerelease)
13+
14+ steps :
15+ - name : Checkout repository
16+ uses : actions/checkout@v4
17+ with :
18+ # We need to fetch all history for gh release list and to push
19+ fetch-depth : 0
20+ # For pushing changes back
21+ token : ${{ secrets.GITHUB_TOKEN }} # Or a PAT with write access if GITHUB_TOKEN is not enough
22+
23+ - name : Determine Version
24+ id : get_version
25+ run : |
26+ if [[ "${{ github.event_name }}" == "release" ]]; then
27+ VERSION="${{ github.event.release.tag_name }}"
28+ echo "Using release version: $VERSION"
29+ elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
30+ echo "Fetching latest release version..."
31+ # Ensure gh is installed (usually available on GitHub runners)
32+ # This command fetches the latest non-prerelease, non-draft release tag
33+ VERSION=$(gh release list --repo "${{ github.repository }}" --limit 1 --exclude-drafts --exclude-pre-releases --json tagName --jq '.[0].tagName')
34+ if [[ -z "$VERSION" ]]; then
35+ echo "Error: Could not fetch latest release version."
36+ exit 1
37+ fi
38+ echo "Using latest fetched version: $VERSION"
39+ else
40+ echo "Error: Unknown event type."
41+ exit 1
42+ fi
43+ # Remove 'v' prefix if present, as the compose file doesn't use it in the example, but releases usually do.
44+ # Adjust if your compose file expects 'v'
45+ VERSION_NO_V=${VERSION#v}
46+ echo "Version without 'v': $VERSION_NO_V"
47+ echo "version_tag=$VERSION_NO_V" >> $GITHUB_OUTPUT
48+
49+ - name : Update compose.yml
50+ run : |
51+ VERSION_TO_USE="${{ steps.get_version.outputs.version_tag }}"
52+ echo "Updating compose.yml with version: $VERSION_TO_USE"
53+ # Using a temporary file for sed to avoid issues with in-place editing on different sed versions
54+ sed "s|hookdeck/outpost:v[0-9]\+\.[0-9]\+\.[0-9]\+\(-[a-zA-Z0-9.]\+\)\?|hookdeck/outpost:v${VERSION_TO_USE}|g" examples/docker-compose/compose.yml > examples/docker-compose/compose.yml.tmp
55+ mv examples/docker-compose/compose.yml.tmp examples/docker-compose/compose.yml
56+ echo "compose.yml updated."
57+ cat examples/docker-compose/compose.yml
58+
59+ - name : Create Pull Request
60+ run : |
61+ git config --global user.name 'github-actions[bot]'
62+ git config --global user.email 'github-actions[bot]@users.noreply.github.com'
63+
64+ VERSION_TAG="${{ steps.get_version.outputs.version_tag }}"
65+ BRANCH_NAME="ci/update-compose-version-$VERSION_TAG"
66+
67+ git checkout -b "$BRANCH_NAME"
68+ git add examples/docker-compose/compose.yml
69+
70+ # Check if there are changes to commit
71+ if git diff --staged --quiet; then
72+ echo "No changes to commit. Branch $BRANCH_NAME will not be created or pushed."
73+ else
74+ COMMIT_MESSAGE="ci: Update outpost version in compose.yml to $VERSION_TAG"
75+ git commit -m "$COMMIT_MESSAGE"
76+ git push origin "$BRANCH_NAME"
77+
78+ echo "Changes committed and pushed to branch $BRANCH_NAME."
79+
80+ gh pr create \
81+ --base main \
82+ --head "$BRANCH_NAME" \
83+ --title "$COMMIT_MESSAGE" \
84+ --body "Automated PR to update outpost version in compose.yml to $VERSION_TAG."
85+ echo "Pull request created."
86+ fi
87+ env :
88+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments