@@ -3,137 +3,24 @@ name: Release
33on :
44 push :
55 tags :
6- - ' v[0-9]+.[0-9]+.[0-9]+*'
7-
8- permissions :
9- contents : write
6+ - " v*"
107
118jobs :
12- create-release :
13- name : Create release
9+ goreleaser :
1410 runs-on : ubuntu-latest
11+ permissions :
12+ contents : write
1513 steps :
16- - uses : actions/checkout@v6
17- - name : Verify tag matches Cargo.toml version
18- run : |
19- TAG="${GITHUB_REF_NAME#v}"
20- CARGO_VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)"/\1/')
21- if [ "$TAG" != "$CARGO_VERSION" ]; then
22- echo "::error::Tag $GITHUB_REF_NAME does not match Cargo.toml version $CARGO_VERSION"
23- exit 1
24- fi
25- - name : Create draft release
26- env :
27- GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
28- run : |
29- gh release create "$GITHUB_REF_NAME" \
30- --draft \
31- --title "$GITHUB_REF_NAME" \
32- --generate-notes
33-
34- build-release :
35- name : Build (${{ matrix.target }})
36- needs : create-release
37- runs-on : ${{ matrix.os }}
38- strategy :
39- fail-fast : true
40- matrix :
41- include :
42- - target : aarch64-apple-darwin
43- os : macos-latest
44- - target : x86_64-apple-darwin
45- os : macos-latest
46- - target : aarch64-unknown-linux-gnu
47- os : ubuntu-latest
48- use_cross : true
49- - target : x86_64-unknown-linux-gnu
50- os : ubuntu-latest
51- - target : x86_64-unknown-linux-musl
52- os : ubuntu-latest
53- use_cross : true
54- - target : x86_64-pc-windows-msvc
55- os : windows-latest
56- steps :
57- - uses : actions/checkout@v6
58-
59- - name : Install Rust toolchain
60- uses : actions-rust-lang/setup-rust-toolchain@v1
14+ - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
6115 with :
62- target : ${{ matrix.target }}
63-
64- - name : Prepend Strawberry Perl to PATH (Windows)
65- if : runner.os == 'Windows'
66- run : echo "C:\Strawberry\perl\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
67-
68- - name : Install cross
69- if : matrix.use_cross
70- uses : taiki-e/install-action@v2
16+ fetch-depth : 0
17+ - uses : actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
7118 with :
72- tool : cross
73-
74- - name : Build
75- if : " !matrix.use_cross"
76- run : cargo build --release --target ${{ matrix.target }}
77-
78- - name : Build (cross)
79- if : matrix.use_cross
80- shell : bash
81- run : cross build --release --target ${{ matrix.target }}
82-
83- - name : Package and checksum
84- id : package
85- shell : bash
86- run : |
87- BIN="serpapi"
88- TARGET="${{ matrix.target }}"
89- VERSION="${GITHUB_REF_NAME#v}"
90- PKG="${BIN}-${VERSION}-${TARGET}"
91-
92- mkdir "$PKG"
93- cp README.md LICENSE "$PKG/"
94-
95- if [[ "$TARGET" == *"windows"* ]]; then
96- cp "target/${TARGET}/release/${BIN}.exe" "$PKG/"
97- 7z a "${PKG}.zip" "$PKG"
98- ARCHIVE="${PKG}.zip"
99- else
100- cp "target/${TARGET}/release/${BIN}" "$PKG/"
101- tar czf "${PKG}.tar.gz" "$PKG"
102- ARCHIVE="${PKG}.tar.gz"
103- fi
104-
105- sha256sum "$ARCHIVE" > "${ARCHIVE}.sha256"
106- echo "archive=$ARCHIVE" >> "$GITHUB_OUTPUT"
107- echo "sha256=${ARCHIVE}.sha256" >> "$GITHUB_OUTPUT"
108-
109- - name : Upload to release
110- shell : bash
111- env :
112- GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
113- run : |
114- gh release upload "$GITHUB_REF_NAME" \
115- "${{ steps.package.outputs.archive }}" \
116- "${{ steps.package.outputs.sha256 }}"
117-
118- publish-release :
119- name : Publish release
120- needs : build-release
121- runs-on : ubuntu-latest
122- steps :
123- - name : Publish release
124- env :
125- GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
126- run : gh release edit "$GITHUB_REF_NAME" --draft=false --repo "$GITHUB_REPOSITORY"
127-
128- publish-crates :
129- name : Publish to crates.io
130- needs : publish-release
131- runs-on : ubuntu-latest
132- steps :
133- - uses : actions/checkout@v6
134- - name : Install Rust toolchain
135- run : rustup toolchain install stable --profile minimal
136- - name : Publish
137- run : cargo publish --locked
19+ go-version-file : go.mod
20+ - uses : goreleaser/goreleaser-action@9ed2f89a662bf1735a48bc8557fd212fa902bebf # v6.2.1
21+ with :
22+ version : ~> v2
23+ args : release --clean
13824 env :
139- CARGO_REGISTRY_TOKEN : ${{ secrets.CARGO_REGISTRY_TOKEN }}
25+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
26+ HOMEBREW_TAP_TOKEN : ${{ secrets.HOMEBREW_TAP_TOKEN }}
0 commit comments