-
Notifications
You must be signed in to change notification settings - Fork 6
145 lines (130 loc) · 4.94 KB
/
flow-deploy-release-artifact.yaml
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
name: "Deploy Release Artifact"
on:
workflow_dispatch:
inputs:
java-version:
description: "Java JDK Version:"
type: string
required: false
default: "17.0.5"
java-distribution:
description: "Java JDK Distribution:"
type: string
required: false
default: "temurin"
gradle-version:
description: "Gradle Version:"
type: string
required: false
default: "wrapper"
push:
branches:
- main
tags:
- "v[0-9]+.[0-9]+.[0-9]+-?*"
defaults:
run:
shell: bash
permissions:
contents: read
env:
LC_ALL: C.UTF-8
jobs:
prepare-tag-release:
name: Release / Tag / Prepare
runs-on: [ self-hosted, Linux, pbj, standard, ephemeral ]
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}
outputs:
version: ${{ steps.tag.outputs.version }}
prerelease: ${{ steps.tag.outputs.prerelease }}
steps:
- name: Install Semantic Version Tools
run: |
echo "::group::Download SemVer Binary"
sudo curl -L -o /usr/local/bin/semver https://raw.githubusercontent.com/fsaintjacques/semver-tool/master/src/semver
echo "::endgroup::"
echo "::group::Change SemVer Binary Permissions"
sudo chmod -v +x /usr/local/bin/semver
echo "::endgroup::"
echo "::group::Show SemVer Binary Version Info"
semver --version
echo "::endgroup::"
- name: Extract Tag Version
id: tag
run: |
RELEASE_VERSION="$(semver get release "${{ github.ref_name }}")"
PRERELEASE_VERSION="$(semver get prerel "${{ github.ref_name }}")"
FINAL_VERSION="${RELEASE_VERSION}"
PRERELEASE_FLAG="false"
[[ -n "${PRERELEASE_VERSION}" ]] && FINAL_VERSION="${RELEASE_VERSION}-${PRERELEASE_VERSION}"
[[ -n "${PRERELEASE_VERSION}" ]] && PRERELEASE_FLAG="true"
echo "version=${FINAL_VERSION}" >>"${GITHUB_OUTPUT}"
echo "prerelease=${PRERELEASE_FLAG}" >>"${GITHUB_OUTPUT}"
prepare-mc-release:
name: Release / MC / Prepare
runs-on: [ self-hosted, Linux, pbj, standard, ephemeral ]
needs:
- prepare-tag-release
outputs:
payload: ${{ steps.dispatch.outputs.payload }}
if: ${{ always() }}
steps:
- name: Install JSON Tools
run: |
if ! command -v jq >/dev/null 2>&1; then
echo "::group::Setup JQ Command"
sudo apt update
sudo apt install -y jq
echo "::endgroup::"
fi
JQ_VERSION="$(jq --version)"
if [[ "${JQ_VERSION}" != "jq-1.6" ]]; then
echo "::group::Updating JQ Version"
sudo apt update
sudo apt upgrade -y jq
echo "::endgroup::"
fi
if ! command -v tee >/dev/null 2>&1; then
echo "::group::Setup Tee Command"
sudo apt update
sudo apt install -y coreutils
echo "::endgroup::"
fi
echo "::group::Show JQ Version"
jq --version
echo "::endgroup::"
- name: Prepare Dispatch Payload
id: dispatch
env:
REQ_IS_TAG_PUSH: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}
run: |
VERSION_POLICY="snapshot"
VERSION_NUM=""
if [[ -n "${REQ_IS_TAG_PUSH}" && "${REQ_IS_TAG_PUSH}" == true ]]; then
VERSION_POLICY="specified"
VERSION_NUM="${{ needs.prepare-tag-release.outputs.version }}"
fi
REQ_JSON="$(jq --compact-output --null-input \
--arg ref "${{ github.ref }}" \
--arg jdist "${{ github.event.inputs.java-distribution || 'temurin' }}" \
--arg jver "${{ github.event.inputs.java-version || '17.0.5' }}" \
--arg gver "${{ github.event.inputs.gradle-version || 'wrapper' }}" \
--arg vpol "${VERSION_POLICY}" \
--arg vnum "${VERSION_NUM}" \
'{"ref": $ref, "java": {"distribution": $jdist, "version": $jver}, "gradle": {"version": $gver}, "release": {"version": {"policy": $vpol, "number": $vnum}}}')"
echo "payload=${REQ_JSON}" >>"${GITHUB_OUTPUT}"
printf "## Dispatch Payload\n\`\`\`json\n%s\n\`\`\`\n" "$(jq '.' <<<"${REQ_JSON}")" >>"${GITHUB_STEP_SUMMARY}"
dispatch-mc-release:
name: Release / MC / Dispatch
runs-on: [ self-hosted, Linux, pbj, standard, ephemeral ]
needs:
- prepare-mc-release
if: ${{ needs.prepare-mc-release.result == 'success' && always() }}
steps:
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.GH_REPO_DISPATCH_TOKEN }}
repository: hashgraph/hedera-internal-workflows
event-type: pbj-mc-release
client-payload: ${{ needs.prepare-mc-release.outputs.payload }}