Skip to content

Commit 3388590

Browse files
committed
🔧 Modernize CI/CD pipeline with updated actions
Modernize CI/CD pipeline with updated actions This fun overhaul streamlines our GitHub Actions workflow with: - Upgrade actions/checkout from v2 to v4 with proper git history - Replace multi-step caching with Swatinem/rust-cache for simplicity - Consolidate release jobs into a more efficient workflow - Replace deprecated actions with modern alternatives - Structure artifact handling for better reusability - Simplify permissions and release automation The new pipeline is more maintainable, faster, and future-proof!
1 parent c81cd1c commit 3388590

File tree

1 file changed

+112
-141
lines changed

1 file changed

+112
-141
lines changed

.github/workflows/cicd.yml

Lines changed: 112 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,21 @@ jobs:
2727

2828
steps:
2929
- name: Checkout repository
30-
uses: actions/checkout@v2
30+
uses: actions/checkout@v4
31+
with:
32+
fetch-depth: 0
3133

3234
- name: Install Rust
3335
uses: dtolnay/rust-toolchain@stable
3436
with:
3537
targets: ${{ matrix.target }}
3638

37-
- name: Cache cargo registry
38-
uses: actions/cache@v2
39+
- name: Rust cache
40+
uses: Swatinem/rust-cache@v2
3941
with:
40-
path: |
41-
~/.cargo/registry
42-
~/.cargo/git
43-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
44-
restore-keys: |
45-
${{ runner.os }}-cargo-
42+
# Let action generate cache keys automatically
43+
workspaces: ". -> target"
44+
# The action will automatically include the OS and job name in the key
4645

4746
- name: Build
4847
run: ${{ matrix.cmd }} build --verbose --locked --target ${{ matrix.target }}
@@ -51,185 +50,157 @@ jobs:
5150
run: ${{ matrix.cmd }} test --verbose --locked --target ${{ matrix.target }}
5251

5352
# The following jobs only run on tag pushes (i.e., releases)
54-
create-release:
53+
build-artifacts:
5554
if: startsWith(github.ref, 'refs/tags/')
5655
needs: build-and-test
57-
runs-on: ubuntu-latest
58-
steps:
59-
- name: Create Release
60-
id: create_release
61-
uses: actions/create-release@v1
62-
env:
63-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64-
with:
65-
tag_name: ${{ github.ref }}
66-
release_name: Release ${{ github.ref }}
67-
draft: false
68-
prerelease: false
69-
- name: Output Release URL File
70-
run: echo "${{ steps.create_release.outputs.upload_url }}" > release_url.txt
71-
- name: Save Release URL File for publish
72-
uses: actions/upload-artifact@v4
73-
with:
74-
name: release_url
75-
path: release_url.txt
76-
77-
build-and-publish:
78-
if: startsWith(github.ref, 'refs/tags/')
79-
needs: create-release
8056
runs-on: ${{ matrix.os }}
8157
strategy:
8258
matrix:
8359
include:
8460
- build: linux-amd64
8561
os: ubuntu-latest
8662
target: x86_64-unknown-linux-gnu
87-
cmd: cargo
8863
binary_name: git-iris
89-
# FIXME: Fails when running changelog::tests::test_detail_level_from_str with segfault
90-
#- build: macos-arm64
91-
# os: macos-latest
92-
# target: aarch64-apple-darwin
93-
# cmd: cargo
9464

9565
- build: windows-gnu
9666
os: windows-latest
9767
target: x86_64-pc-windows-gnu
98-
cmd: cargo
9968
binary_name: git-iris.exe
10069

70+
- build: macos-arm64
71+
os: macos-latest
72+
target: aarch64-apple-darwin
73+
binary_name: git-iris
74+
10175
steps:
10276
- name: Checkout code
103-
uses: actions/checkout@v2
77+
uses: actions/checkout@v4
78+
with:
79+
fetch-depth: 0
10480

10581
- name: Install Rust
10682
uses: dtolnay/rust-toolchain@stable
10783
with:
10884
targets: ${{ matrix.target }}
10985

