-
Notifications
You must be signed in to change notification settings - Fork 0
163 lines (138 loc) · 4.67 KB
/
release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
name: release
on:
push:
tags:
- '*'
permissions:
contents: write
jobs:
archive-src:
name: archive-src
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install --yes --no-install-recommends \
lzip
- name: Archive source code
shell: bash
run: |
v="${GITHUB_REF#refs/tags/}"
release_name="commitmsgfmt-$v"
asset_name="${release_name}.tar.lz"
git archive --prefix="${release_name}/" --format=tar "$v" |
lzip -6 >"$asset_name"
printf 'ASSET=%s\n' "$asset_name" >> $GITHUB_ENV
printf 'RELEASE_VERSION=%s\n' "$v" >> $GITHUB_ENV
- name: Upload source code archive
uses: softprops/action-gh-release@v1
with:
draft: true
tag_name: ${{ env.RELEASE_VERSION }}
files: ${{ env.ASSET }}
build-package:
name: build-package
runs-on: ${{ matrix.os }}
strategy:
matrix:
build:
- linux
- macos
- win-msvc
include:
- build: linux
os: ubuntu-22.04
target: x86_64-unknown-linux-musl
binary_ext:
- build: macos
os: macos-12
target: x86_64-apple-darwin
binary_ext:
- build: win-msvc
os: windows-2022
target: x86_64-pc-windows-msvc
binary_ext: .exe
env:
# Backtraces for panics.
RUST_BACKTRACE: 1
TARGET_FLAGS:
TARGET_DIR: ./target
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Prepare environment
shell: bash
run: |
printf 'TARGET_FLAGS=--target %s\n' "${{ matrix.target }}" >> $GITHUB_ENV
printf 'TARGET_DIR=./target/${{ matrix.target }}\n' >> $GITHUB_ENV
printf 'RELEASE_VERSION=%s\n' "${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
printf 'RELEASE_BINARY=%s\n' "target/${{ matrix.target }}/release/commitmsgfmt${{ matrix.binary_ext }}" >> $GITHUB_ENV
# So much cruft just to install Asciidoctor.
# It's possible to do something like
# run: ./ci/install-${{ matrix.os }}
# but I couldn't get Windows to do anything that way.
- name: Install dependencies (Ubuntu)
if: matrix.os == 'ubuntu-22.04'
run: |
sudo apt-get update
sudo apt-get install --yes --no-install-recommends \
asciidoctor
- name: Install dependencies (Windows)
if: matrix.os == 'windows-2022'
run: gem install asciidoctor
- name: Install dependencies (macOS)
if: matrix.os == 'macos-12'
run: brew install asciidoctor
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
# Build all releases on nightly for latest optimizations.
toolchain: nightly
targets: ${{ matrix.target }}
- name: Install cargo-binstall
uses: cargo-bins/[email protected]
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Install Cross
# "install cross" takes 1 minute, "binstall cross" takes 1 second.
run: cargo binstall --no-confirm cross
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Build release
run: cross build --verbose --release ${{ env.TARGET_FLAGS }}
- name: Strip release binary
if: matrix.build == 'linux' || matrix.build == 'macos'
run: strip "${{ env.RELEASE_BINARY }}"
- name: Assemble package
shell: bash
run: |
package="commitmsgfmt-${{ env.RELEASE_VERSION }}-${{ matrix.target }}"
mkdir -p "$package"
asciidoctor --doctype manpage --backend manpage "doc/*.adoc"
cp "doc/commitmsgfmt.1" "$package"
cp LICENSE.txt "$package"
cp README.md "$package"
cp CHANGELOG.md "$package"
cp -r contrib "$package"
cp "${{ env.RELEASE_BINARY }}" "$package"
if [[ "${{ matrix.os }}" = 'windows-2022' ]]
then
7z a "$package.zip" "$package"
printf 'ASSET=%s\n' "$package.zip" >> $GITHUB_ENV
else
tar caf "$package.tar.gz" "$package"
printf 'ASSET=%s\n' "$package.tar.gz" >> $GITHUB_ENV
fi
- name: Upload package
uses: softprops/action-gh-release@v1
with:
draft: true
tag_name: ${{ env.RELEASE_VERSION }}
files: ${{ env.ASSET }}