-
-
Notifications
You must be signed in to change notification settings - Fork 37
187 lines (167 loc) · 7.43 KB
/
release.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
name: Build Release
on:
workflow_dispatch:
inputs:
dryRun:
type: boolean
description: 'Will Dry Run the workflow, skipping the release step, but showing you what would be released.'
required: false
env:
releaseTemplate: "RELEASE TEMPLATE.md"
packagePrefix: "com"
overrideOwnerString: "mattshark"
permissions:
contents: write
jobs:
generateMatrix:
name: Generate Package Matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.generateMatrix.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Get Repo Owner
id: getRepoOwner
#run: echo prop=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]') >> $GITHUB_OUTPUT #grab the repo owner and make it lowercase
run: echo prop=$(echo '${{ env.overrideOwnerString }}' | tr '[:upper:]' '[:lower:]') >> $GITHUB_OUTPUT #grab the repo owner and make it lowercase
- name: Set Matrix
id: generateMatrix
#Multiline string for dumb reasons
run: |
TEMP=""
for package in $(find Packages -maxdepth 1 -mindepth 1 -type d -name "${{ env.packagePrefix }}.${{ steps.getRepoOwner.outputs.prop }}*"); do
packageID=${package##*/}
TEMP="$TEMP\"$packageID\", "
done
TEMP=${TEMP::-2}
TEMP="$TEMP"
echo "matrix=[$TEMP]" >> $GITHUB_OUTPUT
- name: Output Matrix
run: echo ${{ steps.generateMatrix.outputs.matrix }}
build:
name: Build ${{ matrix.packageID }}
needs: generateMatrix
runs-on: ubuntu-latest
strategy:
matrix:
packageID: ${{ fromJSON(needs.generateMatrix.outputs.matrix) }}
env:
ACTIONS_RUNNER_DEBUG: false #This prevents set-output warnings for now
#TODO: Remove this once all actions are updated to use the new output format
steps:
- name: Checkout
uses: actions/checkout@v3
- name: get version
id: version
uses: notiz-dev/[email protected]
with:
path: "Packages/${{matrix.packageID}}/package.json"
prop_path: "version"
- name: get name
id: name
uses: notiz-dev/[email protected]
with:
path: "Packages/${{matrix.packageID}}/package.json"
prop_path: "displayName"
- name: sanitize name
id: sanitizeName
run: echo prop=$(echo '${{ steps.name.outputs.prop }}' | tr ' ' '_') >> $GITHUB_OUTPUT
- name: generate tag
id: tag
run: echo prop="${{ steps.sanitizeName.outputs.prop }}-${{ steps.version.outputs.prop }}" >> $GITHUB_OUTPUT
- name: Check if Release Tag Exists
id: checkReleaseTag
uses: mukunku/[email protected]
with:
tag: ${{ steps.tag.outputs.prop }}
- name: Set Environment Variables
if: ${{ steps.checkReleaseTag.outputs.exists == 'false' }}
run: |
echo "zipFile=${{ matrix.packageID }}-${{ steps.tag.outputs.prop }}".zip >> $GITHUB_ENV
echo "unityPackage=${{ matrix.packageID }}-${{ steps.tag.outputs.prop }}.unitypackage" >> $GITHUB_ENV
- name: Create Zip
if: ${{ steps.checkReleaseTag.outputs.exists == 'false' }}
uses: thedoctor0/zip-release@09336613be18a8208dfa66bd57efafd9e2685657
with:
type: "zip"
directory: "Packages/${{matrix.packageID}}/"
filename: "../../${{env.zipFile}}" # make the zip file two directories up, since we start two directories in above
- run: find "Packages/${{matrix.packageID}}/" -name \*.meta >> metaList
if: ${{ steps.checkReleaseTag.outputs.exists == 'false' }}
- name: Create UnityPackage
if: ${{ steps.checkReleaseTag.outputs.exists == 'false' }}
uses: pCYSl5EDgo/create-unitypackage@cfcd3cf0391a5ef1306342794866a9897c32af0b
with:
package-path: ${{ env.unityPackage }}
include-files: metaList
- name: Read Release Template
if: ${{ steps.checkReleaseTag.outputs.exists == 'false' }}
id: ReleaseTemplateContents
uses: juliangruber/[email protected]
with:
path: "./${{ env.releaseTemplate }}"
- name: Make Release
if: ${{ steps.checkReleaseTag.outputs.exists == 'false' && github.event.inputs.dryRun == 'false' }}
uses: softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5
with:
tag_name: ${{ steps.tag.outputs.prop }}
files: |
${{ env.zipFile }}
${{ env.unityPackage }}
Packages/${{ matrix.packageID }}/package.json
body: |
${{ steps.ReleaseTemplateContents.outputs.content }}
prerelease: true
# Output for matrices workaround
- name: Build Status
uses: cloudposse/[email protected]
with:
matrix-step-name: ${{ github.job }}
matrix-key: ${{ matrix.packageID }}
outputs: |-
name: ${{ steps.name.outputs.prop }}
version: ${{ steps.version.outputs.prop }}
tag: ${{ steps.tag.outputs.prop }}
releaseCandidateCreated: ${{ steps.checkReleaseTag.outputs.exists == 'false' }}
summary:
name: Final #This name is weird because it is put into the summary, so calling it summary would just mean github would show summary twice
needs: [build, generateMatrix]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Read Build Matrix Outputs
uses: cloudposse/github-action-matrix-outputs-read@main
id: matrixOutputs
with:
matrix-step-name: build
#loop through the matrix outputs and add them to the summary
#object
# name
# package1
# package2
# version
# package1
# package2
- name: Create Build Results
run: |
echo "Build Results:" >> $GITHUB_STEP_SUMMARY
echo "Dry Run: ${{ github.event.inputs.dryRun }}" >> $GITHUB_STEP_SUMMARY
buildResults='${{ steps.matrixOutputs.outputs.result }}'
# Loop through the package IDs from the `generateMatrix` job output
for packageID in ${{ needs.generateMatrix.outputs.matrix }}; do
# Clean up the package ID by removing brackets, spaces, and quotes
cleanID=$(echo "${packageID}" | tr -d '[] ,"')
# Get the name, version, tag, and release candidate state for the current package ID
name=$(echo "${buildResults}" | jq --arg cleanID "${cleanID}" '.name[$cleanID]' | tr -d '"')
version=$(echo "${buildResults}" | jq --arg cleanID "${cleanID}" '.version[$cleanID]' | tr -d '"')
tag=$(echo "${buildResults}" | jq --arg cleanID "${cleanID}" '.tag[$cleanID]' | tr -d '"')
rcCreated=$(echo "${buildResults}" | jq --arg cleanID "${cleanID}" '.releaseCandidateCreated[$cleanID]' | tr -d '"')
# Append the package details to the summary file
echo "- ${name}" >> $GITHUB_STEP_SUMMARY
echo " - Package ID: \`${cleanID}\`" >> $GITHUB_STEP_SUMMARY
echo " - Version: \`${version}\`" >> $GITHUB_STEP_SUMMARY
echo " - Tag: \`${tag}\`" >> $GITHUB_STEP_SUMMARY
echo " - Release Candidate Created: \`${rcCreated}\`" >> $GITHUB_STEP_SUMMARY
done