Skip to content

Commit 6bfd726

Browse files
committed
feat: add release github workflow
1 parent d6abc87 commit 6bfd726

File tree

5 files changed

+341
-0
lines changed

5 files changed

+341
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Publish Github-Releases
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
tag:
7+
required: true
8+
type: string
9+
os:
10+
required: true
11+
type: string
12+
artifact_name:
13+
required: true
14+
type: string
15+
16+
jobs:
17+
github-releases:
18+
name: ${{ inputs.artifact_name }}
19+
runs-on: ${{ inputs.os }}
20+
steps:
21+
- uses: LIT-Protocol/artifact-exists-action@v0
22+
id: check_artifact
23+
with:
24+
name: ${{ inputs.artifact_name }}
25+
26+
- name: Download artifacts
27+
if: steps.check_artifact.outputs.exists == 'true'
28+
uses: actions/download-artifact@v4
29+
with:
30+
name: ${{ inputs.artifact_name }}
31+
path: ./artifact
32+
33+
- name: Get file
34+
if: steps.check_artifact.outputs.exists == 'true'
35+
id: get_file_name
36+
shell: bash
37+
working-directory: ./artifact
38+
run: |
39+
ls -R
40+
echo "file_name=$(ls | head -n 1)" >> "$GITHUB_OUTPUT"
41+
42+
- name: Upload artifact to release
43+
if: steps.check_artifact.outputs.exists == 'true'
44+
uses: svenstaro/upload-release-action@v2
45+
with:
46+
repo_token: ${{ secrets.GITHUB_TOKEN }}
47+
file: ./artifact/${{ steps.get_file_name.outputs.file_name }}
48+
tag: ${{ inputs.tag }}
49+
overwrite: true

.github/workflows/linux.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Build Linux
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
tag:
7+
required: true
8+
type: string
9+
binary:
10+
required: true
11+
type: string
12+
13+
14+
jobs:
15+
github-releases:
16+
name: linux
17+
env:
18+
platform: linux-x86_64
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Build
24+
run: |
25+
cargo build --release --target x86_64-unknown-linux-gnu --no-default-features
26+
27+
- name: Set file name
28+
id: set_file_name
29+
run: |
30+
echo "file_name=${{ inputs.binary }}_${{ inputs.tag }}_${{ env.platform }}" >> "$GITHUB_OUTPUT"
31+
32+
- name: Prepare package
33+
run: |
34+
cp target/x86_64-unknown-linux-gnu/release/${{ inputs.binary }} ${{ steps.set_file_name.outputs.file_name }}
35+
36+
- name: Upload binaries to artifacts
37+
uses: actions/upload-artifact@v4
38+
with:
39+
name: ${{ env.platform }}
40+
path: ${{ steps.set_file_name.outputs.file_name }}
41+
retention-days: 1

