Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: split PR build and release build to manually trigger builds of artifacts #838

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
192 changes: 192 additions & 0 deletions .github/workflows/build-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
name: Creating PR artifacts

on:
pull_request:
types: [labeled]
branches:
- main
paths-ignore:
- "**/*.md"
- "docs/**"
workflow_dispatch:

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: ".exe"
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@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
with:
fetch-depth: 0
- name: Install Rust toolchain
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # 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
- name: install cargo-auditable for non-cross builds
shell: bash
if: ${{ matrix.job.use_cross != true}}
run: |
cargo install cargo-auditable cargo-audit
- uses: Swatinem/rust-cache@e207df5d269b42b69c8bc5101da26f7d31feddb4 # 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@844f36862e911db73fe0815f00a4a2602c279505 # v1
if: ${{ matrix.job.use-cross == true }}
with:
command: build
use-cross: ${{ matrix.job.use-cross }}
toolchain: ${{ matrix.rust }}
args: --release --target ${{ matrix.job.target }}
- name: Cargo auditable build
uses: actions-rs/cargo@844f36862e911db73fe0815f00a4a2602c279505 # v1
if: ${{ matrix.job.use-cross == false }}
with:
command: auditable
use-cross: ${{ matrix.job.use-cross }}
toolchain: ${{ matrix.rust }}
args: build --release --target ${{ matrix.job.target }}
- name: Packaging final binary
shell: bash
id: package-binary
run: |
cp -a config target/${{ matrix.job.target }}/release/config
cd target/${{ matrix.job.target }}/release

########## create tar.gz ##########

# accounting for main branch and therefore beta builds
if [[ ${{ github.ref }} = refs/heads/main ]]; then
RELEASE_NAME=rustic-beta-${{ matrix.job.target}}.tar.gz
elif [[ ${{ github.ref }} = refs/tags/* ]]; then
RELEASE_NAME=rustic-${{ github.ref_name }}-${{ matrix.job.target}}.tar.gz
else
RELEASE_NAME=rustic-${{ github.run_id }}-${{ github.run_attempt }}-${{ matrix.job.target}}.tar.gz
fi

tar czvf $RELEASE_NAME rustic${{ matrix.job.binary-postfix }} config/

########## create sha256 ##########
if [[ ${{ runner.os }} == 'Windows' ]]; then
certutil -hashfile $RELEASE_NAME sha256 | grep -E [A-Fa-f0-9]{64} > $RELEASE_NAME.sha256
else
shasum -a 256 $RELEASE_NAME > $RELEASE_NAME.sha256
fi

echo "release_name=$RELEASE_NAME" >> $GITHUB_OUTPUT
- name: Storing binary as artefact
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3
with:
name: binary-${{ matrix.job.target}}
path: target/${{ matrix.job.target }}/release/${{ steps.package-binary.outputs.release_name }}*

remove-build-label:
name: Remove build label
needs: create-artifact
permissions:
contents: read
issues: write
pull-requests: write
runs-on: ubuntu-latest
if: |
always() &&
! contains(needs.*.result, 'skipped')
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

# Alternative approach (remove if above works fine)
# 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
6 changes: 0 additions & 6 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
on:
pull_request:
branches:
- main
paths-ignore:
- "**/*.md"
- "docs/**/*"
push:
branches:
- main
Expand Down