ci: split PR build and release build to manually trigger builds of artifacts #10
Workflow file for this run
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: Creating PR artifacts | |
on: | |
pull_request: | |
types: [labeled] | |
branches: | |
- main | |
paths-ignore: | |
- "**/*.md" | |
- "docs/**" | |
jobs: | |
create-artifact: | |
name: Target ${{ matrix.job.target }} | |
if: ${{ github.event.label.name == 'S-build' }} | |
runs-on: ${{ matrix.job.os }} | |
strategy: | |
matrix: | |
rust: [stable] | |
job: | |
- os: windows-latest | |
os-name: windows | |
target: x86_64-pc-windows-msvc | |
architecture: x86_64 | |
binary-postfix: "" | |
use-cross: false | |
- os: macos-latest | |
os-name: macos | |
target: x86_64-apple-darwin | |
architecture: x86_64 | |
binary-postfix: "" | |
use-cross: false | |
- os: macos-latest | |
os-name: macos | |
target: aarch64-apple-darwin | |
architecture: arm64 | |
binary-postfix: "" | |
use-cross: true | |
- os: ubuntu-latest | |
os-name: linux | |
target: x86_64-unknown-linux-gnu | |
architecture: x86_64 | |
binary-postfix: "" | |
use-cross: false | |
- os: ubuntu-latest | |
os-name: linux | |
target: x86_64-unknown-linux-musl | |
architecture: x86_64 | |
binary-postfix: "" | |
use-cross: false | |
- os: ubuntu-latest | |
os-name: linux | |
target: aarch64-unknown-linux-gnu | |
architecture: arm64 | |
binary-postfix: "" | |
use-cross: true | |
- os: ubuntu-latest | |
os-name: linux | |
target: i686-unknown-linux-gnu | |
architecture: i686 | |
binary-postfix: "" | |
use-cross: true | |
- os: ubuntu-latest | |
os-name: netbsd | |
target: x86_64-unknown-netbsd | |
architecture: x86_64 | |
binary-postfix: "" | |
use-cross: true | |
- os: ubuntu-latest | |
os-name: linux | |
target: armv7-unknown-linux-gnueabihf | |
architecture: armv7 | |
binary-postfix: "" | |
use-cross: true | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Install Rust toolchain | |
uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: ${{ matrix.rust }} | |
profile: minimal | |
override: true | |
target: ${{ matrix.job.target }} | |
- name: install compiler | |
shell: bash | |
run: | | |
if [[ ${{ matrix.job.target }} == x86_64-unknown-linux-musl ]]; then | |
sudo apt update | |
sudo apt-get install -y musl-tools | |
fi | |
- uses: Swatinem/rust-cache@v2 | |
with: | |
key: ${{ matrix.job.target }} | |
- name: Set Version | |
shell: bash | |
run: echo "PROJECT_VERSION=$(git describe --tags)" >> $GITHUB_ENV | |
- name: Cargo build | |
uses: actions-rs/cargo@v1 | |
with: | |
command: build | |
use-cross: ${{ matrix.job.use-cross }} | |
toolchain: ${{ matrix.rust }} | |
args: --release --target ${{ matrix.job.target }} | |
- name: Packaging final binary | |
if: ${{ !contains(github.ref_name, '/') }} | |
shell: bash | |
run: | | |
cd target/${{ matrix.job.target }}/release | |
########## create tar.gz ########## | |
RELEASE_NAME=rustic-${{ github.ref_name }}-${{ matrix.job.target}} | |
tar czvf $RELEASE_NAME.tar.gz rustic${{ matrix.job.binary-postfix }} | |
########## create sha256 ########## | |
if [[ ${{ runner.os }} == 'Windows' ]]; then | |
certutil -hashfile $RELEASE_NAME.tar.gz sha256 | grep -E [A-Fa-f0-9]{64} > $RELEASE_NAME.sha256 | |
else | |
shasum -a 256 $RELEASE_NAME.tar.gz > $RELEASE_NAME.sha256 | |
fi | |
- name: Storing binary as artefact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: binary-${{ matrix.job.target}} | |
path: target/${{ matrix.job.target }}/release/rustic-${{ github.ref_name }}-${{ matrix.job.target}}.tar.gz | |
remove-build-label: | |
name: Remove build label | |
needs: create-artifact | |
runs-on: ubuntu-latest | |
if: always() | |
steps: | |
- name: Remove label | |
uses: actions-ecosystem/action-remove-labels@v1 | |
if: always() | |
with: | |
github_token: ${{ github.token }} | |
labels: "S-build" | |
number: ${{ github.event.number }} | |
fail_on_error: true | |
# OLD TRY | |
# name: Remove build label | |
# needs: create-artifact | |
# permissions: | |
# contents: read | |
# issues: write | |
# pull-requests: write | |
# runs-on: ubuntu-latest | |
# if: always() | |
# steps: | |
# - name: Remove label | |
# env: | |
# GH_TOKEN: ${{ github.token }} | |
# run: | | |
# gh api \ | |
# --method DELETE \ | |
# -H "Accept: application/vnd.github+json" \ | |
# -H "X-GitHub-Api-Version: 2022-11-28" \ | |
# /repos/${{ github.repository }}/issues/${{ github.event.number }}/labels/S-build |