1+ # Workflow to build and release OcrInspector for production
2+ name : OCR Inspector Production
3+
4+ # Permissions for the workflow
5+ permissions :
6+ contents : write
7+
8+ # Trigger workflow on push to the main branch
9+ on :
10+ push :
11+ branches :
12+ - main
13+
14+ # Set environment variables
15+ env :
16+ artifactStagingDirectory : ${{ github.workspace }}/artifact_staging
17+ artifactType : ' Production'
18+ binariesDirectory : ${{ github.workspace }}/binaries
19+ buildConfiguration : ' Release'
20+ buildPlatform : ' any cpu'
21+ projectName : UiaXpathTester
22+
23+ # Default settings for all run steps
24+ defaults :
25+ run :
26+ working-directory : src
27+
28+ # Define jobs for the workflow
29+ jobs :
30+ # Job to get the version of the build
31+ new-version :
32+ name : New Version
33+ runs-on : windows-latest
34+
35+ # Outputs of the job
36+ outputs :
37+ buildVersion : ${{ steps.parse-version.outputs.version }}
38+ validVersion : ${{ steps.validate-version.outputs.valid }}
39+
40+ steps :
41+ # Step to checkout the repository
42+ - name : Checkout repository
43+ uses : actions/checkout@v4
44+
45+ # Step to parse the build version for GitHub tag
46+ - name : Parse Build Version for GitHub Tag
47+ id : parse-version
48+ shell : pwsh
49+ run : echo "version=$(Get-Date -UFormat '%Y.%m.%d').${{ github.run_number }}" >> $env:GITHUB_OUTPUT
50+
51+ # Step to validate the parsed version
52+ - name : Validate Version ${{ steps.parse-version.outputs.version }}
53+ id : validate-version
54+ shell : pwsh
55+ run : |
56+ $version = "${{ steps.parse-version.outputs.version }}"
57+ echo "valid=$($version -match '^\d+(\.\d+){3}$')" >> $env:GITHUB_OUTPUT
58+
59+ # Job to build and publish the project
60+ build :
61+ name : Build & Publish Version ${{ needs.new-version.outputs.buildVersion }}
62+ runs-on : windows-latest
63+ needs : new-version
64+ if : ${{ needs.new-version.result == 'success' && needs.new-version.outputs.validVersion == 'True' }}
65+
66+ # Outputs of the job
67+ outputs :
68+ buildVersion : ${{ needs.new-version.outputs.buildVersion }}
69+
70+ # Set environment variables specific to the build job
71+ env :
72+ buildVersion : ${{ needs.new-version.outputs.buildVersion }}
73+
74+ steps :
75+ # Step to checkout the repository
76+ - name : Checkout repository
77+ uses : actions/checkout@v4
78+
79+ # Step to setup .NET Core SDK
80+ - name : Setup .NET Core SDK
81+ uses : actions/setup-dotnet@v4
82+ with :
83+ dotnet-version : 8
84+
85+ # Step to restore packages
86+ - name : Restore Packages
87+ shell : pwsh
88+ run : dotnet restore
89+
90+ # Step to publish the project
91+ - name : Publish
92+ shell : pwsh
93+ run : dotnet publish -c Release --self-contained -r win-x64
94+
95+ # Step to create a build artifact
96+ - name : Create Build Artifact
97+ shell : pwsh
98+ run : |
99+ New-Item -Path "${{ env.artifactStagingDirectory }}" -ItemType Directory
100+ Compress-Archive `
101+ -Path ${{ env.projectName }}/bin/Release/net8.0-windows/win-x64./publish/* `
102+ -DestinationPath ${{ env.artifactStagingDirectory }}/${{ env.projectName }}.${{ env.buildVersion }}-win-x64.zip
103+
104+ # Step to upload the build artifact
105+ - name : Upload a Build Artifact
106+ uses : actions/upload-artifact@v4
107+ with :
108+ name : drop
109+ path : ${{ env.artifactStagingDirectory }}/*.zip
110+
111+ # Job to create a GitHub release and tag the new version
112+ create-release :
113+ name : New GitHub Release Version ${{ needs.new-version.outputs.buildVersion }}
114+ runs-on : windows-latest
115+ needs :
116+ - new-version
117+ - build
118+ if : success()
119+
120+ # Set environment variables specific to the release job
121+ env :
122+ buildVersion : ${{ needs.new-version.outputs.buildVersion }}
123+
124+ steps :
125+ # Step to checkout the repository
126+ - name : Checkout repository
127+ uses : actions/checkout@v4
128+
129+ # Step to download build artifacts
130+ - name : Download Build Artifacts
131+ uses : actions/download-artifact@v4
132+ with :
133+ name : drop
134+
135+ # Step to create a GitHub release and tag
136+ - name : Create GitHub Release & Tag v${{ env.buildVersion }}
137+ uses : softprops/action-gh-release@v2
138+ with :
139+ files : ./${{ env.projectName }}.${{ env.buildVersion }}-win-x64.zip
140+ tag_name : v${{ env.buildVersion }}
141+ name : ${{ env.artifactType }} v${{ env.buildVersion }}
142+ generate_release_notes : true
143+ env :
144+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments