-
Notifications
You must be signed in to change notification settings - Fork 11
143 lines (129 loc) · 4.7 KB
/
Copy pathstage.yml
File metadata and controls
143 lines (129 loc) · 4.7 KB
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
---
name: Stage
on:
pull_request_target:
types:
- closed
branches:
- main
paths:
- "src/main/**"
- "pom.xml"
- ".github/workflows/**"
jobs:
deploy:
runs-on: ubuntu-latest
name: Deploy snapshot
env:
RUN_PYTHON_BIN: ${{ vars.RUN_PYTHON_BIN }}
if: github.repository_owner == 'guacsec' && github.event.pull_request.merged == true && !startsWith(github.head_ref, 'release/')
outputs:
project_version: ${{ steps.project.outputs.version }}
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Setup Java 17
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
cache: maven
- name: Get pom specs
id: project
run: |
echo "version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> "$GITHUB_OUTPUT"
- name: Deploy snapshot to GitHub
if: |
contains(steps.project.outputs.version, 'SNAPSHOT') &&
github.repository == 'guacsec/trustify-da-java-client'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: mvn deploy -Pprepare-deployment,deploy-github -B -ff -DskipTests=true -Dskip.junit_platform=true
release:
runs-on: ubuntu-latest
name: Release snapshot
environment: staging
needs: deploy
if: |
contains(needs.deploy.outputs.project_version, 'SNAPSHOT') &&
github.repository_owner == 'guacsec' && github.event.pull_request.merged == true && !startsWith(github.head_ref, 'release/')
steps:
- name: Check for existing ${{ needs.deploy.outputs.project_version }} release
id: existing_release
uses: actions/github-script@v7
env:
PROJECT_VERSION: ${{ needs.deploy.outputs.project_version }}
continue-on-error: true
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const repo = context.repo;
const tag = process.env.PROJECT_VERSION;
try {
const response = await github.rest.repos.getReleaseByTag({
owner: repo.owner,
repo: repo.repo,
tag: tag
});
core.setOutput('id', response.data.id);
} catch (error) {
if (error.status === 404) {
core.info(`Release for tag '${tag}' not found.`);
} else {
throw error;
}
}
- name: Checkout sources
uses: actions/checkout@v3
- name: Delete ${{ needs.deploy.outputs.project_version }} release if exists
if: ${{ steps.existing_release.outputs.id }}
uses: actions/github-script@v6
env:
RELEASE_ID: ${{ steps.existing_release.outputs.id }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const repo = context.repo;
const releaseId = process.env.RELEASE_ID;
try {
console.log(`Deleting release ID: ${releaseId}`);
await github.rest.repos.deleteRelease({
owner: repo.owner,
repo: repo.repo,
release_id: releaseId
});
console.log(`Deleted release ID: ${releaseId}`);
} catch (error) {
if (error.status === 404) {
console.log(`Release ID: ${releaseId} not found. Skipping deletion.`);
} else {
throw error;
}
}
- name: Delete ${{ needs.deploy.outputs.project_version }} tag if exists
continue-on-error: true
run: git push --delete origin ${{ needs.deploy.outputs.project_version }}
# Workaround for GitHub release cache issue — avoids ghost "draft" releases
- name: Sleep to allow release deletion to propagate
run: sleep 5
- name: Create new ${{ needs.deploy.outputs.project_version }} release
uses: actions/github-script@v7
env:
PROJECT_VERSION: ${{ needs.deploy.outputs.project_version }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const repo = context.repo;
const tag = process.env.PROJECT_VERSION;
console.log(`Creating release for tag: ${tag}`);
const response = await github.rest.repos.createRelease({
owner: repo.owner,
repo: repo.repo,
tag_name: tag,
name: tag,
draft: false,
prerelease: true,
generate_release_notes: true,
make_latest: 'false',
});
console.log(`Release created: ${response.data.html_url}`);