Skip to content

Commit

Permalink
ci: add release workflow (#2)
Browse files Browse the repository at this point in the history
* ci: add release workflow

* ci: fix archive options and deprecated set-output

* ci: add needs for create-release

* ci: force pull github_ref

* ci: move to maintained create release action

* ci: fix correctly write archive name to output

* ci: set correct archive name for release upload

* ci: default to tag names of release action

* ci: install musl tools for cross-compilation

* ci: try to set linker for aarch64

* fix: config.toml format

* ci: try to set the correct linker

* ci: install linker within workflow

* ci: try to upload assets with the create-release action

* ci: downgrade action-gh-release

softprops/action-gh-release#555

* ci: add checksum for binaries
  • Loading branch information
dj95 authored Dec 25, 2024
1 parent be2af25 commit 1ad3da7
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.aarch64-unknown-linux-musl]
linker = "aarch64-linux-gnu-ld"
118 changes: 118 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
---
name: Release
on:
push:
tags:
- 'v*.*.*'
workflow_dispatch:

jobs:
create-release:
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
fetch-tags: false # https://github.com/actions/checkout/issues/1467

- run: git fetch --tags --all --force && git pull origin ${{ github.ref }} --unshallow --force
name: Fetch tags manually as a workaround. See https://github.com/actions/checkout/issues/1467

- name: Generate a changelog
uses: orhun/git-cliff-action@4a4a951bc43fafe41cd2348d181853f52356bee7 # v3
id: git-cliff
with:
config: cliff.toml
args: -vv --latest --strip header
env:
OUTPUT: CHANGES.md

- name: Create release
id: create_release
uses: softprops/action-gh-release@01570a1f39cb168c169c802c3bceb9e93fb10974 # v2.1.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
draft: true
body: ${{ steps.git-cliff.outputs.content }}
prerelease: false

build-release:
name: build-release
runs-on: ${{ matrix.runs-on }}
needs: create-release
env:
RUST_BACKTRACE: 1
strategy:
matrix:
build:
- 'linux musl x64'
- 'linux musl aarch64'
- 'darwin x64'
- 'darwin aarch64'
include:
- build: 'linux musl x64'
runs-on: 'ubuntu-latest'
target: 'x86_64-unknown-linux-musl'
- build: 'linux musl aarch64'
runs-on: 'ubuntu-latest'
target: 'aarch64-unknown-linux-musl'
- build: 'darwin x64'
runs-on: 'macos-latest'
target: 'x86_64-apple-darwin'
- build: 'darwin aarch64'
runs-on: 'macos-latest'
target: 'aarch64-apple-darwin'
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
fetch-tags: false # https://github.com/actions/checkout/issues/1467

- name: Install Rust
uses: dtolnay/rust-toolchain@4f647fc679bcd3b11499ccb42104547c83dabe96 # stable
with:
toolchain: '1.83.0'
target: ${{ matrix.target }}

- name: Install musl-tools
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get install -y --no-install-recommends musl-tools

- name: Install aarch linker
if: matrix.target == 'aarch64-unknown-linux-musl'
run: sudo apt-get install -y --no-install-recommends gcc-aarch64-linux-gnu

- name: Build release binary
run: cargo build --release --target ${{ matrix.target }}

- name: Create checksum
id: checksum
working-directory: ./target/${{ matrix.target }}/release
run: |
name="kdl-fmt.${{ matrix.target }}.sha256sum"
if [[ "$RUNNER_OS" != "macOS" ]]; then
sha256sum "kdl-fmt" > "${name}"
else
shasum -a 256 "kdl-fmt" > "${name}"
fi
echo "name=${name}" >> $GITHUB_OUTPUT
- name: Archive binary
id: archive-binary
working-directory: ./target/${{ matrix.target }}/release
run: |
tar cvzf "kdl-fmt.${{ matrix.target }}.tar.gz" kdl-fmt
echo "name=kdl-fmt.${{ matrix.target }}.tar.gz" >> $GITHUB_OUTPUT
- name: Upload binary file to release
uses: softprops/action-gh-release@01570a1f39cb168c169c802c3bceb9e93fb10974 # v2.1.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
draft: true
files: |
./target/${{ matrix.target }}/release/${{ steps.archive-binary.outputs.name }}
./target/${{ matrix.target }}/release/${{ steps.checksum.outputs.name }}

0 comments on commit 1ad3da7

Please sign in to comment.