.github/workflows/macos.yaml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: Build MacOS
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
tag:
7+
required: true
8+
type: string
9+
binary:
10+
required: true
11+
type: string
12+
run_macos_intel:
13+
required: true
14+
type: string
15+
run_macos_apple_silicon:
16+
required: true
17+
type: string
18+
19+
20+
jobs:
21+
build-macos-intel:
22+
if: inputs.run_macos_intel == 'true'
23+
name: macos_intel
24+
env:
25+
platform: darwin-x86_64
26+
runs-on: macos-latest
27+
steps:
28+
- uses: actions/checkout@v4
29+
30+
- name: Environment Setup
31+
run: |
32+
export CFLAGS="-fno-stack-check"
33+
export MACOSX_DEPLOYMENT_TARGET="10.9"
34+
rustup component add rust-std --target x86_64-apple-darwin
35+
36+
- name: Build
37+
run: |
38+
cargo build --release --target x86_64-apple-darwin
39+
40+
- name: Set file name
41+
id: set_file_name
42+
run: |
43+
echo "file_name=${{ inputs.binary }}_${{ inputs.tag }}_${{ env.platform }}" >> "$GITHUB_OUTPUT"
44+
45+
- name: Prepare Package
46+
run: |
47+
cp target/x86_64-apple-darwin/release/${{ inputs.binary }} ${{ steps.set_file_name.outputs.file_name }}
48+
49+
- name: Upload binaries to artifacts
50+
uses: actions/upload-artifact@v4
51+
with:
52+
name: ${{ env.platform }}
53+
path: ${{ steps.set_file_name.outputs.file_name }}
54+
retention-days: 1
55+
56+
build-macos-apple-silicon:
57+
name: macos_apple_silicon
58+
if: inputs.run_macos_apple_silicon == 'true'
59+
env:
60+
platform: darwin-aarch64
61+
runs-on: macos-latest
62+
steps:
63+
- uses: actions/checkout@v4
64+
65+
- name: Environment
66+
# macos 11 was the first version to support ARM
67+
run: |
68+
export MACOSX_DEPLOYMENT_TARGET="11"
69+
70+
- name: Build
71+
run: |
72+
cargo build --release --target aarch64-apple-darwin
73+
74+
- name: Set file name
75+
id: set_file_name
76+
run: |
77+
echo "file_name=${{ inputs.binary }}_${{ inputs.tag }}_${{ env.platform }}" >> "$GITHUB_OUTPUT"
78+
79+
- name: Prepare Package
80+
run: |
81+
cp target/aarch64-apple-darwin/release/${{ inputs.binary }} ${{ steps.set_file_name.outputs.file_name }}
82+
83+
- name: Upload binaries to artifacts
84+
uses: actions/upload-artifact@v4
85+
with:
86+
name: ${{ env.platform }}
87+
path: ${{ steps.set_file_name.outputs.file_name }}
88+
retention-days: 1

