Skip to content

Commit bd572a5

Browse files
authored
Add release builds (#13)
* add release workfile * Use the same tag style
1 parent 6f24161 commit bd572a5

File tree

1 file changed

+157
-0
lines changed

1 file changed

+157
-0
lines changed

.github/workflows/release.yml

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# Copied from ripgrep
2+
3+
# The way this works is a little weird. But basically, the create-release job
4+
# runs purely to initialize the GitHub release itself. Once done, the upload
5+
# URL of the release is saved as an artifact.
6+
#
7+
# The build-release job runs only once create-release is finished. It gets
8+
# the release upload URL by downloading the corresponding artifact (which was
9+
# uploaded by create-release). It then builds the release executables for each
10+
# supported platform and attaches them as release assets to the previously
11+
# created release.
12+
#
13+
# The key here is that we create the release only once.
14+
15+
name: release
16+
on:
17+
push:
18+
# Enable when testing release infrastructure on a branch.
19+
#branches:
20+
# - master
21+
#pull_request:
22+
# branches:
23+
# - master
24+
tags:
25+
- 'v[0-9]+.[0-9]+.[0-9]+'
26+
jobs:
27+
create-release:
28+
name: create-release
29+
runs-on: ubuntu-latest
30+
# env:
31+
# Set to force version number, e.g., when no tag exists.
32+
# RG_VERSION: TEST-0.0.0
33+
steps:
34+
- name: Create artifacts directory
35+
run: mkdir artifacts
36+
37+
- name: Get the release version from the tag
38+
if: env.TERMCHAT_VERSION == ''
39+
run: |
40+
# Apparently, this is the right way to get a tag name. Really?
41+
#
42+
# See: https://github.community/t5/GitHub-Actions/How-to-get-just-the-tag-name/m-p/32167/highlight/true#M1027
43+
echo "::set-env name=TERMCHAT_VERSION::${GITHUB_REF#refs/tags/}"
44+
echo "version is: ${{ env.TERMCHAT_VERSION }}"
45+
46+
- name: Create GitHub release
47+
id: release
48+
uses: actions/create-release@v1
49+
env:
50+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
with:
52+
tag_name: ${{ env.TERMCHAT_VERSION }}
53+
release_name: ${{ env.TERMCHAT_VERSION }}
54+
55+
- name: Save release upload URL to artifact
56+
run: echo "${{ steps.release.outputs.upload_url }}" > artifacts/release-upload-url
57+
58+
- name: Save version number to artifact
59+
run: echo "${{ env.TERMCHAT_VERSION }}" > artifacts/release-version
60+
61+
- name: Upload artifacts
62+
uses: actions/upload-artifact@v1
63+
with:
64+
name: artifacts
65+
path: artifacts
66+
67+
build-release:
68+
name: build-release
69+
needs: ['create-release']
70+
runs-on: ${{ matrix.os }}
71+
env:
72+
# For some builds, we use cross to test on 32-bit and big-endian
73+
# systems.
74+
CARGO: cargo
75+
TARGET_DIR: ./target
76+
strategy:
77+
matrix:
78+
build: [linux, macos, win-msvc, win-gnu]
79+
include:
80+
- build: linux
81+
os: ubuntu-18.04
82+
rust: stable
83+
target: x86_64-unknown-linux-musl
84+
- build: macos
85+
os: macos-latest
86+
rust: stable
87+
target: x86_64-apple-darwin
88+
- build: win-msvc
89+
os: windows-2019
90+
rust: stable
91+
target: x86_64-pc-windows-msvc
92+
- build: win-gnu
93+
os: windows-2019
94+
rust: stable-x86_64-gnu
95+
target: x86_64-pc-windows-gnu
96+
97+
steps:
98+
- name: Checkout repository
99+
uses: actions/checkout@v2
100+
with:
101+
fetch-depth: 1
102+
103+
- name: Install Rust
104+
uses: actions-rs/toolchain@v1
105+
with:
106+
toolchain: ${{ matrix.rust }}
107+
profile: minimal
108+
override: true
109+
target: ${{ matrix.target }}
110+
111+
- name: Get release download URL
112+
uses: actions/download-artifact@v1
113+
with:
114+
name: artifacts
115+
path: artifacts
116+
117+
- name: Set release upload URL and release version
118+
shell: bash
119+
run: |
120+
release_upload_url="$(cat artifacts/release-upload-url)"
121+
echo "::set-env name=RELEASE_UPLOAD_URL::$release_upload_url"
122+
echo "release upload url: $RELEASE_UPLOAD_URL"
123+
release_version="$(cat artifacts/release-version)"
124+
echo "::set-env name=RELEASE_VERSION::$release_version"
125+
echo "release version: $RELEASE_VERSION"
126+
127+
- name: Build release binary
128+
run: |
129+
cargo build --release
130+
131+
- name: Build archive
132+
shell: bash
133+
run: |
134+
staging="termchat-${{ env.RELEASE_VERSION }}-${{ matrix.target }}"
135+
mkdir -p "$staging"
136+
137+
cp {README.md,LICENSE} "$staging/"
138+
139+
if [ "${{ matrix.os }}" = "windows-2019" ]; then
140+
cp "target/release/termchat.exe" "$staging/"
141+
7z a "$staging.zip" "$staging"
142+
echo "::set-env name=ASSET::$staging.zip"
143+
else
144+
cp "target/release/termchat" "$staging/"
145+
tar czf "$staging.tar.gz" "$staging"
146+
echo "::set-env name=ASSET::$staging.tar.gz"
147+
fi
148+
149+
- name: Upload release archive
150+
uses: actions/upload-release-asset@v1.0.1
151+
env:
152+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
153+
with:
154+
upload_url: ${{ env.RELEASE_UPLOAD_URL }}
155+
asset_path: ${{ env.ASSET }}
156+
asset_name: ${{ env.ASSET }}
157+
asset_content_type: application/octet-stream

0 commit comments

Comments
 (0)