-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (96 loc) · 3.55 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
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@v7
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@v4
- 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