.github/workflows/release.yaml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
name: Release
2+
3+
# Configure your build and release platforms
4+
env:
5+
# If your repo name differs from your binary name, change it.
6+
# Check you Cargo.toml -> package -> name
7+
binary: ${{ github.event.repository.name }}
8+
9+
# Build platforms
10+
11+
# Valid platforms: "linux, windows, macos_intel, macos_apple_silicon"
12+
# - Write "intel" and "apple" to abbreviate "macos_intel" and "macos_apple_silicon," respectively.
13+
# - Write "macos" to build for both "intel" and "apple"
14+
build_for: "linux,windows,macos"
15+
16+
# Releases
17+
18+
# Valid platforms: "github_releases"
19+
# - For brevity you can write: "releases"
20+
publish_to: "github_releases"
21+
22+
permissions:
23+
# To upload files to GitHub Releases
24+
contents: write
25+
# To verify the deployment originates from an appropriate source
26+
id-token: write
27+
28+
on:
29+
push:
30+
tags:
31+
- "*"
32+
workflow_dispatch:
33+
inputs:
34+
tag:
35+
description: "Add tag version: (e.g. -> v3.6.1)"
36+
required: true
37+
type: string
38+
build_for:
39+
description: "Build for:"
40+
default: linux,windows,macos
41+
publish_to:
42+
description: "Publish to:"
43+
default: github_releases
44+
45+
jobs:
46+
# Load variables
47+
load-env:
48+
runs-on: ubuntu-latest
49+
steps:
50+
- uses: actions/checkout@v4
51+
outputs:
52+
run_build_linux: ${{ (inputs.tag && contains(inputs.build_for, 'linux')) || (!inputs.tag && contains(env.build_for, 'linux') ) }}
53+
run_build_windows: ${{ ( inputs.tag && contains(inputs.build_for, 'windows')) || (!inputs.tag && contains(env.build_for, 'windows') ) }}
54+
run_build_macos_intel: ${{ ( inputs.tag && ( contains(inputs.build_for, 'intel') || contains(inputs.build_for, 'macos') )) || (!inputs.tag && (contains(env.build_for, 'intel') || contains(env.build_for, 'macos')) ) }}
55+
run_build_macos_apple_silicon: ${{ ( inputs.tag && ( contains(inputs.build_for, 'apple') || contains(inputs.build_for, 'macos') )) || (!inputs.tag && (contains(env.build_for, 'apple') || contains(env.build_for, 'macos')) ) }}
56+
run_publish_github_releases: ${{ ( inputs.tag && contains(inputs.publish_to, 'releases')) || (!inputs.tag && contains(env.publish_to, 'releases') ) }}
57+
tag: ${{ ( inputs.tag || github.ref_name ) }}
58+
binary: ${{ env.binary }}
59+
60+
# Build for Linux x86_64
61+
build-linux:
62+
needs: load-env
63+
if: needs.load-env.outputs.run_build_linux == 'true'
64+
uses: ./.github/workflows/linux.yaml
65+
name: build
66+
with:
67+
tag: ${{ needs.load-env.outputs.tag }}
68+
binary: ${{ needs.load-env.outputs.binary }}
69+
70+
# Build for Windows x86_64
71+
build-windows:
72+
needs: load-env
73+
if: needs.load-env.outputs.run_build_windows == 'true'
74+
uses: ./.github/workflows/windows.yaml
75+
name: build
76+
with:
77+
tag: ${{ needs.load-env.outputs.tag }}
78+
binary: ${{ needs.load-env.outputs.binary }}
79+
80+
81+
# Build for MacOS x86_64/ARM64
82+
build-macos:
83+
needs: load-env
84+
if: needs.load-env.outputs.run_build_macos_intel == 'true' || needs.load-env.outputs.run_build_macos_apple_silicon == 'true'
85+
uses: ./.github/workflows/macos.yaml
86+
name: build
87+
with:
88+
tag: ${{ needs.load-env.outputs.tag }}
89+
binary: ${{ needs.load-env.outputs.binary }}
90+
run_macos_intel: ${{ needs.load-env.outputs.run_build_macos_intel }}
91+
run_macos_apple_silicon: ${{ needs.load-env.outputs.run_build_macos_apple_silicon }}
92+
93+
94+
# Release binaries in GitHub
95+
publish-github-releases:
96+
needs:
97+
- load-env
98+
- build-linux
99+
- build-windows
100+
- build-macos
101+
if: ${{ always() && !failure() && !cancelled() && needs.load-env.outputs.run_publish_github_releases == 'true'}}
102+
strategy:
103+
fail-fast: false
104+
matrix:
105+
include:
106+
- artifact_name: linux-x86_64
107+
os: ubuntu-latest
108+
- artifact_name: windows-x86_64
109+
os: windows-latest
110+
- artifact_name: darwin-x86_64
111+
os: macos-latest
112+
- artifact_name: darwin-aarch64
113+
os: macos-latest
114+
uses: ./.github/workflows/github_releases.yaml
115+
name: publish / github-releases
116+
with:
117+
tag: ${{ needs.load-env.outputs.tag }}
118+
os: ${{ matrix.os }}
119+
artifact_name: ${{ matrix.artifact_name }}
120+
secrets: inherit

.github/workflows/windows.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Build Windows
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
tag:
7+
required: true
8+
type: string
9+
binary:
10+
required: true
11+
type: string
12+
13+
14+
jobs:
15+
github-releases:
16+
name: windows
17+
env:
18+
platform: windows-x86_64
19+
runs-on: windows-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Build
24+
run: |
25+
cargo build --release --target x86_64-pc-windows-msvc
26+
27+
- name: Set file name
28+
id: set_file_name
29+
shell: bash
30+
run: |
31+
echo "file_name=${{ inputs.binary }}_${{ inputs.tag }}_${{ env.platform }}" >> "$GITHUB_OUTPUT"
32+
33+
- name: Prepare package
34+
shell: bash
35+
run: |
36+
cp target/x86_64-pc-windows-msvc/release/${{ inputs.binary }}.exe ${{ steps.set_file_name.outputs.file_name }}.exe
37+
38+
- name: Upload binaries to artifacts
39+
uses: actions/upload-artifact@v4
40+
with:
41+
name: ${{ env.platform }}
42+
path: ${{ steps.set_file_name.outputs.file_name }}.exe
43+
retention-days: 1

0 commit comments

Comments
 (0)