Improve .msi asset handling in upload-msi action
- Allow .msi file to be specified via input to action - Delete obsolete .exe file after uploading .msi
This commit is contained in:
parent
abca8d8685
commit
a34d07aecb
4 changed files with 8367 additions and 8307 deletions
6
.github/actions/upload-msi/action.yml
vendored
6
.github/actions/upload-msi/action.yml
vendored
|
|
@ -1,5 +1,9 @@
|
|||
name: 'Upload MSI'
|
||||
description: 'Upload gh.msi to both homebrew-gh and gh-cli releases'
|
||||
description: 'Upload an additional asset to a release'
|
||||
inputs:
|
||||
msi-file:
|
||||
description: 'path to the MSI file to attach to a release'
|
||||
required: true
|
||||
runs:
|
||||
using: 'node12'
|
||||
main: 'dist/index.js'
|
||||
|
|
|
|||
16617
.github/actions/upload-msi/dist/index.js
vendored
16617
.github/actions/upload-msi/dist/index.js
vendored
File diff suppressed because one or more lines are too long
49
.github/actions/upload-msi/index.js
vendored
49
.github/actions/upload-msi/index.js
vendored
|
|
@ -3,9 +3,10 @@ const path = require('path');
|
|||
|
||||
const github = require('@actions/github');
|
||||
const core = require('@actions/core');
|
||||
const Octokit = require('@octokit/rest');
|
||||
|
||||
const GITHUB_TOKEN = process.env['GITHUB_TOKEN'];
|
||||
const MSI_PATH = 'gh.msi';
|
||||
const MSI_PATH = core.getInput('msi-file');
|
||||
|
||||
process.on('unhandledRejection', function(reason, _) {
|
||||
handleError(reason);
|
||||
|
|
@ -21,23 +22,33 @@ async function main() {
|
|||
|
||||
const owner = github.context.repo.owner;
|
||||
const repo = github.context.repo.repo;
|
||||
|
||||
const octokit = new github.GitHub(GITHUB_TOKEN);
|
||||
const release = await getRelease(octokit, owner, repo, tag);
|
||||
|
||||
|
||||
const release = await getRelease(GITHUB_TOKEN, owner, repo, tag);
|
||||
|
||||
const assetFile = fs.readFileSync(MSI_PATH);
|
||||
|
||||
await uploadAsset(GITHUB_TOKEN, release, assetFile);
|
||||
const assetFile = fs.createReadStream(MSI_PATH);
|
||||
|
||||
try {
|
||||
await uploadAsset(octokit, release, assetFile);
|
||||
await deleteAsset(octokit, release, owner, repo, path.basename(MSI_PATH, '.msi') + '.exe');
|
||||
} finally {
|
||||
assetFile.close()
|
||||
}
|
||||
}
|
||||
|
||||
async function getRelease(token, owner, repo, tag) {
|
||||
const octokit = new github.GitHub(token);
|
||||
/**
|
||||
* @param {github.GitHub} octokit
|
||||
*/
|
||||
async function getRelease(octokit, owner, repo, tag) {
|
||||
const response = await octokit.repos.getReleaseByTag({ owner, repo, tag });
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async function uploadAsset(token, release, assetFile) {
|
||||
const octokit = new github.GitHub(token);
|
||||
/**
|
||||
* @param {github.GitHub} octokit
|
||||
* @param {Octokit.ReposGetReleaseByTagResponse} release
|
||||
*/
|
||||
async function uploadAsset(octokit, release, assetFile) {
|
||||
await octokit.repos.uploadReleaseAsset({
|
||||
url: release.upload_url,
|
||||
file: assetFile,
|
||||
|
|
@ -49,6 +60,22 @@ async function uploadAsset(token, release, assetFile) {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {github.GitHub} octokit
|
||||
* @param {Octokit.ReposGetReleaseByTagResponse} release
|
||||
*/
|
||||
async function deleteAsset(octokit, release, owner, repo, assetName) {
|
||||
for (const asset of release.assets) {
|
||||
if (asset.name == assetName) {
|
||||
await octokit.repos.deleteReleaseAsset({
|
||||
owner,
|
||||
repo,
|
||||
asset_id: asset.id
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function handleError(err) {
|
||||
console.error(err);
|
||||
core.setFailed(err.message);
|
||||
|
|
|
|||
2
.github/workflows/releases.yml
vendored
2
.github/workflows/releases.yml
vendored
|
|
@ -61,6 +61,8 @@ jobs:
|
|||
-Executable "${{ steps.buildmsi.outputs.msi }}"
|
||||
- name: Upload MSI
|
||||
uses: ./.github/actions/upload-msi
|
||||
with:
|
||||
msi-file: ${{ steps.buildmsi.outputs.msi }}
|
||||
env:
|
||||
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
||||
releases:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue