Skip to content

Commit 712890a

Browse files
committed
refactor: update CI/CD workflows to improve job structure and artifact management
1 parent ca92eb1 commit 712890a

4 files changed

Lines changed: 148 additions & 32 deletions

File tree

.github/workflows/README.md

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,47 @@
22

33
This document explains how to use the GitHub Actions workflows in this repository.
44

5-
## CI Workflow (`dotnet-ci.yml`)
5+
## CI Workflow (`main.yml`)
66

77
This workflow automatically runs on every push to the `main` or `master` branch and on pull requests to these branches.
88

9-
### What it does:
10-
1. Checks out the repository
11-
2. Sets up .NET 8.0
12-
3. Restores dependencies
13-
4. Builds the project in Release configuration
14-
5. Runs all tests
9+
### Jobs:
10+
11+
#### 1. Build Job
12+
- Checks out the repository
13+
- Sets up .NET 8.0
14+
- Restores dependencies
15+
- Builds the project in Release configuration
16+
- Caches and uploads build artifacts for the test job
17+
18+
#### 2. Test Job
19+
- Runs after the build job completes
20+
- Downloads the build artifacts
21+
- Runs all tests against the built assemblies
1522

1623
### How to use it:
1724
- You don't need to do anything special to trigger this workflow; it runs automatically on pushes and pull requests.
1825
- Check the status of the workflow runs in the "Actions" tab of your GitHub repository.
1926

20-
## CD Workflow (`dotnet-release.yml`)
27+
## CD Workflow (`release.yml`)
2128

2229
This workflow creates release artifacts for Windows, Linux, and macOS.
2330

24-
### What it does:
25-
1. Checks out the repository
26-
2. Sets up .NET 8.0
27-
3. Restores dependencies and builds the project
28-
4. Creates self-contained executables for Windows, Linux, and macOS
29-
5. Creates zip archives of the builds
30-
6. Uploads the artifacts for download from the Actions tab
31-
7. If triggered by a release, attaches the artifacts to the GitHub release
31+
### Jobs:
32+
33+
#### 1. Build Release Job
34+
- Checks out the repository
35+
- Sets up .NET 8.0
36+
- Restores dependencies and builds the project
37+
- Creates self-contained executables for Windows, Linux, and macOS
38+
- Uploads build outputs as artifacts
39+
40+
#### 2. Package Job
41+
- Runs after the build-release job completes
42+
- Downloads the build outputs
43+
- Creates zip archives of the builds
44+
- Uploads the zip archives as artifacts
45+
- If triggered by a GitHub release, attaches the zip files to the release
3246

3347
### How to trigger it:
3448
1. **Manual Trigger:**

.github/workflows/main.yml

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ on:
77
branches: [ main, master ]
88

99
jobs:
10-
build-and-test:
10+
build:
11+
name: Build
1112
runs-on: ubuntu-latest
1213

1314
steps:
@@ -24,13 +25,9 @@ jobs:
2425

2526
- name: Build
2627
run: dotnet build --no-restore --configuration Release
27-
28-
- name: Run tests
29-
run: dotnet test --no-build --verbosity normal --configuration Release
3028

3129
# Cache the built artifacts for use in other workflows
3230
- name: Cache build outputs
33-
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
3431
uses: actions/cache@v3
3532
with:
3633
path: |
@@ -39,3 +36,38 @@ jobs:
3936
key: ${{ runner.os }}-build-${{ github.sha }}
4037
restore-keys: |
4138
${{ runner.os }}-build-
39+
40+
# Upload build artifacts for the test job
41+
- name: Upload build artifacts
42+
uses: actions/upload-artifact@v3
43+
with:
44+
name: build-artifacts
45+
path: |
46+
BCFileDecryptor/bin/Release
47+
BCFileDecryptorTests/bin/Release
48+
retention-days: 1
49+
50+
test:
51+
name: Test
52+
needs: build
53+
runs-on: ubuntu-latest
54+
55+
steps:
56+
- name: Checkout repository
57+
uses: actions/checkout@v3
58+
59+
- name: Setup .NET
60+
uses: actions/setup-dotnet@v3
61+
with:
62+
dotnet-version: 8.0.x
63+
64+
# Download build artifacts from the build job
65+
- name: Download build artifacts
66+
uses: actions/download-artifact@v3
67+
with:
68+
name: build-artifacts
69+
path: ./
70+
71+
# Run tests using the built artifacts
72+
- name: Run tests
73+
run: dotnet test --no-build --verbosity normal --configuration Release

