-
Notifications
You must be signed in to change notification settings - Fork 19
/
action.yml
306 lines (281 loc) · 11.7 KB
/
action.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
name: 'Publish Native Installers'
description: Publish jDeploy Bundles on Github or npm
author: shannah
branding:
icon: archive
color: blue
inputs:
deploy_target:
description: Target deployment destination (npm or github).
# Options are github or npm
default: github
github_token:
description: Github token
required: false
npm_token:
description: npm token
required: false
jdeploy_version:
description: The version of Jdeploy
default: '4.1.2'
target_repository:
description: Optional target repository where to publish releases.
required: false
default: ${{ github.repository }}
runs:
using: composite
steps:
- name: Check Deploy Target
if: ${{ inputs.deploy_target != 'github' && inputs.deploy_target != 'npm' }}
shell: bash
run: |
echo "Unsupported jdeploy deploy_target: ${{ inputs.deploy_target }}"
exit 1
- name: Check Github Deployment Inputs
if: ${{ inputs.deploy_target == 'github' && inputs.github_token == '' }}
shell: bash
run: |
echo "jdeploy action missing github_token parameter"
exit 1
- name: Check npm Deployment Inputs
if: ${{ inputs.deploy_target == 'npm' && inputs.npm_token == '' }}
shell: bash
run: |
echo "jdeploy action missing npm_token parameter"
exit 1
- name: Set up Git Config
shell: bash
run: |
git config user.name "GitHub Actions Bot"
git config user.email "<>"
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: '16.x'
registry-url: 'https://registry.npmjs.org'
- name: Save Original JAVA_HOME
if: env.JAVA_HOME
shell: bash
run: |
echo "ORIGINAL_JAVA_HOME=${JAVA_HOME}" >> $GITHUB_ENV
- name: Set up Isolated Java for jDeploy (only for git:// version)
if: ${{ startsWith(inputs.jdeploy_version, 'git://') }}
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'zulu'
cache: maven
id: setup-java-jdeploy
- name: Configure Java for jDeploy Only
if: ${{ startsWith(inputs.jdeploy_version, 'git://') }}
shell: bash
run: |
echo "JAVA_HOME_JDEPLOY=${{ steps.setup-java-jdeploy.outputs.path }}" >> $GITHUB_ENV
echo "Using isolated JAVA_HOME for jDeploy: $JAVA_HOME_JDEPLOY"
- name: Restore Original JAVA_HOME
if: ${{ startsWith(inputs.jdeploy_version, 'git://') && env.ORIGINAL_JAVA_HOME }}
shell: bash
run: |
echo "Restoring original JAVA_HOME"
echo "JAVA_HOME=${ORIGINAL_JAVA_HOME}" >> $GITHUB_ENV
- name: Set jDeploy Ref
if: ${{ startsWith(inputs.jdeploy_version, 'git://') }}
shell: bash
run: |
jdeploy_version="${{ inputs.jdeploy_version }}"
JDEPLOY_REF="${jdeploy_version#git://}"
echo "JDEPLOY_REF=$JDEPLOY_REF" >> $GITHUB_ENV
- name: Checkout jDeploy Source
if: ${{ startsWith(inputs.jdeploy_version, 'git://') }}
uses: actions/checkout@v3
with:
repository: 'shannah/jdeploy'
path: './jdeploy-source'
ref: '${{ env.JDEPLOY_REF }}'
- name: Install jDeploy from Source
id: jdeploy_install_source
if: ${{ startsWith(inputs.jdeploy_version, 'git://') }}
shell: bash
run: |
export JAVA_HOME="$JAVA_HOME_JDEPLOY"
export PATH="$JAVA_HOME/bin:$PATH"
echo "Building jDeploy from source..."
cd jdeploy-source/shared
mvn clean install -DskipTests --batch-mode --no-transfer-progress
cd ../cli
mvn clean package -DskipTests --batch-mode --no-transfer-progress
npm install
npm link
echo "jdeploy_exec=$(which jdeploy)" >> $GITHUB_ENV
env:
MAVEN_OPTS: "-Xmx2g"
- name: Install jDeploy from NPM
id: jdeploy_install_standard
if: ${{ !startsWith(inputs.jdeploy_version, 'git://') }}
shell: bash
run: |
echo "jdeploy_exec=npx jdeploy@${JDEPLOY_VERSION}" >> $GITHUB_ENV
env:
JDEPLOY_VERSION: ${{ inputs.jdeploy_version }}
- name: Set jdeploy.jdeployVersion for Branch
if: ${{ inputs.deploy_target == 'github' && github.ref_type == 'branch' }}
shell: bash
run: |
if [[ "${{ startsWith(inputs.jdeploy_version, 'git://') }}" == "true" ]]; then
npm pkg set jdeploy.jdeployVersion='latest'
else
npm pkg set jdeploy.jdeployVersion='${{ inputs.jdeploy_version }}'
fi
npm pkg set version="0.0.0-${{ github.ref_name }}"
npm pkg set jdeploy.commitHash="$GITHUB_SHA"
GITHUB_REPOSITORY=${{ inputs.target_repository }} $jdeploy_exec github-prepare-release
env:
GH_TOKEN: ${{ github.actor }}:${{ inputs.github_token }}
- name: Sanitize version name
shell: bash
if: ${{ github.ref_type == 'tag' }}
run: |
TAG_VERSION=${{ github.ref_name }}
if [[ $TAG_VERSION} = v* ]]; then
echo "TAG_VERSION=${TAG_VERSION:1}" >> $GITHUB_ENV
else
echo "TAG_VERSION=${TAG_VERSION}" >> $GITHUB_ENV
fi
- name: Prepare Installer Bundles for Branch
if: ${{ inputs.deploy_target == 'github' && github.ref_type == 'branch' }}
shell: bash
run: |
npm pkg set version="0.0.0-${{ github.ref_name }}"
if [[ "${{ startsWith(inputs.jdeploy_version, 'git://') }}" == "true" ]]; then
npm pkg set jdeploy.jdeployVersion='latest'
else
npm pkg set jdeploy.jdeployVersion='${{ inputs.jdeploy_version }}'
fi
npm pkg set jdeploy.commitHash="$GITHUB_SHA"
GITHUB_REPOSITORY=${{ inputs.target_repository }} $jdeploy_exec github-prepare-release
env:
GH_TOKEN: ${{ github.actor }}:${{ inputs.github_token }}
- name: Prepare Installer Bundles for Tag
if: ${{ inputs.deploy_target == 'github' && github.ref_type == 'tag' }}
shell: bash
run: |
npm pkg set version="$TAG_VERSION"
if [[ "${{ startsWith(inputs.jdeploy_version, 'git://') }}" == "true" ]]; then
npm pkg set jdeploy.jdeployVersion='latest'
else
npm pkg set jdeploy.jdeployVersion='${{ inputs.jdeploy_version }}'
fi
npm pkg set jdeploy.commitHash="$GITHUB_SHA"
npm pkg set jdeploy.gitTag="${{ github.ref_name }}"
GITHUB_REPOSITORY=${{ inputs.target_repository }} $jdeploy_exec github-prepare-release
env:
GH_TOKEN: ${{ github.actor }}:${{ inputs.github_token }}
- name: Publish package-info.json to Github
uses: marvinpinto/action-automatic-releases@latest
if: ${{ inputs.deploy_target == 'github' && inputs.target_repository == github.repository }}
with:
repo_token: "${{ inputs.github_token }}"
automatic_release_tag: "jdeploy"
prerelease: true
title: "jDeploy Package Info"
files: ./jdeploy/github-release-files/package-info.json
- name: Publish package-info.json to Github
if: ${{ inputs.deploy_target == 'github' && inputs.target_repository != github.repository }}
shell: bash
run: |
gh release delete -R '${{ inputs.target_repository }}' jdeploy || true
gh release create -R '${{ inputs.target_repository }}' jdeploy ./jdeploy/github-release-files/package-info.json
env:
GH_TOKEN: ${{ inputs.github_token }}
- name: Upload files to Github Snapshot Release for Branch
if: ${{ inputs.deploy_target == 'github' && github.ref_type == 'branch' && inputs.target_repository == github.repository }}
uses: marvinpinto/action-automatic-releases@latest
with:
repo_token: "${{ inputs.github_token }}"
automatic_release_tag: "${{ github.ref_name }}"
prerelease: true
title: "Native Bundles (${{ github.ref_name }})"
files: "./jdeploy/github-release-files/*"
- name: Upload files to Github Snapshot Release for Branch
if: ${{ inputs.deploy_target == 'github' && inputs.target_repository != github.repository }}
shell: bash
run: |
gh release delete -R '${{ inputs.target_repository }}' '${{ github.ref_name }}' || true
gh release create -R '${{ inputs.target_repository }}' '${{ github.ref_name }}' -F ./jdeploy/github-release-files/jdeploy-release-notes.md ./jdeploy/github-release-files/*
env:
GH_TOKEN: ${{ inputs.github_token }}
- name: Upload Files to Github Release for Tag
if: ${{ inputs.deploy_target == 'github' && github.ref_type == 'tag' && inputs.target_repository == github.repository }}
uses: xresloader/upload-to-github-release@v1
env:
GITHUB_TOKEN: ${{ inputs.github_token }}
with:
file: "./jdeploy/github-release-files/*"
tags: true
overwrite: true
- name: Update release body (for branch release)
if: ${{ inputs.deploy_target == 'github' && github.ref_type == 'branch' && inputs.target_repository == github.repository }}
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.github_token }}
GITHUB_REF_NAME: ${{ github.ref_name }}
GITHUB_REPOSITORY: ${{ github.repository }}
run: |
set -e
BODY=$(cat ./jdeploy/github-release-files/jdeploy-release-notes.md)
BODY_JSON="{\"body\": $(echo "$BODY" | jq -sR .)}"
RELEASE_RESULT=$(curl -s \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/tags/${GITHUB_REF_NAME})
RELEASE_ID=$( jq -r '.id' <<< "${RELEASE_RESULT}" )
echo "Release ID is ${RELEASE_ID}"
curl \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID} \
-d "$BODY_JSON"
- name: Update release body (for tag release)
if: ${{ inputs.deploy_target == 'github' && github.ref_type == 'tag' && inputs.target_repository == github.repository }}
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.github_token }}
GITHUB_REF_NAME: ${{ github.ref_name }}
GITHUB_REPOSITORY: ${{ github.repository }}
run: |
set -e
BODY=$(cat ./jdeploy/github-release-files/jdeploy-release-notes.md)
RELEASE_RESULT=$(curl -s \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/tags/${GITHUB_REF_NAME})
RELEASE_ID=$( jq -r '.id' <<< "${RELEASE_RESULT}" )
OLD_BODY=$(jq -r '.body' <<< "${RELEASE_RESULT}" )
NEW_BODY=$(GITHUB_RELEASE_BODY="$OLD_BODY" JDEPLOY_RELEASE_NOTES="$BODY" $jdeploy_exec github-build-release-body)
BODY_JSON="{\"body\": $(echo "$NEW_BODY" | jq -sR .)}"
echo "Release ID is ${RELEASE_ID}"
curl \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID} \
-d "$BODY_JSON"
- name: Publish to npm
if: ${{ inputs.deploy_target == 'npm' && github.ref_type == 'tag' }}
shell: bash
env:
NODE_AUTH_TOKEN: ${{ inputs.npm_token }}
run: |
npm pkg set version="$TAG_VERSION"
if [[ "${{ startsWith(inputs.jdeploy_version, 'git://') }}" == "true" ]]; then
npm pkg set jdeploy.jdeployVersion='latest'
else
npm pkg set jdeploy.jdeployVersion='${{ inputs.jdeploy_version }}'
fi
npm pkg set jdeploy.commitHash="$GITHUB_SHA"
$jdeploy_exec publish