-
-
Notifications
You must be signed in to change notification settings - Fork 6
180 lines (155 loc) · 6.12 KB
/
build.yaml
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
name: build
on:
push:
tags:
- "*"
env:
CARGO: cargo
jobs:
build:
name: Release
strategy:
matrix:
job:
- { os: ubuntu-latest, target: aarch64-unknown-linux-gnu }
- { os: ubuntu-latest, target: aarch64-unknown-linux-musl }
- { os: ubuntu-latest, target: x86_64-unknown-linux-gnu }
- { os: ubuntu-latest, target: x86_64-unknown-linux-musl }
- { os: windows-latest, target: x86_64-pc-windows-msvc }
- { os: macos-latest, target: x86_64-apple-darwin }
runs-on: ${{ matrix.job.os }}
timeout-minutes: 20
outputs:
PKG_NAME: ${{ steps.vars.outputs.PKG_NAME }}
PKG_VERSION: ${{ steps.vars.outputs.PKG_VERSION }}
PKG_DESC: ${{ steps.vars.outputs.PKG_DESC }}
PKG_AUTHOR: ${{ steps.vars.outputs.PKG_AUTHOR }}
PKG_EMAIL: ${{ steps.vars.outputs.PKG_EMAIL }}
PKG_HOMEPAGE: ${{ steps.vars.outputs.PKG_HOMEPAGE }}
steps:
- name: Git Checkout
uses: actions/checkout@v3
- name: Initialize workflow variables
id: vars
shell: bash
run: |
# Package version
if [[ $GITHUB_REF = refs/tags/* ]]; then
PKG_VERSION=$(
tag=${GITHUB_REF##*/};
echo ${tag:1}
)
else
PKG_VERSION=${GITHUB_SHA:0:7}
fi
PKG_NAME=$(sed -n 's/^name = "\(.*\)"/\1/p' Cargo.toml | head -n1)
PKG_DESC=$(sed -n 's/^description = "\(.*\)"/\1/p' Cargo.toml | head -n1)
PKG_AUTHORS=$(sed -n 's/^authors = \["\(.*\)"\]/\1/p' Cargo.toml)
PKG_HOMEPAGE=$(sed -n 's/^homepage = "\(.*\)"/\1/p' Cargo.toml)
PKG_BASENAME="${PKG_NAME}-${{ matrix.job.target }}"
echo "MSRV=$(sed -n 's/^rust-version = "\(.*\)"/\1/p' Cargo.toml)" >> $GITHUB_ENV
echo ::set-output name=PKG_VERSION::${PKG_VERSION}
echo ::set-output name=PKG_NAME::${PKG_NAME}
echo ::set-output name=PKG_BASENAME::${PKG_BASENAME}
echo ::set-output name=PKG_DESC::${PKG_DESC}
echo ::set-output name=PKG_AUTHOR::$(echo $PKG_AUTHORS | awk '{print $1}')
echo ::set-output name=PKG_EMAIL::$(echo $PKG_AUTHORS | awk '{print $2}' | sed -e 's/[<>]//g')
echo ::set-output name=PKG_HOMEPAGE::${PKG_HOMEPAGE}
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.MSRV }}
target: ${{ matrix.job.target }}
- name: Install Cross
shell: bash
if: ${{ startsWith(matrix.job.target, 'aarch64') || endsWith(matrix.job.target, 'musl') }}
run: |
cargo install cross
echo "CARGO=cross" >> $GITHUB_ENV
- name: Build
shell: bash
run: ${{ env.CARGO }} build --release --features=cli --target=${{ matrix.job.target }}
- name: Test
shell: bash
run: ${{ env.CARGO }} test --features=vimdoc --target=${{ matrix.job.target }}
- name: Package
shell: bash
id: package
if: startsWith(github.ref, 'refs/tags/')
run: |
# Staging area
PKG_STAGING=".ci_staging/${{ steps.vars.outputs.PKG_BASENAME }}"
# Create the staging area
mkdir -p $PKG_STAGING
# Package suffix relative to the platform
if [[ "${{ matrix.job.target }}" = *-windows-* ]]; then
PKG_SUFFIX=".zip"
BIN_SUFFIX=".exe"
else
PKG_SUFFIX=".tar.gz"
fi
BIN_NAME="${{ steps.vars.outputs.PKG_NAME }}${BIN_SUFFIX}"
BIN_PATH="target/${{ matrix.job.target }}/release/${BIN_NAME}"
# Copy binary
cp $BIN_PATH $PKG_STAGING
# Tarball name
TARBALL="${{ steps.vars.outputs.PKG_BASENAME }}${PKG_SUFFIX}"
# Creating release assets
pushd "${PKG_STAGING}/" >/dev/null
if [[ "${{ matrix.job.target }}" = *-windows-* ]]; then
7z -y a ${TARBALL} * | tail -2
else
tar czf ${TARBALL} *
fi
popd >/dev/null
echo ::set-output name=PKG_PATH::"${PKG_STAGING}/${TARBALL}"
- name: Publish archives and packages
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
generate_release_notes: true
files: ${{ steps.package.outputs.PKG_PATH }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish_rust_crate:
name: Publish Rust Crate on crates.io
runs-on: ubuntu-latest
timeout-minutes: 20
needs: build
if: startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v3
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.MSRV }}
- name: Publish
run: ${{ env.CARGO }} publish --verbose --all-features --token ${{ secrets.CARGO_TOKEN }}
publish_aur_package:
name: Publish AUR package
runs-on: ubuntu-latest
timeout-minutes: 20
if: startsWith(github.ref, 'refs/tags/')
needs: build
steps:
- uses: actions/checkout@v3
- name: Generate PKGBUILD
id: gen_pkgbuild
shell: bash
run: |
sed -i -e "s%{{AUTHOR}}%${{needs.build.outputs.PKG_AUTHOR}}%g;" ./.aur/PKGBUILD
sed -i -e "s%{{EMAIL}}%${{needs.build.outputs.PKG_EMAIL}}%g;" ./.aur/PKGBUILD
sed -i -e "s%{{NAME}}%${{needs.build.outputs.PKG_NAME}}%g;" ./.aur/PKGBUILD
sed -i -e "s%{{DESC}}%${{needs.build.outputs.PKG_DESC}}%g;" ./.aur/PKGBUILD
sed -i -e "s%{{VERSION}}%${{needs.build.outputs.PKG_VERSION}}%g;" ./.aur/PKGBUILD
sed -i -e "s%{{URL}}%${{needs.build.outputs.PKG_HOMEPAGE}}%g;" ./.aur/PKGBUILD
cat ./.aur/PKGBUILD
- name: Publish to the AUR
uses: KSXGitHub/github-actions-deploy-aur@v2.2.5
with:
pkgbuild: ./.aur/PKGBUILD
pkgname: ${{ needs.build.outputs.PKG_NAME }}
commit_username: ${{ needs.build.outputs.PKG_AUTHOR }}
commit_email: ${{ needs.build.outputs.PKG_EMAIL }}
commit_message: ${{ needs.build.outputs.PKG_VERSION }}
ssh_private_key: ${{ secrets.AUR_SSH_PRIVATE_KEY }}