-
Notifications
You must be signed in to change notification settings - Fork 1
104 lines (104 loc) · 3.65 KB
/
release.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
name: Release
on:
push:
branches:
- master
jobs:
release:
strategy:
matrix:
os:
- macos-latest
- ubuntu-latest
- windows-latest
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Build
run: cargo build --release
- name: Test
run: cargo test --release
- name: Get Cargo Metadata
id: cargo
shell: bash
run: >-
echo -n "::set-output name=version::" &&
cargo metadata --format-version=1 --no-deps |
jq -r '.packages[-1].version' &&
echo -n "::set-output name=name::" &&
cargo metadata --format-version=1 --no-deps |
jq -r '.packages[-1].name'
- name: Check if tag is released
id: tag
shell: bash
env:
TAG: ${{ steps.cargo.outputs.version }}
run: >-
git fetch --depth=1 origin "+refs/tags/${TAG}" > /dev/null 2>&1 &&
echo "::set-output name=exists::true" ||
echo "::set-output name=exists::false"
- name: Bundle Release Asset
id: asset
shell: bash
env:
NAME: ${{ steps.cargo.outputs.name }}
VERSION: ${{ steps.cargo.outputs.version }}
OS: ${{ matrix.os }}
run: >-
export ARCH="linux" &&
if [ "$OS" = "macos-latest" ]; then export ARCH="darwin"; fi &&
if [ "$OS" = "windows-latest" ]; then export ARCH="win32"; fi &&
export ASSET_NAME="${NAME}-v${VERSION}-${ARCH}-x64.tar.gz" &&
export ASSET_PATH="${RUNNER_TEMP}/${ASSET_NAME}" &&
if [ "$OS" = "windows-latest" ]; then export NAME="${NAME}.exe"; fi &&
export BINARY="./target/release/${NAME}" &&
if [ "$OS" != "windows-latest" ]; then strip "$BINARY"; fi &&
if [ "$OS" != "windows-latest" ]; then tar -czf "$ASSET_PATH" -C "./target/release" "$NAME"; fi &&
if [ "$OS" = "windows-latest" ]; then tar --force-local -czf "$ASSET_PATH" -C "./target/release" "$NAME"; fi &&
echo -n "::set-output name=path::" &&
echo "$ASSET_PATH"
- name: Create Release
uses: softprops/action-gh-release@v1
if: steps.tag.outputs.exists == 'false'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.cargo.outputs.version }}
files: ${{ steps.asset.outputs.path }}
retag:
runs-on: ubuntu-latest
needs: release
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Get Cargo Metadata
id: cargo
shell: bash
run: >-
echo -n "::set-output name=version::" &&
cargo metadata --format-version=1 --no-deps |
jq -r '.packages[-1].version'
- name: Check if tag is released
id: tag
shell: bash
env:
TAG: ${{ steps.cargo.outputs.version }}
run: >-
git fetch --depth=1 origin "+refs/tags/${TAG}" > /dev/null 2>&1 &&
echo "::set-output name=exists::true" ||
echo "::set-output name=exists::false"
- name: Create semver tags
if: steps.tag.outputs.exists == 'false'
shell: bash
env:
VERSION: ${{ steps.cargo.outputs.version }}
run: >-
export MAJOR_VERSION="$(cut -d'.' -f1 <<< "$VERSION")" &&
export MINOR_VERSION="$(cut -d'.' -f1-2 <<< "$VERSION")" &&
git tag "$MAJOR_VERSION" &&
git tag "$MINOR_VERSION" &&
git tag "$VERSION" &&
git push -f origin "$MAJOR_VERSION" &&
git push -f origin "$MINOR_VERSION" &&
git push -f origin "$VERSION"