Skip to content
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
8 changes: 0 additions & 8 deletions .github/labeler.yml

This file was deleted.

59 changes: 0 additions & 59 deletions .github/workflows/label-prs.yaml

This file was deleted.

55 changes: 25 additions & 30 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,32 @@ on:
- closed
branches:
- main
workflow_dispatch:

name: Build and publish a release

jobs:
# We make `if_merged` a `needs:` of the other jobs here to only run this
# workflow on merged PRs.
if_merged:
name: Check that PR was merged and not closed
if: github.event.pull_request.merged == true
&& contains(github.event.pull_request.labels.*.name, 'release')
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
name: Check that PR was merged and not closed
if: github.event_name == 'workflow_dispatch'
|| (
github.event.pull_request.merged == true
&& contains(github.event.pull_request.labels.*.name, 'release')
)
runs-on: ubuntu-latest
steps:
- run: |
echo "This is a canonical hack to run GitHub Actions on merged PRs"
echo "See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#running-your-pull_request-workflow-when-a-pull-request-merges"

- name: Comment on PR with link to this action
uses: peter-evans/create-or-update-comment@v3
uses: peter-evans/create-or-update-comment@v4
if: github.event_name == 'pull_request'
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
Expand All @@ -43,14 +49,9 @@ jobs:
version: ${{ steps.get_cargo_metadata.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@v5

- uses: cachix/install-nix-action@v22
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
extra_nix_config: |
extra-experimental-features = nix-command flakes
accept-flake-config = true
- uses: cachix/install-nix-action@v31

- name: Get version number
id: get_cargo_metadata
Expand All @@ -64,20 +65,12 @@ jobs:
# parts of the matrix (so we can have the macOS and Linux executables in
# the next job).
needs: if_merged
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@v5

- uses: cachix/install-nix-action@v22
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
extra_nix_config: |
extra-experimental-features = nix-command flakes
accept-flake-config = true
- uses: cachix/install-nix-action@v31

- name: Build documentation
run: |
Expand All @@ -86,14 +79,13 @@ jobs:
cp "$RESULT"/* target/

- name: Upload documentation
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: documentation
path: |
target/*

- name: Publish to crates.io
if: runner.os == 'Linux'
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
Expand All @@ -108,13 +100,15 @@ jobs:
- version
permissions:
contents: write
issues: write
pull-requests: write
steps:
- name: Tag the release
uses: mathieudutour/github-tag-action@v6.0
uses: mathieudutour/github-tag-action@v6.2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
commit_sha: ${{ github.event.pull_request.merge_commit_sha }}
commit_sha: ${{ github.sha }}
# Note: This action automatically applies a prefix for us!
custom_tag: ${{ needs.version.outputs.version }}

- name: Download artifacts
Expand All @@ -130,11 +124,11 @@ jobs:
# path: target/release/ghciwatch-aarch64-linux
#
# will be downloaded to `linux/ghciwatch-aarch64-linux`.
uses: actions/download-artifact@v3
uses: actions/download-artifact@v5

- name: Create release
id: create_release
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2.3.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
Expand All @@ -146,7 +140,8 @@ jobs:
documentation/*

- name: Comment on PR with link to the release
uses: peter-evans/create-or-update-comment@v3
uses: peter-evans/create-or-update-comment@v4
if: github.event_name == 'pull_request'
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
Expand Down
103 changes: 29 additions & 74 deletions .github/workflows/version.yaml
Original file line number Diff line number Diff line change
@@ -1,99 +1,63 @@
---
# This workflow runs when PRs labeled `major`, `minor`, or `patch` are closed
# and increments version numbers. Then, it opens a PR labeled `release` for the
# changes. When that PR is merged, a release is created (see `release.yaml`).

on:
pull_request:
types:
- closed
branches:
- main
workflow_dispatch:
inputs:
bump_type:
description: 'Version bump type to perform'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major

name: Update versions and create release PR

jobs:
# We make `if_merged` a `needs:` of the other jobs here to only run this
# workflow on merged PRs.
if_merged:
name: Check that PR was merged and not closed
if: github.event.pull_request.merged == true
&& ( contains(github.event.pull_request.labels.*.name, 'major')
|| contains(github.event.pull_request.labels.*.name, 'minor')
|| contains(github.event.pull_request.labels.*.name, 'patch')
)
runs-on: ubuntu-latest
steps:
- run: |
echo "This is a canonical hack to run GitHub Actions on merged PRs"
echo "See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#running-your-pull_request-workflow-when-a-pull-request-merges"

bump_type:
name: Determine version bump type
needs: if_merged
runs-on: ubuntu-latest
outputs:
bump_type: ${{ steps.bump_type.outputs.bump_type }}
steps:
- name: Set output
id: bump_type
env:
is_major: ${{ contains(github.event.pull_request.labels.*.name, 'major') }}
is_minor: ${{ contains(github.event.pull_request.labels.*.name, 'minor') }}
is_patch: ${{ contains(github.event.pull_request.labels.*.name, 'patch') }}
run: |
if [[ "$is_major" == "true" ]]; then
echo "bump_type=major" >> "$GITHUB_OUTPUT"
elif [[ "$is_minor" == "true" ]]; then
echo "bump_type=minor" >> "$GITHUB_OUTPUT"
elif [[ "$is_patch" == "true" ]]; then
echo "bump_type=patch" >> "$GITHUB_OUTPUT"
fi

version:
name: Bump version and create release PR
permissions:
pull-requests: write
needs:
- if_merged
- bump_type
runs-on: ubuntu-latest
steps:
# See: https://github.com/peter-evans/create-pull-request/blob/915d841dae6a4f191bb78faf61a257411d7be4d2/docs/concepts-guidelines.md#authenticating-with-github-app-generated-tokens
- uses: actions/create-github-app-token@v2
id: generate_token
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}

- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
# Fetch all history/tags (needed to compute versions)
fetch-depth: 0

- uses: cachix/install-nix-action@v22
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
extra_nix_config: |
extra-experimental-features = nix-command flakes
accept-flake-config = true
- uses: cachix/install-nix-action@v31

- name: Get old version number
id: old_cargo_metadata
run: echo "version=$(nix run .#get-crate-version)" >> "$GITHUB_OUTPUT"

- name: Increment `Cargo.toml` version
run: nix run .#make-release-commit -- ${{ needs.bump_type.outputs.bump_type }}
run: nix run .#make-release-commit -- ${{ inputs.bump_type }}

- name: Get new version number
id: new_cargo_metadata
run: echo "version=$(nix run .#get-crate-version)" >> "$GITHUB_OUTPUT"

- name: Create release PR
id: release_pr
uses: peter-evans/create-pull-request@v5
uses: peter-evans/create-pull-request@v7
with:
# We push with the repo-scoped GitHub token to avoid branch
# protections. This token is tied to my account (@9999years) which is
# excluded from branch protection restrictions.
#
# I'd love a better way of implementing this but GitHub doesn't have
# one: https://github.com/github-community/community/discussions/13836
token: ${{ secrets.REPO_GITHUB_TOKEN }}
#
# Also, PRs created with the default `secrets.GITHUB_TOKEN` won't
# trigger `pull_request` workflows, so regular CI won't run either.
#
# See: https://github.com/orgs/community/discussions/65321
# See: https://github.com/peter-evans/create-pull-request/blob/915d841dae6a4f191bb78faf61a257411d7be4d2/docs/concepts-guidelines.md#authenticating-with-github-app-generated-tokens
token: ${{ steps.generate_token.outputs.token }}
branch: release/${{ steps.new_cargo_metadata.outputs.version }}
delete-branch: true
base: main
Expand All @@ -102,12 +66,3 @@ jobs:
Update version to ${{ steps.new_cargo_metadata.outputs.version }} with [cargo-release](https://github.com/crate-ci/cargo-release).
Merge this PR to build and publish a new release.
labels: release

- name: Comment on PR with link to release PR
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
[A PR to release these changes has been created, bumping the version from ${{ steps.old_cargo_metadata.outputs.version }} to ${{ steps.new_cargo_metadata.outputs.version }}.][pr]

[pr]: ${{ steps.release_pr.outputs.pull-request-url }}