forked from shannah/jdeploy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
206 lines (191 loc) · 8.27 KB
/
Copy pathaction.yml
File metadata and controls
206 lines (191 loc) · 8.27 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
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
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.0.43'
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: 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 }}"
npm pkg set jdeploy.jdeployVersion='${{ inputs.jdeploy_version }}'
npm pkg set jdeploy.commitHash="$GITHUB_SHA"
GITHUB_REPOSITORY=${{ inputs.target_repository }} npx 'jdeploy@${{ inputs.jdeploy_version }}' 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"
npm pkg set jdeploy.jdeployVersion='${{ inputs.jdeploy_version }}'
npm pkg set jdeploy.commitHash="$GITHUB_SHA"
npm pkg set jdeploy.gitTag="${{ github.ref_name }}"
GITHUB_REPOSITORY=${{ inputs.target_repository }} npx 'jdeploy@${{ inputs.jdeploy_version }}' 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" npx 'jdeploy@${{ inputs.jdeploy_version }}' 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"
npm pkg set jdeploy.jdeployVersion='${{ inputs.jdeploy_version }}'
npm pkg set jdeploy.commitHash="$GITHUB_SHA"
npx jdeploy@${{ inputs.jdeploy_version }} publish