Skip to content

Commit 448fb4d

Browse files
authored
Merge pull request #238 from jindrapetrik/gha
New github actions
2 parents 4605bbc + 6c2c76c commit 448fb4d

File tree

3 files changed

+320
-254
lines changed

3 files changed

+320
-254
lines changed
Lines changed: 22 additions & 254 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
name: Build
22

3+
concurrency:
4+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
5+
cancel-in-progress: true
6+
37
on:
48
push:
59
tags:
@@ -13,201 +17,43 @@ on:
1317
- master
1418

1519
env:
16-
CICD_REPO_SLUG: jindrapetrik/jpexs-decompiler
17-
CICD_REFTYPE: ${{ github.ref_type }}
18-
CICD_REFNAME: ${{ github.ref_name }}
19-
CICD_COMMIT: ${{ github.sha }}
20-
CICD_NAME: GitHub Actions
21-
CICD_EMAIL: GitHub
22-
CICD_EVENTNAME: ${{ github.event_name }}
23-
NIGHTLY_BRANCH: dev
2420
GITHUB_USER: jindrapetrik
2521
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2622

2723
permissions:
28-
contents: write
2924
id-token: write
3025

3126
jobs:
3227
compute-version:
3328
name: Compute version
29+
uses: ./.github/workflows/version.yml
30+
secrets: inherit
31+
32+
build:
33+
name: Build and test
3434
runs-on: windows-latest
35-
36-
outputs:
37-
doRelease: ${{ steps.vars.outputs.doRelease }}
38-
verMajor: ${{ steps.vars.outputs.verMajor }}
39-
verMinor: ${{ steps.vars.outputs.verMinor }}
40-
verRelease: ${{ steps.vars.outputs.verRelease }}
41-
verBuild: ${{ steps.vars.outputs.verBuild }}
42-
verRevision: ${{ steps.vars.outputs.verRevision }}
43-
verLong: ${{ steps.vars.outputs.verLong }}
44-
verRaw: ${{ steps.vars.outputs.verRaw }}
45-
verShort: ${{ steps.vars.outputs.verShort }}
46-
verDebug: ${{ steps.vars.outputs.verDebug }}
47-
verOldTag: ${{ steps.vars.outputs.verOldTag }}
48-
verTag: ${{ steps.vars.outputs.verTag }}
49-
verTitle: ${{ steps.vars.outputs.verTitle }}
50-
35+
needs: compute-version
5136
steps:
5237
- name: Checkout
53-
uses: actions/checkout@v4
54-
with:
55-
fetch-depth: 0
56-
57-
- name: Compute variables
58-
id: vars
59-
shell: pwsh
60-
run: |
61-
Set-StrictMode -Version Latest
62-
$ErrorActionPreference = 'Stop'
63-
64-
# Ensure tags exist locally
65-
git fetch --tags --force | Out-Null
66-
67-
$ref = "${env:GITHUB_REF}" # e.g. refs/tags/version1.2.3 or refs/heads/dev
68-
$refName = "${env:GITHUB_REF_NAME}" # e.g. version1.2.3 or dev
69-
$isTag = $ref.StartsWith("refs/tags/")
70-
$isDev = ($ref -eq "refs/heads/dev")
71-
72-
$H = (git rev-parse HEAD).Trim()
73-
74-
function Set-Var([string]$name, [string]$value) {
75-
# For later steps in the SAME job
76-
"$name=$value" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
77-
# For later jobs (job outputs)
78-
"$name=$value" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
79-
}
80-
81-
# Defaults
82-
Set-Var "doRelease" "false"
83-
Set-Var "verMajor" ""
84-
Set-Var "verMinor" ""
85-
Set-Var "verRelease" ""
86-
Set-Var "verBuild" ""
87-
Set-Var "verRevision" ""
88-
Set-Var "verLong" ""
89-
Set-Var "verRaw" ""
90-
Set-Var "verShort" ""
91-
Set-Var "verDebug" ""
92-
Set-Var "verOldTag" ""
93-
Set-Var "verTag" ""
94-
Set-Var "verTitle" ""
95-
96-
97-
# Case 1: Tag versionX.Y.Z
98-
if ($isTag -and ($refName -match '^version(\d+)\.(\d+)\.(\d+)$')) {
99-
$X = $Matches[1]
100-
$Y = $Matches[2]
101-
$Z = $Matches[3]
102-
103-
Set-Var "verMajor" $X
104-
Set-Var "verMinor" $Y
105-
Set-Var "verRelease" $Z
106-
Set-Var "verBuild" "0"
107-
Set-Var "verRevision" $H
108-
109-
$raw = "$X.$Y.$Z"
110-
Set-Var "verRaw" $raw
111-
Set-Var "verShort" $raw
112-
Set-Var "verLong" $raw
113-
114-
Set-Var "verDebug" "false"
115-
Set-Var "verOldTag" ""
116-
Set-Var "verTag" $refName
117-
118-
Set-Var "doRelease" "true"
119-
Set-Var "verTitle" "version $raw"
120-
121-
exit 0
122-
}
123-
124-
# Case 2: dev branch
125-
if ($isDev) {
126-
# Find latest nightlyN tag (max N)
127-
$nightlyTags = git tag --list 'nightly*'
128-
$maxN = -1
129-
foreach ($t in $nightlyTags) {
130-
if ($t -match '^nightly(\d+)$') {
131-
$n = [int]$Matches[1]
132-
if ($n -gt $maxN) { $maxN = $n }
133-
}
134-
}
135-
if ($maxN -lt 0) { $maxN = 0 } # if none exists, start from 0 so M becomes 1
136-
$M = $maxN + 1
137-
138-
# Find latest versionX.Y.Z tag by numeric comparison (major,minor,release)
139-
$versionTags = git tag --list 'version*'
140-
$best = $null
141-
foreach ($t in $versionTags) {
142-
if ($t -match '^version(\d+)\.(\d+)\.(\d+)$') {
143-
$maj = [int]$Matches[1]
144-
$min = [int]$Matches[2]
145-
$rel = [int]$Matches[3]
146-
$obj = [pscustomobject]@{ Tag=$t; Major=$maj; Minor=$min; Release=$rel }
147-
if (-not $best) {
148-
$best = $obj
149-
} else {
150-
if ($obj.Major -gt $best.Major -or
151-
($obj.Major -eq $best.Major -and $obj.Minor -gt $best.Minor) -or
152-
($obj.Major -eq $best.Major -and $obj.Minor -eq $best.Minor -and $obj.Release -gt $best.Release)) {
153-
$best = $obj
154-
}
155-
}
156-
}
157-
}
158-
159-
if (-not $best) {
160-
throw "No versionX.Y.Z tag found. Create at least one version tag (e.g. version1.0.0)."
161-
}
162-
163-
$X = $best.Major
164-
$Y = $best.Minor
165-
$Z = $best.Release
166-
167-
Set-Var "verMajor" "$X"
168-
Set-Var "verMinor" "$Y"
169-
Set-Var "verRelease" "$Z"
170-
Set-Var "verBuild" "$M"
171-
Set-Var "verRevision" $H
172-
173-
Set-Var "verLong" "$X.$Y.$Z nightly build $M"
174-
Set-Var "verRaw" "$X.$Y.$Z"
175-
Set-Var "verShort" "$X.$Y.$Z`_nightly$M"
176-
Set-Var "verDebug" "true"
177-
Set-Var "verOldTag" "nightly$maxN"
178-
179-
Set-Var "verTag" "nightly$M"
180-
181-
Set-Var "verTitle" "(PREVIEW) version $X.$Y.$Z nightly $M"
182-
183-
Set-Var "doRelease" "true"
184-
exit 0
185-
}
186-
187-
# Other cases: doRelease stays false
188-
exit 0
38+
uses: actions/checkout@v3
39+
18940
- name: Prepare version info property file
41+
shell: pwsh
19042
run: |
19143
$VERSION_PROP_FILE = "version.properties"
19244
echo "">$VERSION_PROP_FILE
193-
echo "major=${{ steps.vars.outputs.verMajor }}">>$VERSION_PROP_FILE
194-
echo "minor=${{ steps.vars.outputs.verMinor }}">>$VERSION_PROP_FILE
195-
echo "release=${{ steps.vars.outputs.verRelease }}">>$VERSION_PROP_FILE
196-
echo "build=${{ steps.vars.outputs.verBuild }}">>$VERSION_PROP_FILE
197-
echo "revision=${{ steps.vars.outputs.verRevision }}">>$VERSION_PROP_FILE
198-
echo "debug=${{ steps.vars.outputs.verDebug }}">>$VERSION_PROP_FILE
45+
echo "major=${{ needs.compute-version.outputs.verMajor }}">>$VERSION_PROP_FILE
46+
echo "minor=${{ needs.compute-version.outputs.verMinor }}">>$VERSION_PROP_FILE
47+
echo "release=${{ needs.compute-version.outputs.verRelease }}">>$VERSION_PROP_FILE
48+
echo "build=${{ needs.compute-version.outputs.verBuild }}">>$VERSION_PROP_FILE
49+
echo "revision=${{ needs.compute-version.outputs.verRevision }}">>$VERSION_PROP_FILE
50+
echo "debug=${{ needs.compute-version.outputs.verDebug }}">>$VERSION_PROP_FILE
51+
19952
- name: Upload version.properties artifact
20053
uses: actions/upload-artifact@v4
20154
with:
20255
name: version_properties
203-
path: version.properties
204-
build:
205-
name: Build and test
206-
runs-on: windows-latest
207-
needs: compute-version
208-
steps:
209-
- name: Checkout
210-
uses: actions/checkout@v3
56+
path: version.properties
21157

