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)
|
(cd package && zip -r "../${archive}" LICENSE setup.ps1 PolicyDefinitions)
|
||||||
|
|
||||||
- name: Create or update release
|
- name: Create or update release
|
||||||
|
uses: actions/github-script@v7
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ github.token }}
|
SHORT_SHA: ${{ env.SHORT_SHA }}
|
||||||
run: |
|
ARCHIVE: ${{ env.ARCHIVE }}
|
||||||
if gh release view "${SHORT_SHA}" >/dev/null 2>&1; then
|
with:
|
||||||
gh release upload "${SHORT_SHA}" "${ARCHIVE}" --clobber
|
script: |
|
||||||
else
|
const fs = require('fs');
|
||||||
gh release create "${SHORT_SHA}" "${ARCHIVE}" \
|
const path = require('path');
|
||||||
--target "${GITHUB_SHA}" \
|
|
||||||
--title "${SHORT_SHA}" \
|
const owner = context.repo.owner;
|
||||||
--notes "Automated build for ${GITHUB_SHA}."
|
const repo = context.repo.repo;
|
||||||
fi
|
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