.github/workflows/release.yml

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ on:
77
types: [created]
88

99
jobs:
10-
publish:
10+
build-release:
11+
name: Build Release
1112
runs-on: ubuntu-latest
1213

1314
steps:
@@ -35,6 +36,56 @@ jobs:
3536
- name: Publish for macOS
3637
run: dotnet publish BCFileDecryptor/BCFileDecryptor.csproj -c Release -r osx-x64 --self-contained true -p:PublishSingleFile=true -p:PublishTrimmed=true -o publish/osx-x64
3738

39+
# Upload raw build output for the packaging job
40+
- name: Upload Windows build output
41+
uses: actions/upload-artifact@v3
42+
with:
43+
name: windows-build-output
44+
path: publish/win-x64/
45+
retention-days: 1
46+
47+
- name: Upload Linux build output
48+
uses: actions/upload-artifact@v3
49+
with:
50+
name: linux-build-output
51+
path: publish/linux-x64/
52+
retention-days: 1
53+
54+
- name: Upload macOS build output
55+
uses: actions/upload-artifact@v3
56+
with:
57+
name: macos-build-output
58+
path: publish/osx-x64/
59+
retention-days: 1
60+
61+
package:
62+
name: Package and Publish
63+
needs: build-release
64+
runs-on: ubuntu-latest
65+
66+
steps:
67+
- name: Checkout repository
68+
uses: actions/checkout@v3
69+
70+
# Download build outputs from the build job
71+
- name: Download Windows build
72+
uses: actions/download-artifact@v3
73+
with:
74+
name: windows-build-output
75+
path: publish/win-x64/
76+
77+
- name: Download Linux build
78+
uses: actions/download-artifact@v3
79+
with:
80+
name: linux-build-output
81+
path: publish/linux-x64/
82+
83+
- name: Download macOS build
84+
uses: actions/download-artifact@v3
85+
with:
86+
name: macos-build-output
87+
path: publish/osx-x64/
88+
3889
# Create zip archives for each platform
3990
- name: Zip Windows build
4091
run: cd publish/win-x64 && zip -r ../../BCFileDecryptor-windows.zip *

README.md

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,23 +111,42 @@ These tests ensure:
111111

112112
## Continuous Integration/Deployment
113113

114-
This project uses GitHub Actions with separate workflows for CI and CD:
114+
This project uses GitHub Actions with separate workflows for CI and CD, each with multiple jobs:
115115

116116
### CI Workflow (.NET CI)
117-
- Automatically runs on each push and pull request
118-
- Builds the project using .NET 8.0
119-
- Runs all unit tests
120-
- Ensures code quality across platforms
117+
The CI workflow has two jobs that run sequentially:
118+
119+
1. **Build Job**
120+
- Automatically runs on each push and pull request
121+
- Builds the project using .NET 8.0
122+
- Uploads build artifacts for the test job
123+
124+
2. **Test Job**
125+
- Runs after the build job completes successfully
126+
- Downloads the build artifacts
127+
- Runs all unit tests
128+
- Ensures code quality across platforms
121129

122130
### CD Workflow (.NET CD - Release)
123-
- Triggered manually or when a new release is created on GitHub
124-
- Generates standalone executables for Windows, Linux, and macOS
125-
- Creates zip archives of the builds
126-
- Uploads build artifacts for easy downloading
127-
- Attaches the binaries to GitHub releases (when triggered by a release)
131+
The CD workflow also has two jobs that run sequentially:
132+
133+
1. **Build Release Job**
134+
- Triggered manually or when a new release is created on GitHub
135+
- Builds the project using .NET 8.0
136+
- Generates standalone executables for Windows, Linux, and macOS
137+
- Uploads build outputs for the packaging job
138+
139+
2. **Package Job**
140+
- Runs after the build release job completes
141+
- Downloads the build outputs
142+
- Creates zip archives of the builds
143+
- Uploads build artifacts for easy downloading
144+
- Attaches the binaries to GitHub releases (when triggered by a release)
128145

129146
This separation allows for:
130147
- Fast feedback on code changes via the CI pipeline
148+
- Better parallelization and resource utilization
149+
- Clear separation of concerns between building and testing/packaging
131150
- Controlled releases via the manual CD pipeline
132151
- Clean, versioned releases with properly packaged artifacts
133152

0 commit comments

Comments
 (0)