Skip to content

Commit 012623b

Browse files
committed
chore: update stage workflow
Signed-off-by: Ruben Romero Montes <rromerom@redhat.com>
1 parent d7be211 commit 012623b

File tree

1 file changed

+39
-25
lines changed

1 file changed

+39
-25
lines changed

.github/workflows/stage.yml

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ jobs:
1515
if: |
1616
github.repository_owner == 'trustification' &&
1717
!startsWith(github.head_ref, 'release/')
18+
concurrency:
19+
group: deploy-snapshot
20+
cancel-in-progress: true
1821
outputs:
1922
java_version: ${{ steps.java-version.outputs.version }}
2023
typescript_version: ${{ steps.typescript-version.outputs.version }}
@@ -35,55 +38,66 @@ jobs:
3538
node-version: '20'
3639
registry-url: 'https://npm.pkg.github.com'
3740
scope: '@trustification'
38-
cache: 'npm'
3941

4042
- name: Get Java project version
4143
id: java-version
4244
run: |
4345
cd api-models/java
44-
echo "version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> "$GITHUB_OUTPUT"
46+
base_version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
47+
# Remove -SNAPSHOT suffix and add SHA
48+
version="${base_version%-SNAPSHOT}-$(echo ${{ github.sha }} | cut -c1-8)"
49+
echo "version=$version" >> "$GITHUB_OUTPUT"
50+
echo "🔍 Java version: $version"
51+
echo "🔍 Commit SHA: ${{ github.sha }}"
52+
echo "🔍 Workflow run ID: ${{ github.run_id }}"
4553
4654
- name: Get TypeScript project version
4755
id: typescript-version
4856
run: |
4957
cd api-models/typescript
50-
echo "version=$(node -p "require('./package.json').version")" >> "$GITHUB_OUTPUT"
58+
base_version=$(node -p "require('./package.json').version")
59+
# Remove -SNAPSHOT suffix and add SHA
60+
version="${base_version%-SNAPSHOT}-$(echo ${{ github.sha }} | cut -c1-8)"
61+
echo "version=$version" >> "$GITHUB_OUTPUT"
62+
echo "🔍 TypeScript version: $version"
5163
5264
- name: Deploy Java snapshot to GitHub
53-
if: |
54-
contains(steps.java-version.outputs.version, 'SNAPSHOT') &&
55-
github.repository == 'trustification/evalguard'
65+
if: github.repository == 'trustification/evalguard'
5666
env:
5767
GITHUB_ACTOR: ${{ github.actor }}
5868
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5969
run: |
60-
echo "📦 Deploying Java snapshot version: ${{ steps.java-version.outputs.version }}"
70+
echo "📦 Deploying Java version: ${{ steps.java-version.outputs.version }}"
6171
cd api-models/java
72+
# Temporarily set the version to the SHA-based version
73+
mvn versions:set -DnewVersion=${{ steps.java-version.outputs.version }}
6274
mvn clean generate-sources compile -Dapi.version=v1
6375
mvn deploy -Dapi.version=v1 -B -ff -DskipTests=true
76+
# Reset to original version
77+
mvn versions:set -DnewVersion=1.0.0-SNAPSHOT
6478
6579
- name: Deploy TypeScript snapshot to GitHub
66-
if: |
67-
contains(steps.typescript-version.outputs.version, 'SNAPSHOT') &&
68-
github.repository == 'trustification/evalguard'
80+
if: github.repository == 'trustification/evalguard'
6981
env:
7082
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7183
run: |
72-
echo "📦 Deploying TypeScript snapshot version: ${{ steps.typescript-version.outputs.version }}"
84+
echo "📦 Deploying TypeScript version: ${{ steps.typescript-version.outputs.version }}"
7385
cd api-models/typescript
86+
# Temporarily set the version to the SHA-based version
87+
npm version ${{ steps.typescript-version.outputs.version }} --no-git-tag-version
7488
npm ci
7589
npm run generate --version v1
7690
npm run build
7791
npm publish
92+
# Reset to original version
93+
npm version 1.0.0-SNAPSHOT --no-git-tag-version
7894
7995
release-snapshot:
8096
runs-on: ubuntu-latest
8197
name: Release snapshot
8298
environment: staging
8399
needs: deploy-snapshot
84100
if: |
85-
(contains(needs.deploy-snapshot.outputs.java_version, 'SNAPSHOT') ||
86-
contains(needs.deploy-snapshot.outputs.typescript_version, 'SNAPSHOT')) &&
87101
github.repository_owner == 'trustification' &&
88102
!startsWith(github.head_ref, 'release/')
89103
steps:
@@ -94,7 +108,7 @@ jobs:
94108
PROJECT_VERSION: ${{ needs.deploy-snapshot.outputs.java_version }}
95109
continue-on-error: true
96110
with:
97-
github-token: ${{ secrets.STAGING_PAT }}
111+
github-token: ${{ secrets.GITHUB_TOKEN }}
98112
script: |
99113
const repo = context.repo;
100114
const tag = process.env.PROJECT_VERSION;
@@ -120,7 +134,7 @@ jobs:
120134
PROJECT_VERSION: ${{ needs.deploy-snapshot.outputs.typescript_version }}
121135
continue-on-error: true
122136
with:
123-
github-token: ${{ secrets.STAGING_PAT }}
137+
github-token: ${{ secrets.GITHUB_TOKEN }}
124138
script: |
125139
const repo = context.repo;
126140
const tag = process.env.PROJECT_VERSION;
@@ -148,7 +162,7 @@ jobs:
148162
env:
149163
RELEASE_ID: ${{ steps.existing-java-release.outputs.id }}
150164
with:
151-
github-token: ${{ secrets.STAGING_PAT }}
165+
github-token: ${{ secrets.GITHUB_TOKEN }}
152166
script: |
153167
const repo = context.repo;
154168
const releaseId = process.env.RELEASE_ID;
@@ -174,7 +188,7 @@ jobs:
174188
env:
175189
RELEASE_ID: ${{ steps.existing-typescript-release.outputs.id }}
176190
with:
177-
github-token: ${{ secrets.STAGING_PAT }}
191+
github-token: ${{ secrets.GITHUB_TOKEN }}
178192
script: |
179193
const repo = context.repo;
180194
const releaseId = process.env.RELEASE_ID;
@@ -195,26 +209,27 @@ jobs:
195209
}
196210
197211
- name: Delete Java tag if exists
198-
if: contains(needs.deploy-snapshot.outputs.java_version, 'SNAPSHOT')
199212
continue-on-error: true
200-
run: git push --delete origin ${{ needs.deploy-snapshot.outputs.java_version }}
213+
run: |
214+
echo "Deleting Java tag: ${{ needs.deploy-snapshot.outputs.java_version }}"
215+
git push --delete origin ${{ needs.deploy-snapshot.outputs.java_version }} || echo "Tag deletion failed, continuing..."
201216
202217
- name: Delete TypeScript tag if exists
203-
if: contains(needs.deploy-snapshot.outputs.typescript_version, 'SNAPSHOT')
204218
continue-on-error: true
205-
run: git push --delete origin ${{ needs.deploy-snapshot.outputs.typescript_version }}
219+
run: |
220+
echo "Deleting TypeScript tag: ${{ needs.deploy-snapshot.outputs.typescript_version }}"
221+
git push --delete origin ${{ needs.deploy-snapshot.outputs.typescript_version }} || echo "Tag deletion failed, continuing..."
206222
207223
# Workaround for GitHub release cache issue — avoids ghost "draft" releases
208224
- name: Sleep to allow release deletion to propagate
209225
run: sleep 5
210226

211227
- name: Create new Java release
212-
if: contains(needs.deploy-snapshot.outputs.java_version, 'SNAPSHOT')
213228
uses: actions/github-script@v7
214229
env:
215230
PROJECT_VERSION: ${{ needs.deploy-snapshot.outputs.java_version }}
216231
with:
217-
github-token: ${{ secrets.STAGING_PAT }}
232+
github-token: ${{ secrets.GITHUB_TOKEN }}
218233
script: |
219234
const repo = context.repo;
220235
const tag = process.env.PROJECT_VERSION;
@@ -232,12 +247,11 @@ jobs:
232247
console.log(`Java release created: ${response.data.html_url}`);
233248
234249
- name: Create new TypeScript release
235-
if: contains(needs.deploy-snapshot.outputs.typescript_version, 'SNAPSHOT')
236250
uses: actions/github-script@v7
237251
env:
238252
PROJECT_VERSION: ${{ needs.deploy-snapshot.outputs.typescript_version }}
239253
with:
240-
github-token: ${{ secrets.STAGING_PAT }}
254+
github-token: ${{ secrets.GITHUB_TOKEN }}
241255
script: |
242256
const repo = context.repo;
243257
const tag = process.env.PROJECT_VERSION;

0 commit comments

Comments
 (0)