This commit is contained in:
59
.github/workflows/release.yml
vendored
59
.github/workflows/release.yml
vendored
@@ -38,14 +38,53 @@ jobs:
|
||||
(cd package && zip -r "../${archive}" LICENSE setup.ps1 PolicyDefinitions)
|
||||
|
||||
- name: Create or update release
|
||||
uses: actions/github-script@v7
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
run: |
|
||||
if gh release view "${SHORT_SHA}" >/dev/null 2>&1; then
|
||||
gh release upload "${SHORT_SHA}" "${ARCHIVE}" --clobber
|
||||
else
|
||||
gh release create "${SHORT_SHA}" "${ARCHIVE}" \
|
||||
--target "${GITHUB_SHA}" \
|
||||
--title "${SHORT_SHA}" \
|
||||
--notes "Automated build for ${GITHUB_SHA}."
|
||||
fi
|
||||
SHORT_SHA: ${{ env.SHORT_SHA }}
|
||||
ARCHIVE: ${{ env.ARCHIVE }}
|
||||
with:
|
||||
script: |
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const owner = context.repo.owner;
|
||||
const repo = context.repo.repo;
|
||||
const tag = process.env.SHORT_SHA;
|
||||
const archive = process.env.ARCHIVE;
|
||||
|
||||
let release;
|
||||
try {
|
||||
const existing = await github.rest.repos.getReleaseByTag({ owner, repo, tag });
|
||||
release = existing.data;
|
||||
} catch (error) {
|
||||
if (error.status !== 404) throw error;
|
||||
const created = await github.rest.repos.createRelease({
|
||||
owner,
|
||||
repo,
|
||||
tag_name: tag,
|
||||
target_commitish: context.sha,
|
||||
name: tag,
|
||||
body: `Automated build for ${context.sha}.`,
|
||||
});
|
||||
release = created.data;
|
||||
}
|
||||
|
||||
const assetName = path.basename(archive);
|
||||
for (const asset of release.assets || []) {
|
||||
if (asset.name === assetName) {
|
||||
await github.rest.repos.deleteReleaseAsset({ owner, repo, asset_id: asset.id });
|
||||
}
|
||||
}
|
||||
|
||||
const data = fs.readFileSync(archive);
|
||||
await github.rest.repos.uploadReleaseAsset({
|
||||
owner,
|
||||
repo,
|
||||
release_id: release.id,
|
||||
name: assetName,
|
||||
data,
|
||||
headers: {
|
||||
'content-type': 'application/zip',
|
||||
'content-length': data.length,
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user