-
Notifications
You must be signed in to change notification settings - Fork 0
144 lines (121 loc) · 4.24 KB
/
GithubActions.yml
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
# Workflow to build and release OcrInspector for production
name: OCR Inspector Production
# Permissions for the workflow
permissions:
contents: write
# Trigger workflow on push to the main branch
on:
push:
branches:
- main
# Set environment variables
env:
artifactStagingDirectory: ${{ github.workspace }}/artifact_staging
artifactType: 'Production'
binariesDirectory: ${{ github.workspace }}/binaries
buildConfiguration: 'Release'
buildPlatform: 'any cpu'
projectName: OcrInspector
# Default settings for all run steps
defaults:
run:
working-directory: src
# Define jobs for the workflow
jobs:
# Job to get the version of the build
new-version:
name: New Version
runs-on: windows-latest
# Outputs of the job
outputs:
buildVersion: ${{ steps.parse-version.outputs.version }}
validVersion: ${{ steps.validate-version.outputs.valid }}
steps:
# Step to checkout the repository
- name: Checkout repository
uses: actions/checkout@v4
# Step to parse the build version for GitHub tag
- name: Parse Build Version for GitHub Tag
id: parse-version
shell: pwsh
run: echo "version=$(Get-Date -UFormat '%Y.%m.%d').${{ github.run_number }}" >> $env:GITHUB_OUTPUT
# Step to validate the parsed version
- name: Validate Version ${{ steps.parse-version.outputs.version }}
id: validate-version
shell: pwsh
run: |
$version = "${{ steps.parse-version.outputs.version }}"
echo "valid=$($version -match '^\d+(\.\d+){3}$')" >> $env:GITHUB_OUTPUT
# Job to build and publish the project
build:
name: Build & Publish Version ${{ needs.new-version.outputs.buildVersion }}
runs-on: windows-latest
needs: new-version
if: ${{ needs.new-version.result == 'success' && needs.new-version.outputs.validVersion == 'True' }}
# Outputs of the job
outputs:
buildVersion: ${{ needs.new-version.outputs.buildVersion }}
# Set environment variables specific to the build job
env:
buildVersion: ${{ needs.new-version.outputs.buildVersion }}
steps:
# Step to checkout the repository
- name: Checkout repository
uses: actions/checkout@v4
# Step to setup .NET Core SDK
- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8
# Step to restore packages
- name: Restore Packages
shell: pwsh
run: dotnet restore
# Step to publish the project
- name: Publish
shell: pwsh
run: dotnet publish -c Release --self-contained -r win-x64
# Step to create a build artifact
- name: Create Build Artifact
shell: pwsh
run: |
New-Item -Path "${{ env.artifactStagingDirectory }}" -ItemType Directory
Compress-Archive `
-Path OcrInspector/bin/Release/net8.0-windows/win-x64./publish/* `
-DestinationPath ${{ env.artifactStagingDirectory }}/${{ env.projectName }}.${{ env.buildVersion }}-win-x64.zip
# Step to upload the build artifact
- name: Upload a Build Artifact
uses: actions/upload-artifact@v4
with:
name: drop
path: ${{ env.artifactStagingDirectory }}/*.zip
# Job to create a GitHub release and tag the new version
create-release:
name: New GitHub Release Version ${{ needs.new-version.outputs.buildVersion }}
runs-on: windows-latest
needs:
- new-version
- build
if: success()
# Set environment variables specific to the release job
env:
buildVersion: ${{ needs.new-version.outputs.buildVersion }}
steps:
# Step to checkout the repository
- name: Checkout repository
uses: actions/checkout@v4
# Step to download build artifacts
- name: Download Build Artifacts
uses: actions/download-artifact@v4
with:
name: drop
# Step to create a GitHub release and tag
- name: Create GitHub Release & Tag v${{ env.buildVersion }}
uses: softprops/action-gh-release@v2
with:
files: ./${{ env.projectName }}.${{ env.buildVersion }}-win-x64.zip
tag_name: v${{ env.buildVersion }}
name: ${{ env.artifactType }} v${{ env.buildVersion }}
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}