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

feat: add release workflow #19

Merged
merged 2 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
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
87 changes: 87 additions & 0 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Prepare Release

permissions:
contents: write
pull-requests: write

on:
workflow_dispatch:
inputs:
level:
description: 'Specify SemVer version level you wish to bump (see: https://github.com/crate-ci/cargo-release/blob/master/docs/reference.md#bump-level)'
required: true
type: choice
options:
- release
- patch
- minor
- major
- alpha
- beta
- rc

jobs:
prepare-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Use Rust version from rust-toolchain.toml
run: rustup show

- uses: cargo-bins/cargo-binstall@main

- name: Install dependencies
run: cargo binstall cargo-release -y

- name: Set up git config
run: |
git config author.email "${{ github.event.sender.id }}+${{ github.event.sender.login }}@users.noreply.github.com"
git config author.name "${{ github.event.sender.login }}"
git config committer.email "41898282+github-actions[bot]@users.noreply.github.com"
git config committer.name "GitHub Actions Bot"
git config user.email "${{ github.event.sender.id }}+${{ github.event.sender.login }}@users.noreply.github.com"
git config user.name "${{ github.event.sender.login }}"

- name: Determine new version number by dry-running `cargo-release`
run: |
NEW_VERSION="$(
cargo release version ${{ inputs.level }} 2>&1 \
| grep "Upgrading .* from .* to .*" \
| awk '{print $6}' \
)"
echo "New version is $NEW_VERSION"
echo "NEW_VERSION=$NEW_VERSION" >> "$GITHUB_ENV"

- name: Switch to the release branch
run: |
BRANCH_NAME="release/v${{ env.NEW_VERSION }}"
git switch -c "$BRANCH_NAME"

- name: Roll changelog, bump version, and push branch
run: |
# see https://opensource.axo.dev/cargo-dist/book/workspaces/cargo-release-guide.html#using-cargo-release-with-pull-requests
cargo release "${{ inputs.level }}" --execute --no-confirm --config prepare-release.toml

Choose a reason for hiding this comment

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

Is there a benefit of having a separate .toml file for release config over storing the configuration in root Cargo.toml?

I also think that release-prepare.toml (vs prepare-release.toml) is easier to find and mentally parse when eyeballing files in the repo, and conveys same msg

Copy link
Member Author

Choose a reason for hiding this comment

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

The benefit is that cargo release doesn't roll the changelog

Choose a reason for hiding this comment

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

I don't understand. The --config points to a file that has changelog rolling configured.

Copy link

@smallstepman smallstepman Nov 22, 2023

Choose a reason for hiding this comment

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

Unless you mean calling cargo release --execute as last step of the process (as mentioned in contributing.md) has a different behavior. If that's the case, then I find it confusing or at least, not very obvious

Copy link
Member Author

@ericswanson-dfinity ericswanson-dfinity Nov 22, 2023

Choose a reason for hiding this comment

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

When the GH workflow runs cargo release ... --config prepare-release.yml, it needs to roll the changelog, so that that goes in the PR.

After the PR is merged, the cargo release --execute final step should not roll the changelog (which would create an additional commit).


- name: Open the release PR
env:
GH_TOKEN: ${{ github.token }}
run: |
TITLE="chore(release): prepare release ${{ env.NEW_VERSION }}"

cat >BODY.md <<EOF
This PR was automatically generated by this workflow: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}

After merging, run the following:

'''bash
git checkout main
git pull
cargo dist plan
cargo release --execute
'''
EOF

gh pr create --base main --title "$TITLE" --body-file BODY.md
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
<!-- next-header -->

## [Unreleased] - ReleaseDate

- Added `dfx` mode, which selects a dfx version and dispatches execution to it.
- Added `dfxvm install` command, which installs a dfx version.
- Added `dfxvm default` command, which sets or displays the default dfx version.
- Added `dfxvm update` command, which sets the latest dfx version as the default.
- Added `dfxvm uninstall` command, which uninstalls a dfx version.
- Added `dfxvm list` command, which lists all installed dfx versions.

<!-- next-url -->
[Unreleased]: https://github.com/dfinity/dfxvm/compare/828e4ed...HEAD
21 changes: 21 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,26 @@ this in-code documentation must be mirrored by a corresponding change
in `docs/cli-reference`. Finally, any feature or notable bugfix should be
mentioned in [CHANGELOG.md](CHANGELOG.md), under the `## Unreleased` header.

## Release Process

Prerequisites to make a release:
```bash
cargo install cargo-release
cargo install cargo-dist
```

To make a release, follow these steps:
1. Run the [Prepare Release][prepare-release-workflow] workflow.
2. Obtain approval and merge the PR that the workflow generated.
3. Run the following locally:

```bash
git checkout main
git pull
cargo dist plan
cargo release --execute
```

[code-of-conduct]: https://github.com/dfinity/ic-docutrack/blob/main/.github/CODE_OF_CONDUCT.md
[cla]: https://github.com/dfinity/cla/blob/master/CLA.md
[prepare-release-workflow]: https://github.com/dfinity/dfxvm/actions/workflows/prepare-release.yml
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ authors = ["DFINITY Stiftung <sdk@dfinity.org>"]
description = "dfx version manager"
repository = "https://github.com/dfinity/dfxvm"
license = "Apache-2.0"
publish = false # don't publish to crates.io

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down Expand Up @@ -55,3 +56,7 @@ targets = ["x86_64-unknown-linux-gnu", "aarch64-apple-darwin", "x86_64-apple-dar
pr-run-mode = "plan"
# The archive format to use for non-windows builds (defaults .tar.xz)
unix-archive = ".tar.gz"
# In coordination with "publish = false" at the package level,
# this makes `cargo dist` generate binaries for the GitHub release,
# while preventing `cargo release` from publishing to crates.io.
dist = true
10 changes: 10 additions & 0 deletions prepare-release.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pre-release-replacements = [
{file="CHANGELOG.md", search="Unreleased", replace="{{version}}"},
{file="CHANGELOG.md", search="\\.\\.\\.HEAD", replace="...v{{version}}", exactly=1},
{file="CHANGELOG.md", search="ReleaseDate", replace="{{date}}"},
{file="CHANGELOG.md", search="<!-- next-header -->", replace="<!-- next-header -->\n\n## [Unreleased] - ReleaseDate", exactly=1},
{file="CHANGELOG.md", search="<!-- next-url -->", replace="<!-- next-url -->\n[Unreleased]: https://github.com/dfinity/dfxvm/compare/v{{version}}...HEAD", exactly=1},
]
publish = false
tag = false
allow-branch = [ "release/v*" ]
Loading