Skip to content

Commit

Permalink
ci: improve/fix release action
Browse files Browse the repository at this point in the history
Now, on each push on master, a new stable release is made following
semver using commit logs with Knope
  • Loading branch information
pedronauck committed Jun 6, 2024
1 parent 3395096 commit 0aa76e1
Show file tree
Hide file tree
Showing 20 changed files with 439 additions and 228 deletions.
Empty file added .changeset/.gitkeep
Empty file.
File renamed without changes.
1 change: 1 addition & 0 deletions .commitlintrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extends: ['@commitlint/config-conventional']
7 changes: 0 additions & 7 deletions .cz.toml

This file was deleted.

58 changes: 34 additions & 24 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
name: CI

permissions:
contents: read

on:
pull_request:
types: [opened, synchronize, edited, closed, reopened]
types: [opened, synchronize, edited, reopened]

env:
CARGO_TERM_COLOR: always
Expand All @@ -17,11 +14,11 @@ concurrency:
cancel-in-progress: true

jobs:
validate-itle:
validate-title:
name: Validate PR Title
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v4
- uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand All @@ -35,28 +32,41 @@ jobs:
with:
toolchain: stable
- uses: Swatinem/rust-cache@v2
- name: Is lockfile updated?
run: cargo update --workspace --locked
- run: cargo update --workspace --locked

clippy:
name: Clippy
lint:
name: Linting
if: "!startsWith(github.head_ref, 'releases/')"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
uses: dtolnay/rust-toolchain@nightly
with:
toolchain: ${{ env.RUST_VERSION }}
components: clippy
- uses: Swatinem/rust-cache@v2
- run: cargo clippy --all-targets --all-features
components: clippy, rustfmt

pre-commit:
name: Linting & Formatting
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: pre-commit/action@v3.0.1
- name: Cache Rust toolchain
uses: actions/cache@v3
with:
path: |
~/.rustup
~/.cargo/bin
key: ${{ runner.os }}-rust-toolchain

- name: Cache Cargo dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-deps-${{ hashFiles('**/Cargo.lock') }}

- name: Install dependencies
uses: taiki-e/install-action@v2
with:
tool: cargo-sort@1.0.9

- name: Running linting
run: make lint
71 changes: 71 additions & 0 deletions .github/workflows/prepare_release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Open Release PR

on:
push:
branches: [main, staging, release]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

env:
CARGO_TERM_COLOR: always
CLICOLOR: 1
RUST_VERSION: 1.78.0

jobs:
setup:
if: "!startsWith(github.event.head_commit.message, 'ci(bump)')"
runs-on: ubuntu-latest
outputs:
branch: ${{ steps.set-vars.outputs.branch }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Check for pre-release configuration
id: set-vars
run: |
echo "branch=changeset/release-main" >> $GITHUB_OUTPUT
prepare-release:
if: "!startsWith(github.event.head_commit.message, 'ci(bump)')"
needs: setup
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.REPO_TOKEN }}

- name: Configure Git
run: |
git config --global user.name GitHub Actions
git config user.email github-actions@github.com
- name: Cache Rust dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- run: rustup toolchain install nightly -c rustfmt
- uses: taiki-e/install-action@v2
with:
tool: cargo-sort@1.0.9, cargo-edit@0.12.3

- uses: knope-dev/action@v2.1.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Run knope prepare release
env:
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}
RELEASE_BRANCH: ${{ needs.setup.outputs.branch }}
run: knope prepare-release --verbose
149 changes: 50 additions & 99 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,121 +1,72 @@
name: Release

on:
push:
branches: [main, staging, release]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
pull_request:
types: [closed]
branches: [main]

jobs:
setup:
runs-on: ubuntu-latest
outputs:
prerelease: ${{ steps.set-prerelease.outputs.prerelease }}
build-artifacts:
env:
archive_name: artifact

steps:
- name: Checkout code
uses: actions/checkout@v4
strategy:
fail-fast: false
matrix:
pkg: [fuel-nats-stream]
os: [ubuntu-latest]
target: [x86_64-unknown-linux-gnu]

