Skip to content

Commit

Permalink
Update macos-build.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
CookSleep authored Jul 18, 2024
1 parent 5b1c1f0 commit 10d5432
Showing 1 changed file with 56 additions and 9 deletions.
65 changes: 56 additions & 9 deletions .github/workflows/macos-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Build macOS App

on:
release:
types: [created]
types: [published, edited]
workflow_dispatch:

jobs:
Expand Down Expand Up @@ -36,15 +36,62 @@ jobs:
echo "Contents of current directory:"
ls -l
- name: Debug
run: |
echo "GITHUB_REF: ${{ github.ref }}"
ls -l ./Project_Exporter-macOS.zip
- name: Get Release
id: get_release
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
let releaseId, uploadUrl;
if (context.payload.release) {
releaseId = context.payload.release.id;
uploadUrl = context.payload.release.upload_url;
} else {
const response = await github.rest.repos.getLatestRelease({
owner: context.repo.owner,
repo: context.repo.repo,
});
releaseId = response.data.id;
uploadUrl = response.data.upload_url;
}
core.setOutput('upload_url', uploadUrl);
core.setOutput('release_id', releaseId);
- name: Upload Release Asset
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: ./Project_Exporter-macOS.zip
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.get_release.outputs.upload_url }}
asset_path: ./Project_Exporter-macOS.zip
asset_name: Project_Exporter-macOS.zip
asset_content_type: application/zip

- name: Update Release Asset
if: github.event_name == 'release'
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs');
const releaseId = ${{ steps.get_release.outputs.release_id }};
const { data: assets } = await github.rest.repos.listReleaseAssets({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: releaseId,
});
const asset = assets.find(a => a.name === 'Project_Exporter-macOS.zip');
if (asset) {
await github.rest.repos.deleteReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
asset_id: asset.id,
});
}
await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: releaseId,
name: 'Project_Exporter-macOS.zip',
data: fs.readFileSync('Project_Exporter-macOS.zip'),
});

0 comments on commit 10d5432

Please sign in to comment.