Skip to content

Commit 829e901

Browse files
committed
release.yml: create draft release with artifacts
Add a job, dependent on the success of all packaging steps, to download the generated artifacts and attach them to a newly-created draft release. The created draft release description is populated with auto-generated release notes [1]. Note the intermediate step "Consolidate artifact directory"; because downloading all artifacts with the 'download-artifacts' action creates a wrapper directory around each artifact [2], we remove those wrappers by moving all files into a single consolidated 'artifacts' directory before running the release creation & attachment script. [1] https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes [2] https://github.com/actions/download-artifact#download-all-artifacts Signed-off-by: Victoria Dye <[email protected]>
1 parent 73cee47 commit 829e901

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

.github/workflows/release.yml

+69
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ jobs:
1111
name: Prerequisites
1212
runs-on: ubuntu-latest
1313
outputs:
14+
tag_name: ${{ steps.tag.outputs.name }} # The full name of the tag, e.g. v1.0.0
1415
tag_version: ${{ steps.tag.outputs.version }} # The version number (without preceding "v"), e.g. 1.0.0
1516
steps:
1617
- name: Determine tag to build
1718
run: |
19+
echo "name=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
1820
echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
1921
id: tag
2022

@@ -67,3 +69,70 @@ jobs:
6769
name: ${{env.artifactName}}
6870
path: ${{github.workspace}}/${{env.artifactPath}}
6971
if-no-files-found: error
72+
73+
create-github-release:
74+
needs: [prereqs, package]
75+
name: Create release with artifacts
76+
runs-on: ubuntu-latest
77+
steps:
78+
- name: Download packages
79+
uses: actions/download-artifact@v3
80+
with:
81+
path: artifacts-raw
82+
- name: Consolidate artifact directory
83+
shell: bash
84+
run: |
85+
# This step is needed to extract the artifacts from their wrapper
86+
# parent directories. For more details, see
87+
# https://github.com/actions/download-artifact#download-all-artifacts
88+
mkdir artifacts
89+
mv artifacts-raw/*/* artifacts/
90+
- name: Create release & attach artifacts
91+
uses: actions/github-script@v6
92+
with:
93+
script: |
94+
const fs = require('fs');
95+
const path = require('path');
96+
97+
var releaseMetadata = {
98+
owner: context.repo.owner,
99+
repo: context.repo.repo
100+
};
101+
102+
// Create the release
103+
var tagName = "${{ needs.prereqs.outputs.tag_name }}";
104+
var createdRelease = await github.rest.repos.createRelease({
105+
...releaseMetadata,
106+
draft: true,
107+
tag_name: tagName,
108+
name: tagName,
109+
generate_release_notes: true
110+
});
111+
releaseMetadata.release_id = createdRelease.data.id;
112+
113+
// Upload contents of directory to the release created above
114+
async function uploadDirectoryToRelease(directory, includeExtensions=[]) {
115+
return fs.promises.readdir(directory)
116+
.then(async(files) => Promise.all(
117+
files.filter(file => {
118+
return includeExtensions.length==0 || includeExtensions.includes(path.extname(file).toLowerCase());
119+
})
120+
.map(async (file) => {
121+
var filePath = path.join(directory, file);
122+
return github.rest.repos.uploadReleaseAsset({
123+
...releaseMetadata,
124+
name: file,
125+
headers: {
126+
"content-length": (await fs.promises.stat(filePath)).size
127+
},
128+
data: fs.createReadStream(filePath)
129+
});
130+
}))
131+
);
132+
}
133+
134+
await Promise.all([
135+
// Upload all artifacts
136+
uploadDirectoryToRelease('artifacts', ['.pkg', '.deb'])
137+
]);
138+

0 commit comments

Comments
 (0)