-
Notifications
You must be signed in to change notification settings - Fork 0
153 lines (132 loc) · 5.25 KB
/
Copy pathrelease.yml
File metadata and controls
153 lines (132 loc) · 5.25 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
name: Build and Release
on:
push:
tags:
- 'v*'
permissions:
contents: write
pull-requests: write
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-24.04
target: x86_64-unknown-linux-gnu
target_os: linux
cpu: amd64
archive_name: why-linux-amd64
install_cross: ''
linker_env: ''
- os: ubuntu-24.04-arm
target: aarch64-unknown-linux-gnu
target_os: linux
cpu: arm64
archive_name: why-linux-arm64
install_cross: ''
linker_env: ''
- os: macos-15-intel
target: x86_64-apple-darwin
target_os: darwin
cpu: amd64
archive_name: why-darwin-amd64
install_cross: ''
linker_env: ''
- os: macos-15
target: aarch64-apple-darwin
target_os: darwin
cpu: arm64
archive_name: why-darwin-arm64
install_cross: ''
linker_env: ''
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Install Rust
run: rustup toolchain install stable --profile minimal --target ${{ matrix.target }}
- name: Cache Cargo
uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
with:
save-if: "false"
- name: Verify Release Version
shell: bash
run: |
crate_version="$(cargo +stable metadata --locked --no-deps --format-version 1 | python3 -c 'import json, sys; print(json.load(sys.stdin)["packages"][0]["version"])')"
tag_version="${GITHUB_REF_NAME#v}"
if [ "$crate_version" != "$tag_version" ]; then
echo "Release tag v${tag_version} does not match Cargo.toml version ${crate_version}" >&2
exit 1
fi
- name: Install Cross-compiler (Linux ARM64 only)
if: matrix.install_cross != ''
run: ${{ matrix.install_cross }}
- name: Build
shell: bash
run: |
${{ matrix.linker_env }} cargo +stable build --release --locked --target ${{ matrix.target }}
cp target/${{ matrix.target }}/release/why ${{ matrix.archive_name }}
- name: Create Archive
run: tar czf ${{ matrix.archive_name }}.tar.gz ${{ matrix.archive_name }}
- name: Release to GitHub
uses: softprops/action-gh-release@b4309332981a82ec1c5618f44dd2e27cc8bfbfda # v3.0.0
if: startsWith(github.ref, 'refs/tags/')
with:
files: ${{ matrix.archive_name }}.tar.gz
prerelease: ${{ contains(github.ref, '-') }}
update-homebrew:
needs: build
runs-on: ubuntu-latest
# Run only for stable releases (tags without hyphens)
if: startsWith(github.ref, 'refs/tags/') && !contains(github.ref, '-')
steps:
- name: Checkout why-cli repository (for scripts)
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Checkout tap repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
repository: akriaueno/homebrew-tap
token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
persist-credentials: false
path: homebrew-tap
- name: Ensure Formula directory exists
run: mkdir -p homebrew-tap/Formula
- name: Calculate SHA256 of Source Code
id: shasum
run: |
TAG_NAME=${{ github.ref_name }}
# URL for the source code archive generated by GitHub
SOURCE_URL="https://github.com/akriaueno/why-cli/archive/refs/tags/${TAG_NAME}.tar.gz"
echo "Downloading source from $SOURCE_URL"
curl -L -o source.tar.gz "$SOURCE_URL"
# Calculate SHA256 hash
SHA256=$(sha256sum source.tar.gz | awk '{print $1}')
echo "sha=$SHA256" >> "$GITHUB_OUTPUT"
echo "url=$SOURCE_URL" >> "$GITHUB_OUTPUT"
- name: Generate Formula
run: |
# Call the generation script
# Arguments: VERSION, URL, SHA256
bash .github/scripts/generate_formula.sh \
"${{ github.ref_name }}" \
"${{ steps.shasum.outputs.url }}" \
"${{ steps.shasum.outputs.sha }}" > homebrew-tap/Formula/why.rb
# Log the generated content for verification
echo "=== Generated Formula ==="
cat homebrew-tap/Formula/why.rb
echo "========================="
- name: Create PR on tap repository
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
with:
token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} # fine-grained PAT (homebrew-tap, contents:write & pull-requests:write)
path: homebrew-tap
commit-message: "why ${{ github.ref_name }}"
branch: automation/bump-why-${{ github.ref_name }}
title: "why ${{ github.ref_name }}"
body: |
Update formula for why ${{ github.ref_name }}
Source: ${{ steps.shasum.outputs.url }}
SHA256: ${{ steps.shasum.outputs.sha }}