-
Notifications
You must be signed in to change notification settings - Fork 0
139 lines (116 loc) · 4.23 KB
/
Copy pathrelease.yml
File metadata and controls
139 lines (116 loc) · 4.23 KB
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
name: Release
on:
push:
tags:
- "v*.*.*"
permissions:
contents: write
jobs:
build:
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
- os: macos-14
target: x86_64-apple-darwin
- os: macos-14
target: aarch64-apple-darwin
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Cache cargo
uses: Swatinem/rust-cache@v2
- name: Install musl linker
if: ${{ matrix.target == 'x86_64-unknown-linux-musl' }}
run: |
sudo apt-get update
sudo apt-get install -y musl-tools
- name: Test
run: cargo test --locked
- name: Build release binary
env:
CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER: musl-gcc
run: cargo build --locked --release --target "${{ matrix.target }}"
- name: Package archive
shell: bash
run: |
set -euo pipefail
version="${GITHUB_REF_NAME#v}"
archive="cctty-${version}-${{ matrix.target }}.tar.gz"
mkdir -p "dist/${{ matrix.target }}"
cp "target/${{ matrix.target }}/release/cctty" "dist/${{ matrix.target }}/"
cp README.md README.zh-CN.md LICENSE "dist/${{ matrix.target }}/"
cp -R assets "dist/${{ matrix.target }}/assets"
tar -C "dist/${{ matrix.target }}" -czf "dist/${archive}" cctty README.md README.zh-CN.md LICENSE assets
shasum -a 256 "dist/${archive}" > "dist/${archive}.sha256"
- name: Upload build artifact
uses: actions/upload-artifact@v7
with:
name: cctty-${{ matrix.target }}
path: |
dist/*.tar.gz
dist/*.sha256
publish:
name: Publish GitHub release
runs-on: ubuntu-latest
needs: build
env:
HOMEBREW_TAP_REPOSITORY: Pyiner/homebrew-cctty
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Download artifacts
uses: actions/download-artifact@v8
with:
path: dist
merge-multiple: true
- name: Warn when Homebrew tap token is missing
if: ${{ env.HOMEBREW_TAP_TOKEN == '' }}
run: |
echo "::warning::HOMEBREW_TAP_TOKEN is not configured; release assets will be published but Pyiner/homebrew-cctty will not be updated automatically."
- name: Generate Homebrew formula
run: |
bash scripts/generate-homebrew-formula.sh "${GITHUB_REPOSITORY}" "${GITHUB_REF_NAME}" dist > dist/cctty.rb
- name: Publish release
env:
GH_TOKEN: ${{ github.token }}
run: |
if gh release view "${GITHUB_REF_NAME}" >/dev/null 2>&1; then
gh release upload "${GITHUB_REF_NAME}" \
dist/*.tar.gz \
dist/*.sha256 \
--clobber
else
gh release create "${GITHUB_REF_NAME}" \
dist/*.tar.gz \
dist/*.sha256 \
--title "cctty ${GITHUB_REF_NAME}" \
--generate-notes
fi
- name: Update Homebrew tap
if: ${{ env.HOMEBREW_TAP_TOKEN != '' }}
run: |
set -euo pipefail
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git clone "https://github.com/${HOMEBREW_TAP_REPOSITORY}.git" homebrew-tap
git -C homebrew-tap remote set-url origin \
"https://x-access-token:${HOMEBREW_TAP_TOKEN}@github.com/${HOMEBREW_TAP_REPOSITORY}.git"
mkdir -p homebrew-tap/Formula
cp dist/cctty.rb homebrew-tap/Formula/cctty.rb
git -C homebrew-tap add Formula/cctty.rb
if git -C homebrew-tap diff --cached --quiet; then
echo "Homebrew tap already up to date."
exit 0
fi
git -C homebrew-tap commit -m "Update cctty ${GITHUB_REF_NAME}"
git -C homebrew-tap push