-
Notifications
You must be signed in to change notification settings - Fork 0
168 lines (150 loc) · 6.18 KB
/
Copy pathrelease.yml
File metadata and controls
168 lines (150 loc) · 6.18 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
name: Release & Publish
on:
push:
branches: [ master, main ]
workflow_dispatch:
permissions:
contents: write
jobs:
check-version:
name: Check Version & Create Tag
runs-on: ubuntu-latest
outputs:
is_new_version: ${{ steps.check.outputs.is_new_version }}
version: ${{ steps.check.outputs.version }}
tag: ${{ steps.check.outputs.tag }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract Cargo.toml version & check tag
id: check
run: |
VERSION=$(grep -m1 '^version =' Cargo.toml | cut -d '"' -f 2)
TAG="v$VERSION"
echo "Detected version: $VERSION"
echo "Expected tag: $TAG"
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Tag $TAG already exists. Skipping release."
echo "is_new_version=false" >> $GITHUB_OUTPUT
else
echo "New version detected: $VERSION"
echo "is_new_version=true" >> $GITHUB_OUTPUT
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag=$TAG" >> $GITHUB_OUTPUT
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag -a "$TAG" -m "Release $TAG"
git push origin "$TAG"
fi
publish-crates:
name: Publish to crates.io
needs: check-version
if: needs.check-version.outputs.is_new_version == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
- name: Publish to crates.io
run: cargo publish --allow-dirty
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
build-release:
name: Build (${{ matrix.target }})
needs: check-version
if: needs.check-version.outputs.is_new_version == 'true'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
archive_ext: tar.gz
fossil_url: https://fossil-scm.org/home/uv/fossil-linux-x64-2.28.tar.gz
fossil_bin: fossil
is_zip: false
- target: aarch64-apple-darwin
os: macos-latest
archive_ext: tar.gz
fossil_url: https://fossil-scm.org/home/uv/fossil-mac-arm-2.28.tar.gz
fossil_bin: fossil
is_zip: false
- target: x86_64-apple-darwin
os: macos-13
archive_ext: tar.gz
fossil_url: https://fossil-scm.org/home/uv/fossil-mac-x64-2.28.tar.gz
fossil_bin: fossil
is_zip: false
- target: x86_64-pc-windows-msvc
os: windows-latest
archive_ext: zip
fossil_url: https://fossil-scm.org/home/uv/fossil-w64-2.28.zip
fossil_bin: fossil.exe
is_zip: true
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Build Release Binaries
run: cargo build --release --target ${{ matrix.target }} --bins
- name: Download Fossil Sidecar (Unix)
if: matrix.is_zip == false
run: |
mkdir -p sidecar_tmp
curl -sSL "${{ matrix.fossil_url }}" -o sidecar_tmp/fossil.tar.gz
tar -xzf sidecar_tmp/fossil.tar.gz -C sidecar_tmp
chmod +x sidecar_tmp/${{ matrix.fossil_bin }}
- name: Download Fossil Sidecar (Windows)
if: matrix.is_zip == true
shell: pwsh
run: |
New-Item -ItemType Directory -Force -Path sidecar_tmp
Invoke-WebRequest -Uri "${{ matrix.fossil_url }}" -OutFile sidecar_tmp\fossil.zip
Expand-Archive -Path sidecar_tmp\fossil.zip -DestinationPath sidecar_tmp
- name: Package Archive (Unix)
if: matrix.is_zip == false
run: |
STAGE_DIR="git-chkpt-${{ needs.check-version.outputs.tag }}-${{ matrix.target }}"
mkdir -p "$STAGE_DIR"
cp "target/${{ matrix.target }}/release/git-chkpt" "$STAGE_DIR/"
cp "target/${{ matrix.target }}/release/git-checkpoint" "$STAGE_DIR/"
cp "sidecar_tmp/${{ matrix.fossil_bin }}" "$STAGE_DIR/"
cp README.md "$STAGE_DIR/"
cp README_zh.md "$STAGE_DIR/"
[ -f LICENSE-MIT ] && cp LICENSE-MIT "$STAGE_DIR/" || true
[ -f LICENSE-APACHE ] && cp LICENSE-APACHE "$STAGE_DIR/" || true
tar -czf "${STAGE_DIR}.tar.gz" "$STAGE_DIR"
shasum -a 256 "${STAGE_DIR}.tar.gz" > "${STAGE_DIR}.tar.gz.sha256"
- name: Package Archive (Windows)
if: matrix.is_zip == true
shell: pwsh
run: |
$stage = "git-chkpt-${{ needs.check-version.outputs.tag }}-${{ matrix.target }}"
New-Item -ItemType Directory -Force -Path $stage
Copy-Item "target/${{ matrix.target }}/release/git-chkpt.exe" -Destination "$stage\"
Copy-Item "target/${{ matrix.target }}/release/git-checkpoint.exe" -Destination "$stage\"
Copy-Item "sidecar_tmp\${{ matrix.fossil_bin }}" -Destination "$stage\"
Copy-Item README.md -Destination "$stage\"
Copy-Item README_zh.md -Destination "$stage\"
if (Test-Path LICENSE-MIT) { Copy-Item LICENSE-MIT -Destination "$stage\" }
if (Test-Path LICENSE-APACHE) { Copy-Item LICENSE-APACHE -Destination "$stage\" }
Compress-Archive -Path "$stage\*" -DestinationPath "${stage}.zip"
$hash = (Get-FileHash -Algorithm SHA256 "${stage}.zip").Hash.ToLower()
"$hash ${stage}.zip" | Out-File -Encoding ascii "${stage}.zip.sha256"
- name: Upload Release Asset
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.check-version.outputs.tag }}
name: Release ${{ needs.check-version.outputs.tag }}
files: |
git-chkpt-${{ needs.check-version.outputs.tag }}-${{ matrix.target }}.*
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}