21258
- name: Set up JDK
21359
uses: actions/setup-java@v4
@@ -839,83 +685,5 @@ jobs:
839685
uses: actions/upload-artifact@v4
840686
with:
841687
name: packages
842-
path: releases
843-
844-
deploy:
845-
name: Deploy to GitHub
846-
runs-on: ubuntu-latest
847-
if: needs.compute-version.outputs.doRelease == 'true'
848-
needs:
849-
- compute-version
850-
- packages
851-
steps:
852-
- name: Checkout
853-
uses: actions/checkout@v3
854-
855-
- name: Set up PHP
856-
run: |
857-
sudo apt-get update -y -qq
858-
sudo apt-get install -y -qq php
859-
860-
- name: Download packages artifact
861-
uses: actions/download-artifact@v4
862-
with:
863-
name: packages
864-
path: releases/
865-
866-
- name: Download lib javadoc artifact
867-
uses: actions/download-artifact@v4
868-
with:
869-
name: lib_javadoc
870-
path: releases/
871-
872-
- name: Generate release description
873-
run: php cicd_scripts/format_release_info.php -filever "${{ needs.compute-version.outputs.verShort }}" Unreleased ${{ needs.compute-version.outputs.verTag }} ./CHANGELOG.md "${{ env.CICD_REPO_SLUG }}" > ./release_notes.md
874-
875-
- name: Upload release notes artifact
876-
uses: actions/upload-artifact@v4
877-
with:
878-
name: release_notes
879-
path: ./release_notes.md
880-
881-
- name: Create tag
882-
if: needs.compute-version.outputs.verDebug == 'true'
883-
run: |
884-
TAG="${{ needs.compute-version.outputs.verTag }}"
885-
git fetch --tags --force
886-
887-
if git rev-parse "$TAG" >/dev/null 2>&1; then
888-
echo "Tag $TAG already exists -> skipping tag creation."
889-
exit 0
890-
fi
891-
892-
git config user.name "github-actions[bot]"
893-
git config user.email "github-actions[bot]@users.noreply.github.com"
894-
895-
git tag "$TAG"
896-
git push origin "$TAG"
897-
898-
- name: Create GitHub Release + upload assets
899-
uses: softprops/action-gh-release@v2
900-
with:
901-
tag_name: ${{ needs.compute-version.outputs.verTag }}
902-
name: ${{ needs.compute-version.outputs.verTitle }}
903-
body_path: ./release_notes.md
904-
preserve_order: true
905-
prerelease: ${{ needs.compute-version.outputs.verDebug == 'true'}}
906-
fail_on_unmatched_files: true
907-
files: |
908-
releases/ffdec_${{ needs.compute-version.outputs.verShort }}.msi
909-
releases/ffdec_${{ needs.compute-version.outputs.verShort }}.zip
910-
releases/ffdec_${{ needs.compute-version.outputs.verShort }}.deb
911-
releases/ffdec_${{ needs.compute-version.outputs.verShort }}.pkg
912-
releases/ffdec_${{ needs.compute-version.outputs.verShort }}_macosx.zip
913-
releases/ffdec_lib_${{ needs.compute-version.outputs.verShort }}.zip
914-
releases/ffdec_lib_javadoc_${{ needs.compute-version.outputs.verShort }}.zip
915-
- name: Remove old nightly
916-
if: needs.compute-version.outputs.verDebug == 'true'
917-
env:
918-
GH_TOKEN: ${{ github.token }}
919-
run: |
920-
gh release delete ${{needs.compute-version.outputs.verOldTag}} --yes --cleanup-tag
688+
path: releases
921689

0 commit comments

Comments
 (0)