Shared GitHub Actions for CNB Releases (#1) #6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build, Test, and Release Shared GitHub Actions | |
on: | |
pull_request: | |
push: | |
branches: ["main"] | |
permissions: | |
contents: write | |
env: | |
CARGO_TERM_COLOR: always | |
jobs: | |
lint: | |
name: Lint | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Update Rust toolchain | |
run: rustup update | |
- name: Rust Cache | |
uses: Swatinem/rust-cache@v2 | |
- name: Clippy | |
run: cargo clippy --all-targets --all-features -- --deny warnings | |
- name: rustfmt | |
run: cargo fmt -- --check | |
- name: Check docs | |
run: RUSTDOCFLAGS="-D warnings" cargo doc --all-features --document-private-items --no-deps | |
test: | |
name: Test | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Update Rust toolchain | |
run: rustup update | |
- name: Rust Cache | |
uses: Swatinem/rust-cache@v2 | |
- name: Test | |
run: cargo test --all-features | |
check-bootstrap: | |
name: Check Bootstrap Script | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Setup Node | |
uses: actions/setup-node@v3 | |
with: | |
node-version: lts/* | |
cache: npm | |
- name: Install Node dependencies | |
run: npm ci | |
- name: Rebuild bootstrap script | |
run: npm run build | |
- name: Check bootstrap script for uncommitted changes | |
run: if [ -n "$(git status --porcelain)" ]; then exit 1; fi | |
release: | |
name: Release / ${{ matrix.os }} | |
if: success() && github.ref == 'refs/heads/main' | |
needs: | |
- lint | |
- test | |
- check-bootstrap | |
strategy: | |
matrix: | |
os: [macos-latest, ubuntu-latest, windows-latest] | |
runs-on: ${{ matrix.os }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Update Rust toolchain | |
run: rustup update | |
- name: Rust Cache | |
uses: Swatinem/rust-cache@v2 | |
- name: Build | |
run: cargo build --release | |
- name: Get Cargo Metadata | |
id: metadata | |
shell: bash | |
run: | | |
echo "version=$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[-1].version')" >> "$GITHUB_OUTPUT" | |
echo "name=$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[-1].targets[-1].name')" >> "$GITHUB_OUTPUT" | |
- name: Bundle Release Asset | |
id: asset | |
shell: bash | |
env: | |
NAME: ${{ steps.metadata.outputs.name }} | |
VERSION: ${{ steps.metadata.outputs.version }} | |
OS: ${{ matrix.os }} | |
run: | | |
export ARCH="linux" && | |
if [ "$OS" = "macos-latest" ]; then export ARCH="darwin"; fi && | |
if [ "$OS" = "windows-latest" ]; then export ARCH="win32"; fi | |
export ASSET_NAME="${NAME}-v${VERSION}-${ARCH}-x64.tar.gz" | |
if [ "$OS" = "windows-latest" ]; then export RUNNER_TEMP="$(echo $RUNNER_TEMP | sed 's/\\/\//g')"; fi | |
export ASSET_PATH="${RUNNER_TEMP}/${ASSET_NAME}" && | |
if [ "$OS" = "windows-latest" ]; then export ASSET_PATH="${RUNNER_TEMP}/${ASSET_NAME}"; fi | |
if [ "$OS" = "windows-latest" ]; then export NAME="${NAME}.exe"; fi | |
export BINARY="./target/release/${NAME}" | |
if [ "$OS" != "windows-latest" ]; then strip "$BINARY"; fi | |
if [ "$OS" != "windows-latest" ]; then tar -czf "$ASSET_PATH" -C "./target/release" "$NAME"; fi | |
if [ "$OS" = "windows-latest" ]; then tar --force-local -czf "$ASSET_PATH" -C "./target/release" "$NAME"; fi | |
echo "path=${ASSET_PATH}" >> "$GITHUB_OUTPUT" | |
- name: Create Release | |
uses: softprops/action-gh-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: v${{ steps.metadata.outputs.version }} | |
files: ${{ steps.asset.outputs.path }} | |
fail_on_unmatched_files: true | |
generate_release_notes: true |