Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
schillij95 committed Aug 30, 2024
2 parents 7d3fbe0 + eecd6db commit 87df9d5
Showing 1 changed file with 45 additions and 32 deletions.
77 changes: 45 additions & 32 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ permissions:
on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master
workflow_dispatch:

jobs:
Expand Down Expand Up @@ -46,51 +46,64 @@ jobs:
with:
name: ${{ runner.os }}-Executable
path: dist/*
- name: Create or Update Release
- name: Delete Old Release and Create New Release
id: create_release
uses: actions/github-script@v5
with:
script: |
const release = await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: 'latest-release'
}).catch(() => null);
let uploadUrl;
if (release) {
console.log(`Updating release: ${release.data.id}`);
const updatedRelease = await github.rest.repos.updateRelease({
const tag = 'latest-release';
// Get the latest commit SHA on the current branch (master)
const latestCommit = process.env.GITHUB_SHA;

// Attempt to get the release by tag
let release;
try {
release = await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release.data.id,
tag_name: 'latest-release',
name: 'Latest Release',
draft: false,
prerelease: false
tag: tag
});
uploadUrl = updatedRelease.data.upload_url;
} else {
console.log('Creating new release');
const newRelease = await github.rest.repos.createRelease({
} catch (error) {
if (error.status === 404) {
console.log('No existing release found with the tag, creating a new one.');
} else {
throw error;
}
}

// If release exists, delete it
if (release) {
console.log(`Deleting existing release: ${release.data.id}`);
await github.rest.repos.deleteRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: 'latest-release',
name: 'Latest Release',
draft: false,
prerelease: false
release_id: release.data.id
});
uploadUrl = newRelease.data.upload_url;
console.log(`Deleted release: ${release.data.id}`);
}
core.setOutput('upload_url', uploadUrl);
// Delete existing assets if they exist

// Create a new release with the latest commit SHA
console.log('Creating new release');
const newRelease = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: tag,
name: 'Latest Release',
draft: false,
prerelease: false,
target_commitish: latestCommit // Ensure release points to the latest commit
});

core.setOutput('upload_url', newRelease.data.upload_url);

// Optionally, clean up existing assets associated with the deleted release
const assets = await github.rest.repos.listReleaseAssets({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release ? release.data.id : newRelease.data.id,
release_id: newRelease.data.id,
});
for (const asset of assets.data) {
if (asset.name === '${{ runner.os }}.zip') {
await github.rest.repos.deleteReleaseAsset({
Expand Down

0 comments on commit 87df9d5

Please sign in to comment.