-
Notifications
You must be signed in to change notification settings - Fork 0
148 lines (128 loc) · 4.41 KB
/
ci.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
name: ci
on:
push:
branches:
- main
- dev
- major
- minor
- patch
jobs:
pre:
name: Preprocessing
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.matrix.outputs.matrix }}
increment: ${{ steps.increment.outputs.increment }}
steps:
- uses: actions/checkout@v3
- run: git fetch --tags
# Sets the increment: how much to push the version number
- run: |
case ${{ github.ref_name }} in
main) echo "increment=patch" >> $GITHUB_OUTPUT ;;
dev) echo "increment=prerelease" >> $GITHUB_OUTPUT ;;
*) echo "increment=${{ github.ref_name }}" >> $GITHUB_OUTPUT;;
esac
id: increment
# Obtains the matrix strategy from `./matrix.json` to use for
# building, testing, and releasing artifacts on GitHub Releases
- run: echo "matrix=$(jq -rc . .github/workflows/matrix.json)" >> $GITHUB_OUTPUT
id: matrix
- name: Enumerate outputs
run: |
echo 'increment: ${{ steps.increment.outputs.increment }}'
echo 'matrix: ${{ steps.version.outputs.version }}'
build-and-test:
name: Build & Test
needs: [pre]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.pre.outputs.matrix) }}
steps:
- uses: actions/checkout@v3
- name: Run tests
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
cargo build
cargo test
inc:
name: Increment version
needs: [pre, build-and-test]
if: startsWith(github.event.head_commit.message, 'ver:') == false
runs-on: ubuntu-latest
outputs:
version: ${{ steps.semver.outputs.version }}
steps:
- uses: actions/checkout@v3
- uses: nguyenvukhang/semver-increment@v1
id: semver
with:
increment: ${{ needs.pre.outputs.increment }}
identifier: "alpha"
version-file: "Cargo.toml"
version-regex: '^version = "(.*)"'
- name: Commit and push
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
cargo build
git add Cargo.toml Cargo.lock
git commit -m 'ver: bump to ${{ steps.semver.outputs.version }}'
git push
- name: Tag and push
if: ${{ needs.pre.outputs.increment != 'prerelease' }}
run: |
git tag v${{ steps.semver.outputs.version }}
git push --tag
# publish patch-level updates and above only
publish-crates-io:
name: Publish to Crates.io
if: needs.pre.outputs.increment != 'prerelease'
needs: [pre, inc]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: v${{ needs.inc.outputs.version }}
- uses: katyo/publish-crates@v2
with:
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
release-github:
name: Release on GitHub
needs: [pre, inc]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.pre.outputs.matrix) }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ needs.pre.outputs.increment != 'prerelease' && format('v{0}', needs.inc.outputs.version) || github.ref }}
- run: |
TARGET_DIR=./target/${{ matrix.target }}
echo "TARGET_DIR=$TARGET_DIR" >> $GITHUB_ENV
echo "BINFILE=$TARGET_DIR/release/git-nu" >> $GITHUB_ENV
- name: Build binary
run: cargo build --release
env:
CARGO_BUILD_TARGET_DIR: ${{ env.TARGET_DIR }}
- name: Strip release binary
if: >-
(matrix.build == 'linux' || matrix.build == 'linux-arm' || matrix.build == 'macos')
run: strip ${{ env.BINFILE }}
- name: Build archive
run: |
STAGING="git-nu-v${{ needs.inc.outputs.version }}-${{ matrix.target }}"
mkdir -p "$STAGING"
cp ${{ env.BINFILE }} "$STAGING"
tar czf "$STAGING.tar.gz" "$STAGING"
echo "ASSET=$STAGING.tar.gz" >> $GITHUB_ENV
- name: Release
uses: softprops/action-gh-release@v1
if: ${{ needs.pre.outputs.increment != 'prerelease' }}
with:
tag_name: v${{ needs.inc.outputs.version }}
files: ${{ env.ASSET }}