Skip to content

Commit 0b2d852

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 0b2d852

File tree

1 file changed

+101
-138
lines changed

1 file changed

+101
-138
lines changed

.github/workflows/cicd.yml

Lines changed: 101 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,19 @@ 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+
key: ${{ matrix.os }}-${{ matrix.target }}
4643

4744
- name: Build
4845
run: ${{ matrix.cmd }} build --verbose --locked --target ${{ matrix.target }}
@@ -51,185 +48,151 @@ jobs:
5148
run: ${{ matrix.cmd }} test --verbose --locked --target ${{ matrix.target }}
5249

5350
# The following jobs only run on tag pushes (i.e., releases)
54-
create-release:
51+
build-artifacts:
5552
if: startsWith(github.ref, 'refs/tags/')
5653
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
8054
runs-on: ${{ matrix.os }}
8155
strategy:
8256
matrix:
8357
include:
8458
- build: linux-amd64
8559
os: ubuntu-latest
8660
target: x86_64-unknown-linux-gnu
87-
cmd: cargo
8861
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
9462

9563
- build: windows-gnu
9664
os: windows-latest
9765
target: x86_64-pc-windows-gnu
98-
cmd: cargo
9966
binary_name: git-iris.exe
10067

68+
# Disabled macos-arm64 due to segfault in tests
69+
# - build: macos-arm64
70+
# os: macos-latest
71+
# target: aarch64-apple-darwin
72+
# binary_name: git-iris
73+
10174
steps:
10275
- name: Checkout code
103-
uses: actions/checkout@v2
76+
uses: actions/checkout@v4
77+
with:
78+
fetch-depth: 0
10479

10580
- name: Install Rust
10681
uses: dtolnay/rust-toolchain@stable
10782
with:
10883
targets: ${{ matrix.target }}
10984

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
85+
- name: Rust cache
86+
uses: Swatinem/rust-cache@v2
11587
with:
116-
name: release_url
117-
path: ./
88+
key: ${{ matrix.os }}-${{ matrix.target }}-release
11889

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
125-
126-
- name: Upload Release Asset
127-
uses: actions/upload-release-asset@v1
128-
env:
129-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
90+
- name: Build release binary
91+
run: cargo build --verbose --locked --release --target ${{ matrix.target }}
92+
93+
- name: Upload artifact
94+
uses: actions/upload-artifact@v4
13095
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
96+
name: git-iris-${{ matrix.build }}
97+
path: ./target/${{ matrix.target }}/release/${{ matrix.binary_name }}
98+
if-no-files-found: error
99+
retention-days: 1
135100

136-
build-deb:
101+
build-packages:
137102
if: startsWith(github.ref, 'refs/tags/')
138-
needs: create-release
103+
needs: build-and-test
139104
runs-on: ubuntu-latest
105+
outputs:
106+
version: ${{ steps.get_version.outputs.VERSION }}
140107
steps:
141-
- uses: actions/checkout@v2
108+
- name: Checkout code
109+
uses: actions/checkout@v4
110+
with:
111+
fetch-depth: 0
112+
113+
- name: Get version
114+
id: get_version
115+
run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT
116+
142117
- name: Install Rust
143-
uses: actions-rs/toolchain@v1
118+
uses: dtolnay/rust-toolchain@stable
144119
with:
145-
profile: minimal
146-
toolchain: stable
120+
targets: x86_64-unknown-linux-gnu
121+
122+
- name: Rust cache
123+
uses: Swatinem/rust-cache@v2
124+
125+
# Build DEB package
147126
- name: Install cargo-deb
148127
run: cargo install cargo-deb
128+
149129
- name: Build .deb package
150130
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
172131

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
132+
- name: Upload DEB artifact
133+
uses: actions/upload-artifact@v4
181134
with:
182-
profile: minimal
183-
toolchain: stable
184-
- name: Build Release Binary
185-
run: cargo build --release
135+
name: git-iris-deb
136+
path: ./target/debian/git-iris_${{ steps.get_version.outputs.VERSION }}-1_amd64.deb
137+
if-no-files-found: error
138+
retention-days: 1
139+
140+
# Build RPM package
186141
- name: Install cargo-generate-rpm
187142
run: cargo install cargo-generate-rpm
143+
144+
- name: Build Release Binary for RPM
145+
run: cargo build --release
146+
188147
- name: Build .rpm package
189148
run: cargo generate-rpm
190-
- name: Get Release URL
191-
uses: actions/download-artifact@v4
149+
150+
- name: Upload RPM artifact
151+
uses: actions/upload-artifact@v4
192152
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 }}
153+
name: git-iris-rpm
154+
path: ./target/generate-rpm/git-iris-${{ steps.get_version.outputs.VERSION }}-1.x86_64.rpm
155+
if-no-files-found: error
156+
retention-days: 1
157+
158+
# Upload man page as artifact
159+
- name: Upload man page artifact
160+
uses: actions/upload-artifact@v4
206161
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
162+
name: git-iris-man
163+
path: ./git-iris.1
164+
if-no-files-found: error
165+
retention-days: 1
211166

212-
upload-man-page:
167+
create-release:
213168
if: startsWith(github.ref, 'refs/tags/')
214-
needs: create-release
169+
needs: [build-artifacts, build-packages]
215170
runs-on: ubuntu-latest
171+
permissions:
172+
contents: write
216173
steps:
217-
- uses: actions/checkout@v2
218-
- name: Get Release URL
174+
- name: Checkout code
175+
uses: actions/checkout@v4
176+
with:
177+
fetch-depth: 0
178+
179+
- name: Download all artifacts
219180
uses: actions/download-artifact@v4
220181
with:
221-
name: release_url
222-
- name: Get Release File Name & Upload URL
223-
id: get_release_info
182+
path: ./artifacts
183+
184+
- name: Prepare release assets
224185
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 }}
186+
mkdir -p release-assets
187+
find ./artifacts -type f -exec cp {} ./release-assets/ \;
188+
ls -la ./release-assets
189+
190+
- name: Create GitHub Release
191+
uses: softprops/action-gh-release@v2
231192
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
193+
name: Release ${{ github.ref_name }}
194+
draft: false
195+
prerelease: false
196+
files: |
197+
./release-assets/*
198+
generate_release_notes: true

0 commit comments

Comments
 (0)