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: define file paths on events and fix gh release view args #999

Merged
merged 1 commit into from
Dec 4, 2024
Merged
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
45 changes: 33 additions & 12 deletions .github/workflows/rust_binaries_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,45 @@ on:
push:
branches:
- master
- 'releases/**'
- 'hotfix/**'
miraclx marked this conversation as resolved.
Show resolved Hide resolved
paths:
- Cargo.toml
- Cargo.lock
- 'crates/**'
- .github/workflows/rust_binaries_release.yml
pull_request:
types: [opened, synchronize, reopened]
branches:
- master
paths:
- Cargo.toml
- Cargo.lock
- 'crates/**'
- .github/workflows/rust_binaries_release.yml

jobs:
binary_matrix:
prepare:
runs-on: ubuntu-latest
outputs:
binaries: ${{ steps.setup_matrix.outputs.binaries }}
is_release_candidate: ${{ steps.check_release_candidate.outputs.is_release_candidate }}
binary_matrix: ${{ steps.setup_matrix.outputs.binaries }}
steps:
- name: Check if release candidate
id: check_release_candidate
run: |
# Additional checks for head_ref when PR because GH doesn't support that
if [ "${{ github.event_name }}" == "pull_request" ] && ! [[ "${{ github.head_ref }}" == prerelease/* ]]; then
echo 'is_release_candidate=false' >> "$GITHUB_OUTPUT"
else
echo 'is_release_candidate=true' >> "$GITHUB_OUTPUT"
fi

- name: Setup matrix
id: setup_matrix
run: |
echo 'binaries=["merod", "meroctl"]' >> "$GITHUB_OUTPUT"
echo 'binary_matrix=["merod", "meroctl"]' >> "$GITHUB_OUTPUT"

build:
if: needs.prepare.outputs.is_release_candidate == 'true'
strategy:
matrix:
include:
Expand All @@ -35,7 +55,7 @@ jobs:
- os: macos-latest
target: aarch64-apple-darwin
runs-on: ${{ matrix.os }}
needs: binary_matrix
needs: prepare

steps:
- name: Checkout code
Expand All @@ -44,7 +64,7 @@ jobs:
- name: Craft cargo arguments
id: cargo_args
run: |
binaries=$(echo '${{ needs.binary_matrix.outputs.binaries }}' | jq -r 'join(" ") | split(" ") | map("-p " + .) | join(" ")')
binaries=$(echo '${{ needs.prepare.outputs.binary_matrix }}' | jq -r 'join(" ") | split(" ") | map("-p " + .) | join(" ")')
args="$binaries --release --target ${{ matrix.target }}"
echo "Cargo build arguments: $args"
echo args="$args" >> "$GITHUB_OUTPUT"
Expand Down Expand Up @@ -134,7 +154,7 @@ jobs:
- name: Compress artifacts using gzip
run: |
mkdir -p artifacts
echo '${{ needs.binary_matrix.outputs.binaries }}' | jq -r '.[]' | while read binary; do
echo '${{ needs.prepare.outputs.binary_matrix }}' | jq -r '.[]' | while read binary; do
tar -czf artifacts/"$binary"_${{ matrix.target }}.tar.gz -C target/${{ matrix.target }}/release "$binary"
done

Expand All @@ -146,11 +166,12 @@ jobs:
retention-days: 2

release:
if: needs.prepare.outputs.is_release_candidate == 'true'
runs-on: ubuntu-latest
needs: [binary_matrix, build]
needs: [prepare, build]
strategy:
matrix:
binary: ${{ fromJSON(needs.binary_matrix.outputs.binaries) }}
binary: ${{ fromJSON(needs.prepare.outputs.binary_matrix) }}
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -165,7 +186,7 @@ jobs:
id: version_info
shell: bash
env:
GH_TOKEN: ${{ github.token }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "target_commit=${{ github.sha }}" >> $GITHUB_OUTPUT

Expand All @@ -174,7 +195,7 @@ jobs:
version="${{ matrix.binary }}-$version"
echo "Master version: $version"

if gh release view "$version" ${{ github.repository }} >/dev/null 2>&1; then
if gh release view "$version" --repo ${{ github.repository }} >/dev/null 2>&1; then
echo "Master release for this version already exists"
echo "release_required=false" >> $GITHUB_OUTPUT
else
Expand Down
Loading