Skip to content

Commit

Permalink
ci(frontmatter-gen): 👷 add release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienrousseau committed Oct 3, 2024
1 parent 9857ce7 commit 2867b4d
Showing 1 changed file with 127 additions and 0 deletions.
127 changes: 127 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
name: 🧪 Release

on:
push:
branches: [main, feat/frontmatter-gen]
pull_request:
branches: [feat/frontmatter-gen]
release:
types: [created]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
CARGO_TERM_COLOR: always
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_API_TOKEN }}

jobs:
build:
name: Build 🛠
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
strategy:
fail-fast: false
matrix:
include:
- os: windows-latest
target: x86_64-pc-windows-msvc
- os: windows-latest
target: aarch64-pc-windows-msvc
- os: macos-latest
target: x86_64-apple-darwin
- os: macos-latest
target: aarch64-apple-darwin
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: ${{ matrix.target }}
override: true
- uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Build
run: cargo build --verbose --release --target ${{ matrix.target }}
- name: Package
run: |
if [ ! -d "target/package" ]; then
mkdir -p target/package
fi
cd target/${{ matrix.target }}/release
tar czf ../../package/${{ matrix.target }}.tar.gz *
shell: bash

- name: Package (Windows)
if: matrix.os == 'windows-latest'
run: |
if (!(Test-Path "target/package")) {
mkdir target/package
}
cd target/${{ matrix.target }}/release
tar -czf ../../package/${{ matrix.target }}.tar.gz *
shell: pwsh

- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target }}
path: target/package/${{ matrix.target }}.tar.gz

release:
name: Release 🚀
needs: build
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set version
run: echo "VERSION=$(grep version Cargo.toml | sed -n 2p | cut -d '"' -f 2)" >> $GITHUB_ENV
- uses: actions/download-artifact@v4
with:
path: artifacts
- name: Generate Changelog
run: |
echo "## Release v${VERSION} - $(date +'%Y-%m-%d')" > CHANGELOG.md
cat TEMPLATE.md >> CHANGELOG.md
git log --pretty=format:'%s' --reverse HEAD >> CHANGELOG.md
echo "" >> CHANGELOG.md
- uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ env.VERSION }}
release_name: FrontMatter Gen 🦀 v${{ env.VERSION }}
body_path: CHANGELOG.md
draft: true
prerelease: false
- name: Upload Release Assets
run: |
for asset in artifacts/*/*; do
gh release upload v${{ env.VERSION }} "$asset" --clobber
done
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

crate:
name: Publish to Crates.io 🦀
needs: release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- name: Publish
run: cargo publish --token ${CARGO_REGISTRY_TOKEN}
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_API_TOKEN }}

0 comments on commit 2867b4d

Please sign in to comment.