Skip to content
Merged
Changes from 1 commit
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
19 changes: 15 additions & 4 deletions .github/workflows/check-golangupx-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
});
}

commit:
create_pr:
needs: check-golang-version
if: needs.check-golang-version.outputs.new-version == 'true'
runs-on: ubuntu-latest
Expand Down Expand Up @@ -101,10 +101,21 @@ jobs:
sed -i "s/go-version: '[0-9]\+\.[0-9]\+\.[0-9]'/go-version: '${NEW_VERSION}'/" .github/workflows/release_build.yml
echo "Updated release_build.yml Go version ${NEW_VERSION}"

- name: Commit updated files
- name: Create Pull Request
if: github.event_name != 'pull_request'
run: |
set -x
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This can be deleted later.

git branch golangupx_new_release
git switch golangupx_new_release
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add Dockerfile go.mod .github/workflows/release_build.yml
git commit -m "chore: update Golang upx to version ${{ needs.check-golang-version.outputs.version }}" || echo "No changes to commit"
git push || echo "No changes to push"
git commit -m "chore: update Golang upx to version ${{ needs.check-golang-version.outputs.version }}"
git push --force -u origin golangupx_new_release
Copy link
Member

Choose a reason for hiding this comment

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

I do not think the --force flag is required

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It fails without --force if branch exists with a commit on top of it (i.e. an open PR).

Copy link
Member

Choose a reason for hiding this comment

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

see my comment here; by checking early if the PR for the current version already exist, we can avoid pushing multiple times to an existing PR

PR_NUMBER=$(gh pr list --head golangupx_new_release --json number --jq '.[0].number')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here I check for existing PR, so it would not try to create another PR and fail in case there is one.

Copy link
Member

Choose a reason for hiding this comment

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

I think that having unique branch names (cf. my comment above) is a cleaner way to handle duplicates; this will avoid breaking stuff if the API changes or if the gh CLI changes its behavior

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct, but this is still needed in case PR has not been merged yet and workflow runs again (after a day for now).

Copy link
Member

Choose a reason for hiding this comment

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

This case can be avoided thanks to unique branches names (implemented in 2547e85) and by doing the check before the whole Git stuff. For example, the flow could be:

  • build the branch name based on the golang-upx version
  • check if there's already a remote branch with the same name
    • if yes: exit (PR already exists)
    • if no: do the whole git magic (PR doesn't already exist)

This will also avoid having to use --force as we're no longer gonna push on an already existing branch (since we're exiting early)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct, I'll change that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 5baebdd.

if [ ! -n "${PR_NUMBER}" ]; then
gh pr create --fill
gh pr list --head golangupx_new_release --json number --jq '.[0].number'
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}