Skip to content

Commit 4c2177b

Browse files
committed
Add github workflow for publishing release artifacts to github
1 parent eba1d4c commit 4c2177b

File tree

1 file changed

+138
-0
lines changed

1 file changed

+138
-0
lines changed

.github/workflows/release.yml

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
---
2+
3+
name: release
4+
5+
on:
6+
workflow_dispatch:
7+
inputs:
8+
version:
9+
type: string
10+
description: "Release version (tag)"
11+
required: true
12+
dry-run:
13+
type: choice
14+
description: "Dry Run"
15+
options:
16+
- "no"
17+
- "yes"
18+
required: true
19+
20+
# Set permissions to be able to create releases
21+
permissions:
22+
contents: write
23+
24+
jobs:
25+
create-release:
26+
name: create-release
27+
runs-on: ubuntu-22.04
28+
29+
steps:
30+
- name: Inputs from workflow dispatch
31+
shell: bash
32+
if: ${{ github.event_name == 'workflow_dispatch' }}
33+
run: |
34+
echo "TAPESTRY_VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV
35+
echo "TAPESTRY_DRY_RUN=${{ github.event.inputs.dry-run }}" >> $GITHUB_ENV
36+
echo "TAPESTRY_VERSION: ${{ github.event.inputs.version }}"
37+
echo "TAPESTRY_DRY_RUN: ${{ github.event.inputs.dry-run }}"
38+
39+
- name: Checkout repository
40+
uses: actions/checkout@v4
41+
if: ${{ github.event_name == 'workflow_dispatch'}}
42+
with:
43+
ref: ${{ github.event.inputs.version }}
44+
45+
- name: Checkout repository
46+
uses: actions/checkout@v4
47+
if: ${{ github.event_name != 'workflow_dispatch'}}
48+
49+
- name: Get the release version from the tag
50+
shell: bash
51+
if: env.TAPESTRY_VERSION == ''
52+
run: |
53+
echo "TAPESTRY_VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
54+
55+
- name: Show the version
56+
run: |
57+
echo "version is: $TAPESTRY_VERSION"
58+
59+
- name: Check that tag version and Cargo.toml version are the same
60+
shell: bash
61+
run: |
62+
# Here we're doing a bare minimum check to ensure tag and
63+
# version in Cargo.toml is the same. A proper check will
64+
# again be done later at the time of building the artifact.
65+
if ! grep -qE "^version = \"$TAPESTRY_VERSION\"$" Cargo.toml; then
66+
echo "version does not match Cargo.toml" >&2
67+
exit 1
68+
fi
69+
70+
- name: Create Github release (draft)
71+
if: env.TAPESTRY_DRY_RUN != 'yes'
72+
env:
73+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74+
run: gh release create $TAPESTRY_VERSION --draft --verify-tag --title $TAPESTRY_VERSION
75+
76+
outputs:
77+
tapestry_version: ${{ env.TAPESTRY_VERSION }}
78+
tapestry_dry_run: ${{ env.TAPESTRY_DRY_RUN }}
79+
80+
81+
build-release:
82+
name: build-release
83+
needs: ['create-release']
84+
runs-on: ${{ matrix.os }}
85+
86+
strategy:
87+
matrix:
88+
include:
89+
- build: linux
90+
os: ubuntu-22.04
91+
rust: 1.80.1
92+
target: x86_64-unknown-linux-gnu
93+
## @TODO Cross compilation needed here
94+
# - build: linux-arm
95+
# os: ubuntu-22.04
96+
# rust: stable
97+
# target: aarch64-unknown-linux-gnu
98+
- build: macos
99+
os: macos-12
100+
rust: 1.80.1
101+
target: x86_64-apple-darwin
102+
## @TODO Cross compilation needed here
103+
# - build: macos-arm
104+
# os: macos-12
105+
# rust: stable
106+
# target: aarch64-apple-darwin
107+
108+
steps:
109+
- name: Checkout repository
110+
uses: actions/checkout@v4
111+
with:
112+
ref: ${{ needs.create-release.outputs.tapestry_version }}
113+
114+
- name: Install Rust
115+
uses: dtolnay/rust-toolchain@master
116+
with:
117+
toolchain: ${{ matrix.rust }}
118+
target: ${{ matrix.target }}
119+
120+
- name: Build using the scripts/gh-build script
121+
shell: bash
122+
run: |
123+
scripts/gh-build ${{ needs.create-release.outputs.tapestry_version }} ${{ matrix.target }}
124+
125+
- name: Upload release archive
126+
if: ${{ needs.create-release.outputs.tapestry_dry_run != 'yes' }}
127+
env:
128+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
129+
run: |
130+
gh release upload "${{ needs.create-release.outputs.tapestry_version }}" "gh-release/tapestry-${{ matrix.target }}.gz"
131+
gh release upload "${{ needs.create-release.outputs.tapestry_version }}" "gh-release/tapestry-${{ matrix.target }}.gz.sha256"
132+
133+
- name: Cleanup
134+
if: ${{ needs.create-release.outputs.tapestry_dry_run != 'yes' }}
135+
shell: bash
136+
run: |
137+
rm -r gh-release/
138+
cargo clean

0 commit comments

Comments
 (0)