Build Release #172
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
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 | |
- 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/github-action-json-property@v0.2.0 | |
with: | |
path: "Packages/${{matrix.packageID}}/package.json" | |
prop_path: "version" | |
- name: get name | |
id: name | |
uses: notiz-dev/github-action-json-property@v0.2.0 | |
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/tag-exists-action@v1.2.0 | |
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/read-file-action@v1.1.6 | |
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/github-action-matrix-outputs-write@0.3.1 | |
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 | |