110-
- name: Build
111-
run: ${{ matrix.cmd }} build --verbose --locked --release --target ${{ matrix.target }}
112-
113-
- name: Get Release URL
114-
uses: actions/download-artifact@v4
86+
- name: Rust cache
87+
uses: Swatinem/rust-cache@v2
11588
with:
116-
name: release_url
117-
path: ./
89+
# Let action generate cache keys automatically
90+
workspaces: ". -> target/${{ matrix.target }}/release"
91+
# Additional cache suffix for release builds
92+
cache-on-failure: true
11893

119-
- name: Get Release File Name & Upload URL
120-
id: get_release_info
121-
run: |
122-
value=`cat release_url.txt`
123-
echo ::set-output name=upload_url::$value
124-
shell: bash
94+
- name: Build release binary
95+
run: cargo build --verbose --locked --release --target ${{ matrix.target }}
12596

126-
- name: Upload Release Asset
127-
uses: actions/upload-release-asset@v1
128-
env:
129-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
97+
- name: Upload artifact
98+
uses: actions/upload-artifact@v4
13099
with:
131-
upload_url: ${{ steps.get_release_info.outputs.upload_url }}
132-
asset_path: ./target/${{ matrix.target }}/release/${{ matrix.binary_name }}
133-
asset_name: git-iris-${{ matrix.build }}
134-
asset_content_type: application/octet-stream
100+
name: git-iris-${{ matrix.build }}
101+
path: ./target/${{ matrix.target }}/release/${{ matrix.binary_name }}
102+
if-no-files-found: error
103+
retention-days: 1
135104

