-
-
Notifications
You must be signed in to change notification settings - Fork 37
134 lines (117 loc) · 3.89 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
name: Release
permissions:
contents: write
on:
push:
branches:
- main
jobs:
check_release:
runs-on: ubuntu-latest
outputs:
releaseExists: ${{ steps.check_release.outputs.releaseExists }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Check if release exists
id: check_release
uses: actions/github-script@v5
with:
script: |
const { owner, repo } = context.repo;
const fs = require("fs");
const content = fs.readFileSync("Cargo.toml", "utf8");
const match = content.match(/^version = "(.*?)"/m);
const version = match ? match[1] : "";
const tag = `v${version}`;
console.log("Extracted version: ", tag);
let releaseExists = false;
try {
await github.rest.repos.getReleaseByTag({
owner,
repo,
tag,
});
releaseExists = true;
} catch (error) {
if (error.status !== 404) {
throw error;
}
}
console.log("Release exists: ", releaseExists);
core.setOutput("releaseExists", releaseExists);
return { releaseExists };
release:
needs: check_release
if: ${{ needs.check_release.outputs.releaseExists == 'false' }}
strategy:
matrix:
target:
- x86_64-unknown-linux-gnu
- i686-unknown-linux-gnu
- aarch64-unknown-linux-gnu
- armv7-unknown-linux-gnueabihf
- arm-unknown-linux-gnueabihf
- powerpc64le-unknown-linux-gnu
- s390x-unknown-linux-gnu
- aarch64-apple-darwin
- x86_64-apple-darwin
# - x86_64-pc-windows-gnu
runs-on: ${{ (matrix.target == 'aarch64-apple-darwin' || matrix.target == 'x86_64-apple-darwin') && 'macos-latest' || 'ubuntu-latest' }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: ${{ matrix.target }}
override: true
- name: Install mingw-w64
run: sudo apt install -y mingw-w64
if: matrix.target == 'x86_64-pc-windows-gnu'
- name: Build target
uses: actions-rs/cargo@v1
with:
use-cross: true
command: build
args: --release --target ${{ matrix.target }}
- name: Package binaries
shell: bash
run: |
cd target/${{ matrix.target }}/release
short_target=$(echo "${{ matrix.target }}" | sed 's/-unknown//')
if [[ $short_target == *"windows"* ]]; then
tar czvf ../../../killport-${short_target}.tar.gz killport.exe
else
tar czvf ../../../killport-${short_target}.tar.gz killport
fi
cd -
- name: Extract version from Cargo.toml
id: get_version
run: |
VERSION=$(grep '^version =' Cargo.toml | head -n 1 | awk '{print $3}' | tr -d '"' | tr -d "\n")
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "Found version: $VERSION"
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Create release and upload assets
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ env.VERSION }}
name: Release v${{ env.VERSION }}
files: 'killport*'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish:
needs: release
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- name: Publish to crates.io
run: cargo publish --token ${{ secrets.CRATES_IO }}