- name: Setup git user (for changelog step)
run: |
git config --global user.name "${{ github.actor }}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
- name: Check for pre-release configuration
id: set-prerelease
run: |
if [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then
echo "prerelease=nightly" >> $GITHUB_OUTPUT
elif [[ "${GITHUB_REF}" == "refs/heads/staging" ]]; then
echo "prerelease=rc" >> $GITHUB_OUTPUT
else
echo "prerelease=false" >> $GITHUB_OUTPUT
changelog:
runs-on: ubuntu-latest
needs: setup
outputs:
version: ${{ steps.save-outputs.outputs.version }}
changelog: ${{ steps.save-outputs.outputs.changelog }}
commit_message: ${{ steps.save-outputs.outputs.commit_message }}
branch: ${{ steps.save-outputs.outputs.branch }}
runs-on: ${{ matrix.os }}
name: ${{ matrix.pkg }} ${{ matrix.target }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- id: cz
name: Create bump and changelog
uses: commitizen-tools/commitizen-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
changelog_increment_filename: body.md
prerelease: ${{ needs.setup.outputs.prerelease }}
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2

- name: Save outputs
id: save-outputs
run: |
version=${{ steps.cz.outputs.version }}
changelog=$(cat body.md)
commit_message="ci(bump): release ${version}"
branch="release-${{ steps.cz.outputs.version }}"
- name: Install host target
run: rustup target add ${{ matrix.target }}

echo "version=${version}" >> $GITHUB_OUTPUT
echo "changelog=${changelog}" >> $GITHUB_OUTPUT
echo "commit_message=${commit_message}" >> $GITHUB_OUTPUT
echo "branch=${branch}" >> $GITHUB_OUTPUT
- name: Build
run: make build TARGET=${{ matrix.target }} PACKAGE=${{ matrix.pkg }}

create_pr:
runs-on: ubuntu-latest
needs: changelog
- name: Set Archive Name
id: archive
run: echo "archive_name=${{ matrix.pkg }}-${{ matrix.target }}" >> $GITHUB_ENV

steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Create Tar Archive
run: |
mkdir ${{ env.archive_name }}
cp target/${{ matrix.target }}/release/${{ matrix.pkg }} ${{ env.archive_name }}
tar -czf ${{ env.archive_name }}.tgz ${{ env.archive_name }}
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v3
- name: Upload Artifact
uses: actions/upload-artifact@v4.3.3
with:
commit-message: ${{ needs.changelog.outputs.commit_message }}
title: Release ${{ needs.changelog.outputs.version }}
body: |
${{ needs.changelog.outputs.changelog }}
branch: ${{ needs.changelog.outputs.branch }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Check outputs
if: ${{ steps.cpr.outputs.pull-request-number }}
run: |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
name: ${{ matrix.pkg }}-${{ matrix.target }}
path: ${{ env.archive_name }}.tgz
if-no-files-found: error

release:
needs: [build-artifacts]
runs-on: ubuntu-latest
needs: changelog
if: github.ref == 'refs/heads/release'

permissions:
contents: read
actions: write
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Release
uses: softprops/action-gh-release@v1
- uses: actions/checkout@v4.1.6
- uses: actions/download-artifact@v4.1.7
with:
body_path: body.md
tag_name: ${{ needs.changelog.outputs.version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
path: artifacts
merge-multiple: true

notify:
runs-on: ubuntu-latest
if: failure()
- name: List artifacts
run: ls -R artifacts

steps:
- name: Error Notification
run: |-
echo "An error occurred during the release process"
# Optionally, send a notification to Slack or email
- uses: knope-dev/action@v2.1.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- run: knope release
env:
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/update_deps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ jobs:
git commit --no-verify --file=commit.txt
- name: Create or Update Pull Request
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v6
with:
commit-message: ${{ env.COMMIT_MESSAGE }}
title: ${{ env.PR_TITLE }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ lcov.info
node_modules/
pnpm-lock.yaml
./package.json
tmp
Loading

0 comments on commit 0aa76e1

Please sign in to comment.