Release Changes #7
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: Release Changes | |
on: | |
workflow_run: | |
workflows: ["Validate Changes"] | |
branches: [main] | |
types: | |
- completed | |
jobs: | |
begin-release: | |
name: Begin Release | |
runs-on: ubuntu-latest | |
if: github.event.workflow_run.conclusion == 'success' | |
steps: | |
- run: echo "Beginning release." | |
- name: 'Download artifacts from triggering workflow' | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
run_id: context.payload.workflow_run.id, | |
}); | |
let matchArtifacts = allArtifacts.data.artifacts.filter((artifact) => { | |
return artifact.name == 'version-json' || artifact.name == 'release-notes'; | |
}); | |
let downloadsPromises = matchArtifacts.map(async (artifact) => { | |
var blob = await github.rest.actions.downloadArtifact({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
artifact_id: artifact.id, | |
archive_format: 'zip' | |
}); | |
return { name: artifact.name, data: blob.data } | |
}); | |
let downloads = await Promise.all(downloadsPromises); | |
let fs = require('fs'); | |
downloads.forEach((download) => { | |
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/${download.name}.zip`, Buffer.from(download.data)); | |
}); | |
- name: Unzip version-json | |
shell: pwsh | |
run: Expand-Archive -Path "version-json.zip" -DestinationPath ./version-json/ | |
- name: Upload version-json | |
uses: actions/upload-artifact@v3 | |
with: | |
name: version-json | |
path: ./version-json/version.json | |
if-no-files-found: error | |
- name: Unzip release-notes | |
shell: pwsh | |
run: Expand-Archive -Path "release-notes.zip" -DestinationPath ./release-notes/ | |
- name: Upload release-notes | |
uses: actions/upload-artifact@v3 | |
with: | |
name: release-notes | |
path: ./release-notes/release-notes.md | |
if-no-files-found: error | |
publish-github-release: | |
name: Publish GitHub Release | |
runs-on: ubuntu-latest | |
needs: [begin-release] | |
steps: | |
- name: Check out repository code | |
uses: actions/checkout@v3 | |
- name: "Get artifact: version-json" | |
uses: actions/download-artifact@v3 | |
with: | |
name: version-json | |
path: ./out/ | |
- name: Populate GitVersion variables | |
id: gitversion_vars | |
shell: pwsh | |
run: | | |
[object] $version = Get-Content -Path ./out/version.json -Encoding UTF8 | ConvertFrom-Json | |
foreach ($key in $version.PSObject.Properties.Name) { | |
echo "::set-output name=$key::$($version.$key)" | |
} | |
- name: "Get artifact: release-notes" | |
uses: actions/download-artifact@v3 | |
with: | |
name: release-notes | |
path: ./out/ | |
- name: Publish GitHub release | |
id: publish_github_release | |
uses: softprops/action-gh-release@v1 | |
with: | |
token: "${{ secrets.RELEASE_GITHUB_TOKEN }}" | |
name: "v${{ steps.gitversion_vars.outputs.SemVer }}" | |
tag_name: "v${{ steps.gitversion_vars.outputs.SemVer }}" | |
target_commitish: "${{ steps.gitversion_vars.outputs.Sha }}" | |
generate_release_notes: false | |
body_path: ./out/release-notes.md | |
prerelease: "${{ steps.gitversion_vars.outputs.PreReleaseTag != '' }}" | |
draft: false | |
fail_on_unmatched_files: false |