-
Notifications
You must be signed in to change notification settings - Fork 13
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
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,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 | ||
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 }} |
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.
There was a problem hiding this comment.
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.
Copilot uses AI. Check for mistakes.