136-
build-deb:
105+
build-packages:
137106
if: startsWith(github.ref, 'refs/tags/')
138-
needs: create-release
107+
needs: build-and-test
139108
runs-on: ubuntu-latest
109+
outputs:
110+
version: ${{ steps.get_version.outputs.VERSION }}
140111
steps:
141-
- uses: actions/checkout@v2
112+
- name: Checkout code
113+
uses: actions/checkout@v4
114+
with:
115+
fetch-depth: 0
116+
117+
- name: Get version
118+
id: get_version
119+
run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT
120+
142121
- name: Install Rust
143-
uses: actions-rs/toolchain@v1
122+
uses: dtolnay/rust-toolchain@stable
123+
with:
124+
targets: x86_64-unknown-linux-gnu
125+
126+
- name: Rust cache
127+
uses: Swatinem/rust-cache@v2
144128
with:
145-
profile: minimal
146-
toolchain: stable
129+
# Let action generate cache keys automatically
130+
workspaces: "."
131+
cache-on-failure: true
132+
133+
# Build DEB package
147134
- name: Install cargo-deb
148135
run: cargo install cargo-deb
136+
149137
- name: Build .deb package
150138
run: cargo deb
151-
- name: Get Release URL
152-
uses: actions/download-artifact@v4
153-
with:
154-
name: release_url
155-
- name: Get version
156-
id: get_version
157-
run: echo ::set-output name=VERSION::${GITHUB_REF_NAME#v}
158-
- name: Get Release File Name & Upload URL
159-
id: get_release_info
160-
run: |
161-
value=`cat release_url.txt`
162-
echo ::set-output name=upload_url::$value
163-
- name: Upload .deb package
164-
uses: actions/upload-release-asset@v1
165-
env:
166-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
167-
with:
168-
upload_url: ${{ steps.get_release_info.outputs.upload_url }}
169-
asset_path: ./target/debian/git-iris_${{ steps.get_version.outputs.VERSION }}-1_amd64.deb
170-
asset_name: git-iris_${{ steps.get_version.outputs.VERSION }}-1_amd64.deb
171-
asset_content_type: application/vnd.debian.binary-package
172-
173-
build-rpm:
174-
if: startsWith(github.ref, 'refs/tags/')
175-
needs: create-release
176-
runs-on: ubuntu-latest
177-
steps:
178-
- uses: actions/checkout@v2
179-
- name: Install Rust
180-
uses: actions-rs/toolchain@v1
139+
140+
- name: Upload DEB artifact
141+
uses: actions/upload-artifact@v4
181142
with:
182-
profile: minimal
183-
toolchain: stable
184-
- name: Build Release Binary
185-
run: cargo build --release
143+
name: git-iris-deb
144+
path: ./target/debian/git-iris_${{ steps.get_version.outputs.VERSION }}-1_amd64.deb
145+
if-no-files-found: error
146+
retention-days: 1
147+
148+
# Build RPM package
186149
- name: Install cargo-generate-rpm
187150
run: cargo install cargo-generate-rpm
151+
152+
- name: Build Release Binary for RPM
153+
run: cargo build --release
154+
188155
- name: Build .rpm package
189156
run: cargo generate-rpm
190-
- name: Get Release URL
191-
uses: actions/download-artifact@v4
157+
158+
- name: Upload RPM artifact
159+
uses: actions/upload-artifact@v4
192160
with:
193-
name: release_url
194-
- name: Get version
195-
id: get_version
196-
run: echo ::set-output name=VERSION::${GITHUB_REF_NAME#v}
197-
- name: Get Release File Name & Upload URL
198-
id: get_release_info
199-
run: |
200-
value=`cat release_url.txt`
201-
echo ::set-output name=upload_url::$value
202-
- name: Upload .rpm package
203-
uses: actions/upload-release-asset@v1
204-
env:
205-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
206-
with:
207-
upload_url: ${{ steps.get_release_info.outputs.upload_url }}
208-
asset_path: ./target/generate-rpm/git-iris-${{ steps.get_version.outputs.VERSION }}-1.x86_64.rpm
209-
asset_name: git-iris-${{ steps.get_version.outputs.VERSION }}-1.x86_64.rpm
210-
asset_content_type: application/x-rpm
211-
212-
upload-man-page:
161+
name: git-iris-rpm
162+
path: ./target/generate-rpm/git-iris-${{ steps.get_version.outputs.VERSION }}-1.x86_64.rpm
163+
if-no-files-found: error
164+
retention-days: 1
165+
166+
# Upload man page as artifact
167+
- name: Upload man page artifact
168+
uses: actions/upload-artifact@v4
169+
with:
170+
name: git-iris-man
171+
path: ./git-iris.1
172+
if-no-files-found: error
173+
retention-days: 1
174+
175+
create-release:
213176
if: startsWith(github.ref, 'refs/tags/')
214-
needs: create-release
177+
needs: [build-artifacts, build-packages]
215178
runs-on: ubuntu-latest
179+
permissions:
180+
contents: write
216181
steps:
217-
- uses: actions/checkout@v2
218-
- name: Get Release URL
182+
- name: Checkout code
183+
uses: actions/checkout@v4
184+
with:
185+
fetch-depth: 0
186+
187+
- name: Download all artifacts
219188
uses: actions/download-artifact@v4
220189
with:
221-
name: release_url
222-
- name: Get Release File Name & Upload URL
223-
id: get_release_info
190+
path: ./artifacts
191+
192+
- name: Prepare release assets
224193
run: |
225-
value=`cat release_url.txt`
226-
echo ::set-output name=upload_url::$value
227-
- name: Upload Man Page
228-
uses: actions/upload-release-asset@v1
229-
env:
230-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
231-
with:
232-
upload_url: ${{ steps.get_release_info.outputs.upload_url }}
233-
asset_path: ./git-iris.1
234-
asset_name: git-iris.1
235-
asset_content_type: application/x-troff-man
194+
mkdir -p release-assets
195+
find ./artifacts -type f -exec cp {} ./release-assets/ \;
196+
ls -la ./release-assets
197+
198+
- name: Create GitHub Release
199+
uses: softprops/action-gh-release@v2
200+
with:
201+
name: Release ${{ github.ref_name }}
202+
draft: false
203+
prerelease: false
204+
files: |
205+
./release-assets/*
206+
generate_release_notes: true

0 commit comments

Comments
 (0)