-
Notifications
You must be signed in to change notification settings - Fork 95
142 lines (124 loc) · 3.94 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
name: release
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
branches:
- ci-release
jobs:
cargo-publish:
runs-on: ubuntu-latest
environment: release
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
cargo publish
create-github-release:
runs-on: ubuntu-latest
environment: release
permissions:
contents: write
env:
GITU_VERSION: ""
outputs:
upload_url: ${{ steps.release.outputs.upload_url }}
gitu_version: ${{ env.GITU_VERSION }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
sparse-checkout: .recent-changelog-entry
sparse-checkout-cone-mode: false
- name: Gather information
shell: bash
if: env.GITU_VERSION == ''
run: |
echo "GITU_VERSION=${GITHUB_REF_NAME}" >> $GITHUB_ENV
echo "version is: ${{ env.GITU_VERSION }}"
echo "CHANGELOG_ENTRY<<EOF" >> $GITHUB_ENV
cat .recent-changelog-entry >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
echo "changelog entry:"
echo "${{ env.CHANGELOG_ENTRY }}"
- name: Create GitHub release
id: release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.GITU_VERSION }}
release_name: ${{ env.GITU_VERSION }}
body: "${{ env.CHANGELOG_ENTRY }}"
build-github-release:
needs: ['create-github-release']
runs-on: ${{ matrix.os }}
environment: release
permissions:
contents: write
env:
CARGO: cargo
TARGET_FLAGS: "--target ${{ matrix.target }}"
TARGET_DIR: ./target/${{ matrix.target }}
strategy:
matrix:
build: [linux, macos, windows]
include:
- build: linux
os: ubuntu-latest
rust: stable
target: x86_64-unknown-linux-gnu
- build: macos
os: macos-13
rust: stable
target: x86_64-apple-darwin
- build: macos-arm64
os: macos-latest
rust: stable
target: aarch64-apple-darwin
- build: windows
os: windows-latest
rust: stable
target: x86_64-pc-windows-msvc
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Workaround to have a version set (gitu --version)
fetch-tags: true
- name: Build release binary
run: cargo build --verbose --release --locked ${{ env.TARGET_FLAGS }}
- name: Build archive (Windows)
if: matrix.build == 'windows'
shell: bash
run: |
staging="gitu-${{ needs.create-github-release.outputs.gitu_version }}-${{ matrix.target }}"
mkdir -p "$staging"
cp {README.md,LICENSE} "$staging/"
cp "target/${{ matrix.target }}/release/gitu" "$staging/"
"$staging/gitu" --version
7z a -r "$staging.zip" "$staging"
echo "ASSET=$staging.zip" >> $GITHUB_ENV
- name: Build archive (non-Windows)
if: matrix.build != 'windows'
shell: bash
run: |
staging="gitu-${{ needs.create-github-release.outputs.gitu_version }}-${{ matrix.target }}"
mkdir -p "$staging"
cp {README.md,LICENSE} "$staging/"
cp "target/${{ matrix.target }}/release/gitu" "$staging/"
"$staging/gitu" --version
tar czvf "$staging.tar.gz" "$staging"
echo "ASSET=$staging.tar.gz" >> $GITHUB_ENV
- name: Upload release archive
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create-github-release.outputs.upload_url }}
asset_path: ${{ env.ASSET }}
asset_name: ${{ env.ASSET }}
asset_content_type: application/octet-stream