ci: more cache tag setup check #459
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: CI | |
on: | |
push: | |
branches: | |
- master | |
- develop | |
paths-ignore: | |
- 'README.md' | |
- 'LICENSE' | |
- '.gitignore' | |
- '.vscode/**' | |
tags: | |
- v* | |
pull_request: | |
branches: | |
- master | |
- develop | |
paths-ignore: | |
- 'README.md' | |
- 'LICENSE' | |
- '.gitignore' | |
- '.vscode/**' | |
merge_group: | |
workflow_dispatch: | |
inputs: | |
release_build: | |
description: 'Create the release build without publishing' | |
required: true | |
type: boolean | |
default: false | |
env: | |
CARGO_TERM_COLOR: always | |
PKG_CONFIG_SYSROOT_DIR: / | |
permissions: | |
contents: write | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
tests: | |
runs-on: ubuntu-24.04 | |
if: ${{ !startsWith(github.event.head_commit.message, 'docs:') || !contains(github.event.head_commit.message, 'skip ci') }} | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@9a9194f87191a7e9055e3e9b95b8cfb13023bb08 | |
with: | |
submodules: 'true' | |
- name: Rustup stable | |
run: | | |
rustup update stable | |
echo "RUST_VERSION=$(rustc --version | cut -d ' ' -f 2)" >> "$GITHUB_ENV" | |
- name: Setup rust cache | |
uses: Swatinem/rust-cache@9bdad043e88c75890e36ad3bbc8d27f0090dd609 | |
with: | |
prefix-key: "rust-tosho-tests-${{ runner.os }}-${{ env.RUST_VERSION }}" | |
- name: Test | |
run: cargo test --verbose --all | |
build: | |
needs: tests | |
strategy: | |
matrix: | |
os: | |
# GNU Linux (x64) | |
- [ubuntu-24.04, x86_64-unknown-linux-gnu] | |
# macOS Intel (x64) | |
- [macos-13, x86_64-apple-darwin] | |
# macOS Apple Silicon (ARM64) | |
- [macos-14, aarch64-apple-darwin] | |
# Windows Server 2022 (x64) | |
- [windows-2022, x86_64-pc-windows-msvc] | |
fail-fast: false | |
runs-on: ${{ matrix.os[0] }} | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@9a9194f87191a7e9055e3e9b95b8cfb13023bb08 | |
- name: Rust Target | |
run: | | |
rustup update stable | |
rustup target add ${{ matrix.os[1] }} | |
# In here, we set up the rust version used, the build mode (release or nightly/debug) | |
# We can check for relase mode by checking refs/tags/v* or input.release_build | |
- name: Set up cache tag | |
run: | | |
echo "RUST_VERSION=$(rustc --version | cut -d ' ' -f 2)" >> "$GITHUB_ENV" | |
if [ ${{ startsWith(github.ref, 'refs/tags/v') }} = true ] || [ ${{ inputs.release_build == true }} = true ]; then | |
echo "BUILD_PROFILE=release" >> "$GITHUB_ENV" | |
else | |
echo "BUILD_PROFILE=debug" >> "$GITHUB_ENV" | |
fi | |
shell: bash | |
- name: Setup rust cache | |
uses: Swatinem/rust-cache@9bdad043e88c75890e36ad3bbc8d27f0090dd609 | |
with: | |
prefix-key: "rust-tosho-build-${{ env.BUILD_PROFILE }}-${{ runner.os }}-${{ matrix.os[1] }}-${{ env.RUST_VERSION }}" | |
- name: Build (Nightly) | |
if: startsWith(github.ref, 'refs/tags/v') != true | |
run: | | |
cargo build --verbose --all --target ${{ matrix.os[1] }} --profile ci | |
shell: bash | |
- name: Permissions (Nightly) | |
if: startsWith(github.ref, 'refs/tags/v') != true && matrix.os[0] != 'windows-latest' | |
run: | | |
chmod +x target/${{ matrix.os[1] }}/ci/tosho | |
shell: bash | |
- name: Upload artifact | |
if: startsWith(github.ref, 'refs/tags/v') != true | |
uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a | |
with: | |
name: tosho-${{ matrix.os[1] }} | |
path: | | |
target/${{ matrix.os[1] }}/ci/tosho.exe | |
target/${{ matrix.os[1] }}/ci/tosho | |
- name: Build (Release) | |
if: startsWith(github.ref, 'refs/tags/v') || ${{ inputs.release_build }} == true | |
run: | | |
cargo build --verbose --all --target ${{ matrix.os[1] }} --profile ci | |
shell: bash | |
env: | |
RELEASE: true | |
- name: Prepare release | |
if: matrix.os[0] != 'windows-latest' && startsWith(github.ref, 'refs/tags/v') | |
shell: bash | |
run: | | |
cd target/${{ matrix.os[1] }}/ci | |
chmod +x tosho | |
tar -czvf tosho-${{ matrix.os[1] }}.tar.gz tosho | |
mv tosho-${{ matrix.os[1] }}.tar.gz ../../.. | |
cd ../../.. | |
- name: Prepare release (Win32) | |
if: matrix.os[0] == 'windows-latest' && startsWith(github.ref, 'refs/tags/v') | |
run: | | |
cd target/${{ matrix.os[1] }}/ci | |
Compress-Archive -Path tosho.exe -DestinationPath tosho-${{ matrix.os[1] }}.zip | |
mv tosho-${{ matrix.os[1] }}.zip ../../.. | |
cd ../../.. | |
- name: Upload artifact | |
uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a | |
if: startsWith(github.ref, 'refs/tags/v') || ${{ inputs.release_build }} == true | |
with: | |
name: tosho-packages-${{ matrix.os[1] }} | |
path: | | |
tosho-${{ matrix.os[1] }}.zip | |
tosho-${{ matrix.os[1] }}.tar.gz | |
releases: | |
runs-on: ubuntu-latest | |
needs: build | |
if: startsWith(github.ref, 'refs/tags/v') && github.repository_owner == 'noaione' | |
permissions: | |
contents: write | |
discussions: write | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@9a9194f87191a7e9055e3e9b95b8cfb13023bb08 | |
- name: Download artifacts | |
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 | |
with: | |
path: tosho-packages | |
pattern: tosho-packages-* | |
merge-multiple: true | |
- name: Create changelog | |
id: prepare-change | |
run: | | |
python3 scripts/create_changelog.py | |
# Fetch git tag contents subject | |
VERSION_SUBJ=$(git tag -l --format='%(contents:subject)' ${{ github.ref }}) | |
echo "version_subject=$VERSION_SUBJ" >> "$GITHUB_OUTPUT" | |
env: | |
VERSION: ${{ github.ref }} | |
- name: Release | |
uses: softprops/action-gh-release@9a28f2423fd7ba2781181bb13e8aba228027c4e9 | |
with: | |
files: | | |
tosho-packages/* | |
draft: false | |
prerelease: false | |
token: ${{ secrets.GITHUB_TOKEN }} | |
body_path: CHANGELOG-GENERATED.md | |
name: ${{ steps.prepare-change.outputs.version_subject }} | |
- name: Create discussions | |
uses: nvdaes/build-discussion@44180020a97632aa87af4f9452d9bf78c35b25e5 | |
with: | |
title: Release ${{ github.ref_name }} | |
body: | | |
Release **${{ github.ref_name }}** is now available for **[download](https://github.com/noaione/tosho-mango/releases/tag/${{ github.ref_name }})**. | |
Please see the [changelog](https://github.com/noaione/tosho-mango/blob/master/CHANGELOG.md) for more information. | |
Report any issues you found in the [issue tracker](https://github.com/noaione/tosho-mango/issues/new/choose) | |
category-position: 1 # Announcements |