Skip to content
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

Update release workflow #2552

Merged
merged 18 commits into from
Nov 10, 2023
Merged

Update release workflow #2552

merged 18 commits into from
Nov 10, 2023

Conversation

oliversun9
Copy link
Contributor

This updates the CLI release workflow. Releasing CLI itself (not including downstream repos) now has three separate actions, each requiring some level of manual approval.

  1. Manually trigger the 'Create Release PR' action and the action will create a PR that updates the changelog and version in bufcli.go.
  2. Once the the first PR is merged, the second action is triggered. This action builds and signs the new CLI and creates a draft release.
  3. Once the draft release is published (approved), the third action is triggered and creates a go-back-to-development PR that updates the version and changelog.

This also removes third party actions in the release workflow.

@oliversun9 oliversun9 requested a review from doriable November 7, 2023 18:22
@@ -0,0 +1,42 @@
name: Create a PR
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[Unreleased]: https://github.com/bufbuild/buf/compare/${{ env.RELEASED_VERSION_WITH_V }}...HEAD
}" CHANGELOG.md
- name: update home brew badge
run: make updatehomebrewbadge VERSION=${{ env.RELEASED_VERSION_WITH_V }}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't test this in my own repo, but it runs in the same relative order as before. @doriable does this look correct?

APP_ID: 251311

jobs:
prepare:
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 is now create-release-pr.yaml

steps:
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a
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 isn't always needed, we can simply use secrets.GITHUB_TOKEN in most cases. One exception is create-release-pr.yaml, where the action creates a PR and another checks needs to be triggered by this PR. In this case, we can use the official github action for this purpose.

with:
go-version: "1.21.x"
- name: Install Buf
run: make installbuf
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we really need to install buf here? I suppose it checks whether it builds, but regular ci.yaml should cover that.

done
echo ERROR: CHANGELOG has not been updated
exit 1
tag:
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 isn't needed anymore since you pass a tag in gh release create

run: |
jq --null-input '{ text: "BufCLI Release v${{env.VERSION}} has started: ${{ steps.cpr.outputs.pull-request-url }}" }' \
| curl -sSL -X POST -H 'Content-Type: application/json' -d @- '${{ secrets.SLACK_RELEASE_NOTIFICATION_WEBHOOK }}'
verify:
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 is now verify-changelog.yaml

git push origin :${{env.VERSION}} 2> /dev/null || echo 'remote ref does not exist'
git tag ${{env.VERSION}}
git push origin ${{env.VERSION}}
perform:
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 is now build-and-draft-release.yaml

run: |
jq --null-input '{ text: "BufCLI Release ${{env.VERSION}} is complete: ${{ steps.ghr.outputs.url }}" }' \
| curl -sSL -X POST -H 'Content-Type: application/json' -d @- '${{ secrets.SLACK_RELEASE_NOTIFICATION_WEBHOOK }}'
post-release:
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 is replaced by back-to-development.yaml

script:
core.setOutput('version', "${{github.ref_name}}".replace("v", ""));
trigger-maven-update:
runs-on: ubuntu-latest
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These triggers are removed and we will manually released these repos

run: make updateversion VERSION=${{ env.NEXT_VERSION }}
- name: Unrelease changelog
run: |
sed -i "/^# Changelog/ {
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 find the line that says # Changelog and inserts content two lines below this line. This isn't a complex expression, but newline and whitespace behavior seem to be different between gnu-sed and mac sed. Therefore, it is not added as a make target.

I wish we can update makego to make SED_I gsed -i on mac, that way we can guarantee consistent behavior across mac and linux. However, I suspect gsed isn't built-in to GitHub's mac runners and if a CI workflow running on mac needs to use gsed it would have to install it first.

inputs:
version:
type: string
description: The released version without 'v'. For example, 1.0.0.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If this fails, it can be restarted with manual trigger

@@ -0,0 +1,54 @@
name: Go back to Development
on:
workflow_dispatch:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If this fails, it can be restarted with manual trigger. However, no input is needed because in a later step, version is read from bufcli.go

@@ -1,21 +0,0 @@
#!/usr/bin/env bash
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 is now done in draftrelease.bash

- name: Set VERSION variable
# The head ref looks like release/v1.0.0, and we need to trim the string up to the `/v`.
run: |
VERSION="${{ github.event.inputs.version || github.head_ref}}"
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 is handled in action so that the script does not need to know about what triggers it

- name: Checkout repository code
uses: actions/checkout@v4
- name: Get GitHub App Token
uses: actions/create-github-app-token@v1
Copy link
Contributor Author

@oliversun9 oliversun9 Nov 8, 2023

Choose a reason for hiding this comment

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

This is needed because we want a CI check to check that this PR created here has changes in CHANGELOG.md. To trigger that check, this PR needs to be opened with an App token.


env:
VERSION: ${{ github.event.inputs.version }}
APP_ID: 251311
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should perhaps store this ID in a secret to be safer? It's been here for probably a year by now, but it can be done in a follow up.

@@ -135,13 +135,6 @@ bufgeneratesteps:: \
bufrelease: $(MINISIGN)
DOCKER_IMAGE=golang:1.21-bullseye bash make/buf/scripts/release.bash

# We have to manually set the Homebrew version on the Homebrew badge as there
# is no badge on shields.io for Homebrew packages outside of homebrew-core

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't manually set the badge version anymore. It's now dynamic, see

[![Homebrew](https://img.shields.io/homebrew/v/buf)][badges_homebrew]

@@ -1,8 +0,0 @@
#!/usr/bin/env bash
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The make target is removed in the same PR

jobs:
draft_release:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release')) }}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

github.head_ref is potentially untrusted input, and is used later on. It's a potential vector for attacks since we expand it in-line. However, if the PR has been merged (approved by one of us at buf), the branch name is probably safe.

@oliversun9 oliversun9 merged commit 379cb60 into main Nov 10, 2023
@oliversun9 oliversun9 deleted the osun/update-release-workflow branch November 10, 2023 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants