Skip to content

Build macOS App

Build macOS App #16

Workflow file for this run

name: Build macOS App
on:
release:
types: [published, edited]
workflow_dispatch:
jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pyinstaller
- name: Build macOS app
run: |
pyinstaller project_exporter.spec
echo "Contents of dist directory:"
ls -R dist
- name: Create ZIP archive
run: |
cd dist
zip -r "../Project_Exporter-macOS.zip" "项目文件导出工具.app"
cd ..
echo "Contents of current directory:"
ls -l
- 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;
}
console.log(`UPLOAD_URL=${uploadUrl}`);
console.log(`RELEASE_ID=${releaseId}`);
- name: Upload Release Asset
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ env.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 = process.env.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'),
});