-
-
Notifications
You must be signed in to change notification settings - Fork 642
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
Add bump-go action #702
Closed
Closed
Add bump-go action #702
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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,23 @@ | ||
name: Bump Go Version | ||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: '0 5 * * *' | ||
|
||
permissions: | ||
contents: write | ||
pull-requests: write | ||
|
||
jobs: | ||
try-bump: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Bump Go Version | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: stable | ||
- name: Open a PR if not up to date | ||
run: ci/bump-go.sh |
This file contains 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 @@ | ||
#!/bin/bash | ||
|
||
REF_BRANCH=master | ||
PR_KEYWORD="[bump-go]" | ||
PR_LABEL="bump-go" | ||
|
||
set -e | ||
|
||
# Check if the working directory is clean | ||
if [ ! -z "$(git status -s -uall)" ]; then | ||
echo "Working directory is not clean" 2>&1 | ||
exit 1 | ||
fi | ||
|
||
# Create the bump-go branch if it doesn't exist | ||
git show-ref --verify --quiet refs/heads/bump-go || git branch -c $REF_BRANCH bump-go | ||
|
||
# The version in the GO_VERSION file | ||
current_version=$(git show $REF_BRANCH:GO_VERSION 2>/dev/null || echo "") | ||
echo "Current version: $current_version" | ||
|
||
# The latest version installed | ||
latest_version=$(go version | sed -E 's/.*go([0-9\.]*).*/\1/') | ||
echo "Installed version: $latest_version" | ||
|
||
# The version already open in a PR | ||
bump_candidate_version=$(git show bump-go:GO_VERSION 2>/dev/null || echo "") | ||
echo "Bump candidate version: $bump_candidate_version" | ||
|
||
# Lookup number of existing PRs | ||
existing_prs=$(gh pr list --state open --base $REF_BRANCH --label "$PR_LABEL" --json "number" | jq -r 'map(.number) | .[]') | ||
|
||
# Check if the version is up to date | ||
if [ "$current_version" == "$latest_version" ]; then | ||
echo "Go is up to date" | ||
exit 0 | ||
elif [ "$latest_version" == "$bump_candidate_version" ] && [ ! -z "$existing_prs" ]; then | ||
echo "A PR is already open" | ||
exit 0 | ||
fi | ||
|
||
if [ -z "$GITHUB_TOKEN" ]; then | ||
echo "GITHUB_TOKEN not set, but this is what I would do:" | ||
echo "git checkout bump-go && git merge --ff-only $REF_BRANCH" | ||
echo "echo \"$latest_version\" > GO_VERSION" | ||
echo "git add GO_VERSION" | ||
echo "git commit -m \"$PR_KEYWORD Bump Go to $latest_version\"" | ||
echo "git push origin bump-go" | ||
if [ -z "$existing_prs" ]; then | ||
echo "gh pr create --base $REF_BRANCH --head bump-go --title \"$PR_KEYWORD Bump Go to $latest_version\" --label \"$PR_LABEL\"" | ||
else | ||
first_id=$(echo "$existing_prs" | head -n 1) | ||
echo "gh pr edit $first_id --title \"$PR_KEYWORD Bump Go to $latest_version\"" | ||
fi | ||
else | ||
|
||
# Write the new version to the file | ||
git checkout bump-go && git merge --ff-only $REF_BRANCH | ||
echo "$latest_version" > GO_VERSION | ||
git add GO_VERSION | ||
|
||
# Commit the changes | ||
if git diff --quiet --cached; then | ||
echo "No changes to commit" | ||
else | ||
git commit -m "$PR_KEYWORD Bump Go to $latest_version" | ||
fi | ||
|
||
git push origin bump-go | ||
|
||
if [ -z "$existing_prs" ]; then | ||
gh pr create --base $REF_BRANCH --head bump-go \ | ||
--title "$PR_KEYWORD Bump Go to $latest_version" --label "$PR_LABEL" \ | ||
--body "This PR was automatically created by the bump-go action." | ||
else | ||
first_id=$(echo "$existing_prs" | sort -nr | head -n 1) | ||
gh pr edit $first_id --title "$PR_KEYWORD Bump Go to $latest_version" | ||
fi | ||
fi | ||
|
Oops, something went wrong.
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.
Have you considered using renovate / dependabot for this https://docs.renovatebot.com/modules/manager/regex/. I haven't used this specific feature of renovate, but renovate should provide the logic for opening PRs when there is a new version, and updating existing PRs with newer versions. I think the config could look like this
We probably could reference the gotify/build image there, so that it would only create a PR when there is a newer gotify/build image. We could then also add renovate to gotify build to update when there are newer golang docker images.
Generally, I'd rather use these tools than custom scripts as they seem easier to maintain, and I think gotify could also benefit from automatic dep updates (at least for the backend).
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.
Yeah makes sense I support this, although you are in a better position to introduce a new tool like this (I think I don't even have the permission to do it).
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.
I've added renovate to gotify/server and gotify/build. It needs configuration in the repo, there we probably have to only whitelist Go / docker, so that it doesn't update the js deps for now.