Skip to content

Commit 9047e1e

Browse files
committed
github actions
1 parent bfdac81 commit 9047e1e

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed

.github/workflows/release.yaml

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: release
2+
on:
3+
push:
4+
branches:
5+
- main
6+
jobs:
7+
create-release:
8+
name: create-release
9+
runs-on: ubuntu-latest
10+
# env:
11+
# Set to force version number, e.g., when no tag exists.
12+
# RG_VERSION: TEST-0.0.0
13+
outputs:
14+
rg_version: ${{ env.RG_VERSION }}
15+
steps:
16+
- uses: actions/checkout@v3
17+
- name: Get the release version from the tag
18+
shell: bash
19+
if: env.RG_VERSION == ''
20+
run: |
21+
echo "RG_VERSION=$GITHUB_REF_NAME" >> $GITHUB_ENV
22+
echo "version is: ${{ env.RG_VERSION }}"
23+
- name: Create GitHub release
24+
env:
25+
GH_TOKEN: ${{ github.token }}
26+
run: gh release create ${{ env.RG_VERSION }}
27+
build-release:
28+
name: build-release
29+
needs: ['create-release']
30+
runs-on: '${{ matrix.os }}'
31+
env:
32+
CARGO: cargo
33+
TARGET_FLAGS: ''
34+
TARGET_DIR: ./target
35+
RUST_BACKTRACE: 1
36+
PCRE2_SYS_STATIC: 1
37+
strategy:
38+
matrix:
39+
build: [linux, linux-arm, macos, win-msvc, win-gnu, win32-msvc]
40+
include:
41+
- build: linux
42+
os: ubuntu-latest
43+
rust: nightly
44+
target: x86_64-unknown-linux-musl
45+
- build: linux-arm
46+
os: ubuntu-latest
47+
rust: nightly
48+
target: arm-unknown-linux-gnueabihf
49+
- build: macos
50+
os: macos-latest
51+
rust: nightly
52+
target: x86_64-apple-darwin
53+
- build: win-msvc
54+
os: windows-latest
55+
rust: nightly
56+
target: x86_64-pc-windows-msvc
57+
- build: win-gnu
58+
os: windows-latest
59+
rust: nightly-x86_64-gnu
60+
target: x86_64-pc-windows-gnu
61+
- build: win32-msvc
62+
os: windows-latest
63+
rust: nightly
64+
target: i686-pc-windows-msvc
65+
steps:
66+
- name: Checkout repository
67+
uses: actions/checkout@v3
68+
69+
- name: Install Rust
70+
uses: dtolnay/rust-toolchain@master
71+
with:
72+
toolchain: ${{ matrix.rust }}
73+
target: ${{ matrix.target }}
74+
75+
- name: Use cross
76+
run: |
77+
cargo install cross
78+
echo "CARGO=cross" >> $GITHUB_ENV
79+
echo "TARGET_FLAGS=--target ${{ matrix.target }}" >> $GITHUB_ENV
80+
echo "TARGET_DIR=./target/${{ matrix.target }}" >> $GITHUB_ENV
81+
82+
- name: Show commands use for cargo
83+
run: |
84+
echo "cargo command is: ${{ env.CARGO }}"
85+
echo "target flag is: ${{ env.TARGET_FLAGS }}"
86+
echo "target dir is: ${{ env.TARGET_DIR }}"
87+
88+
- name: Build release binary
89+
run: ${{ env.CARGO }} build --verbose --release --features pcre2 ${{ env.TARGET_FLAGS }}
90+
91+
- name: Strip release binary (linux, macos and macos-arm)
92+
if: matrix.build == 'linux' || matrix.os == 'macos'
93+
run: strip "target/${{ matrix.target }}/release/rg"
94+
95+
- name: Strip release binary (arm)
96+
if: matrix.build == 'linux-arm'
97+
run: |
98+
docker run --rm -v \
99+
"$PWD/target:/target:Z" \
100+
rustembedded/cross:arm-unknown-linux-gnueabihf \
101+
arm-linux-gnueabihf-strip \
102+
/target/arm-unknown-linux-gnueabihf/release/rg
103+
- name: Build archive
104+
shell: bash
105+
run: |
106+
staging="ripgrep-${{ needs.create-release.outputs.rg_version }}-${{ matrix.target }}"
107+
mkdir -p "$staging"
108+
if [ "${{ matrix.os }}" = "windows-latest" ]; then
109+
cp "target/${{ matrix.target }}/release/rg.exe" "$staging/"
110+
7z a "$staging.zip" "$staging"
111+
certutil -hashfile "$staging.zip" SHA256 > "$staging.zip.sha256"
112+
echo "ASSET=$staging.zip" >> $GITHUB_ENV
113+
echo "ASSET_SUM=$staging.zip.sha256" >> $GITHUB_ENV
114+
else
115+
cp "target/${{ matrix.target }}/release/rg" "$staging/"
116+
tar czf "$staging.tar.gz" "$staging"
117+
shasum -a 256 "$staging.tar.gz" > "$staging.tar.gz.sha256"
118+
echo "ASSET=$staging.tar.gz" >> $GITHUB_ENV
119+
echo "ASSET_SUM=$staging.tar.gz.sha256" >> $GITHUB_ENV
120+
fi
121+
- name: Upload release archive
122+
env:
123+
GH_TOKEN: ${{ github.token }}
124+
run: gh release upload ${{ needs.create-release.outputs.rg_version }} ${{ env.ASSET }} ${{ env.ASSET_SUM }}

0 commit comments

Comments
 (0)