Skip to content

feat(examples): Add GitHub Action to update Outpost version in compose.yml #365

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 1 commit into from
May 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions .github/workflows/update-compose-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Update Outpost Version in compose.yml

on:
release:
types: [published]
workflow_dispatch:

jobs:
update-version:
runs-on: ubuntu-latest
# Prevent running on forks for release trigger to avoid duplicate runs
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'release' && !github.event.release.prerelease)

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# We need to fetch all history for gh release list and to push
fetch-depth: 0
# For pushing changes back
token: ${{ secrets.GITHUB_TOKEN }} # Or a PAT with write access if GITHUB_TOKEN is not enough

- name: Determine Version
id: get_version
run: |
if [[ "${{ github.event_name }}" == "release" ]]; then
VERSION="${{ github.event.release.tag_name }}"
echo "Using release version: $VERSION"
elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "Fetching latest release version..."
# Ensure gh is installed (usually available on GitHub runners)
# This command fetches the latest non-prerelease, non-draft release tag
VERSION=$(gh release list --repo "${{ github.repository }}" --limit 1 --exclude-drafts --exclude-pre-releases --json tagName --jq '.[0].tagName')
if [[ -z "$VERSION" ]]; then
echo "Error: Could not fetch latest release version."
exit 1
fi
echo "Using latest fetched version: $VERSION"
else
echo "Error: Unknown event type."
exit 1
fi
# Remove 'v' prefix if present, as the compose file doesn't use it in the example, but releases usually do.
# Adjust if your compose file expects 'v'
VERSION_NO_V=${VERSION#v}
echo "Version without 'v': $VERSION_NO_V"
echo "version_tag=$VERSION_NO_V" >> $GITHUB_OUTPUT

- name: Update compose.yml
run: |
VERSION_TO_USE="${{ steps.get_version.outputs.version_tag }}"
echo "Updating compose.yml with version: $VERSION_TO_USE"
# Using a temporary file for sed to avoid issues with in-place editing on different sed versions
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
Copy link
Preview

Copilot AI May 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider using the '-E' flag with sed to enable extended regular expressions explicitly, which can improve readability and ensure compatibility across different environments.

Suggested change
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
sed -E "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

Copilot uses AI. Check for mistakes.

mv examples/docker-compose/compose.yml.tmp examples/docker-compose/compose.yml
echo "compose.yml updated."
cat examples/docker-compose/compose.yml

- name: Create Pull Request
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'

VERSION_TAG="${{ steps.get_version.outputs.version_tag }}"
BRANCH_NAME="ci/update-compose-version-$VERSION_TAG"

git checkout -b "$BRANCH_NAME"
git add examples/docker-compose/compose.yml

# Check if there are changes to commit
if git diff --staged --quiet; then
echo "No changes to commit. Branch $BRANCH_NAME will not be created or pushed."
else
COMMIT_MESSAGE="ci: Update outpost version in compose.yml to $VERSION_TAG"
git commit -m "$COMMIT_MESSAGE"
git push origin "$BRANCH_NAME"

echo "Changes committed and pushed to branch $BRANCH_NAME."

gh pr create \
--base main \
--head "$BRANCH_NAME" \
--title "$COMMIT_MESSAGE" \
--body "Automated PR to update outpost version in compose.yml to $VERSION_TAG."
echo "Pull request created."
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}