Skip to content

Commit

Permalink
feat(release flow): unified cargo + github release with multi arch bi…
Browse files Browse the repository at this point in the history
…naries and change log
  • Loading branch information
stvnksslr committed Oct 9, 2024
1 parent c4091d5 commit 51f4749
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 48 deletions.
49 changes: 8 additions & 41 deletions .github/workflows/release.yaml → .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
name: publish

on:
push:
branches: [ "**" ]
tags: [ "*" ]
pull_request:
branches: [ "main" ]
release:
types: [ published ]


permissions:
Expand All @@ -21,76 +20,63 @@ env:
jobs:
build:
name: Build - ${{ matrix.platform.name }}
# By default, runs on Ubuntu, otherwise, override with the desired os
runs-on: ${{ matrix.platform.os || 'ubuntu-22.04' }}
strategy:
matrix:
# Set platforms you want to build your binaries on
platform:
# Linux
# The name is used for pretty print
- name: Linux x86_64
# The used Rust target architecture
target: x86_64-unknown-linux-gnu

- name: Linux aarch64
target: aarch64-unknown-linux-gnu

# Mac OS
- name: MacOS x86_64
target: x86_64-apple-darwin

- name: MacOS aarch64
target: aarch64-apple-darwin

# Windows
- name: Windows x86_64
# Use another GitHub action OS
os: windows-latest
target: x86_64-pc-windows-msvc

steps:
- name: Checkout Git repo
uses: actions/checkout@v4

# Linux & Windows
- name: Install rust toolchain
if: ${{ !contains(matrix.platform.target, 'apple') }}
# TODO: replace deprecated
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: "${{ env.RUST_VERSION }}"
override: true
target: ${{ matrix.platform.target }}
components: rustfmt, clippy

- name: Build ${{ matrix.platform.name }} binary
if: ${{ !contains(matrix.platform.target, 'apple') }}
# TODO: replace deprecated
uses: actions-rs/cargo@v1
# We use cross-rs if not running on x86_64 architecture on Linux
with:
command: build
use-cross: ${{ !contains(matrix.platform.target, 'x86_64') }}
args: ${{ env.BUILD_ARGS }} --target ${{ matrix.platform.target }}

# Mac OS
- name: Login to DockerHub
if: contains(matrix.platform.target, 'apple')
# We log on DockerHub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKER_LOGIN }}
password: ${{ env.DOCKER_TOKEN }}
- name: Build ${{ matrix.platform.name }} binary
if: contains(matrix.platform.target, 'apple')
# We use a dedicated Rust image containing required Apple libraries to cross-compile on multiple archs
run: |
docker run --rm --volume "${PWD}":/root/src --workdir /root/src joseluisq/rust-linux-darwin-builder:$RUST_VERSION \
sh -c "CC=o64-clang CXX=o64-clang++ cargo build $BUILD_ARGS --target ${{ matrix.platform.target }}"
- name: Store artifact
uses: actions/upload-artifact@v4
with:
# Finally, we store the binary as GitHub artifact for later usage
name: ${{ matrix.platform.target }}-${{ env.BIN_NAME }}
path: target/${{ matrix.platform.target }}/release/${{ env.BIN_NAME }}${{ contains(matrix.platform.target, 'windows') && '.exe' || '' }}
retention-days: 1
Expand Down Expand Up @@ -122,23 +108,4 @@ jobs:
version: '~> v2'
args: release --clean --skip=validate
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

release-plz:
name: Release-plz
runs-on: ubuntu-latest
needs: [ build ]
if: startsWith( github.ref, 'refs/tags/v' )
concurrency:
group: release-plz-${{ github.ref }}
cancel-in-progress: false
steps:
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Run release-plz
uses: MarcoIeni/[email protected]
with:
command: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Release Plz
name: release

permissions:
pull-requests: write
Expand All @@ -10,8 +10,8 @@ on:
- main

jobs:
release-plz:
name: Release-plz
release:
name: Release
runs-on: ubuntu-latest
concurrency:
group: release-plz-${{ github.ref }}
Expand All @@ -21,10 +21,12 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable

- name: Run release-plz
uses: MarcoIeni/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_PLZ_TOKEN }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 34 additions & 1 deletion release-plz.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,35 @@
[workspace]
changelog_update = false
changelog_update = true


[changelog]
body = """
## [{{ version | trim_start_matches(pat="v") }}]\
{%- if release_link -%}\
({{ release_link }})\
{% endif %} \
- {{ timestamp | date(format="%Y-%m-%d") }}
{% for group, commits in commits | group_by(attribute="group") %}
### {{ group | upper_first }}
{% for commit in commits %}
{%- if commit.scope -%}
- *({{commit.scope}})* {% if commit.breaking %}[**breaking**] {% endif %}\
{{ commit.message }}{{ self::username(commit=commit) }}\
{%- if commit.links %} \
({% for link in commit.links %}[{{link.text}}]({{link.href}}) {% endfor -%})\
{% endif %}
{% else -%}
- {% if commit.breaking %}[**breaking**] {% endif %}{{ commit.message }}{{ self::username(commit=commit) }}
{% endif -%}
{% endfor -%}
{% endfor %}
{%- if remote.contributors %}
### Contributors
{% for contributor in remote.contributors %}
* @{{ contributor.username }}
{%- endfor %}
{% endif -%}
{%- macro username(commit) -%}
{% if commit.remote.username %} (by @{{ commit.remote.username }}){% endif -%}
{% endmacro -%}
"""

0 comments on commit 51f4749

Please sign in to comment.