Skip to content

Update ymu.py

Update ymu.py #3

# This workflow will install Python dependencies, run tests, build an executable then upload it to github releases
name: YMU Automatic Release
on:
push:
paths:
- "ymu.py"
jobs:
build:
runs-on: windows-latest
name: Build YMU
outputs:
full_sha: ${{ steps.var.outputs.full_sha }}
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pyinstaller
pip install -r requirements.txt
- name: Verify With Flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Build Executable
run: |
pyinstaller "ymu.py" --noconfirm --onefile --windowed --noconsole --icon "./assets/icon/ymu.ico" --splash "./assets/splash.png" --add-data "./assets/;assets/"
- name: Generate Build Info
id: var
run: |
echo "full_sha=$(git rev-parse HEAD)" >> $env:GITHUB_OUTPUT
echo "short_sha=$(git rev-parse --short HEAD)" >> $env:GITHUB_OUTPUT
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: binary
path: |
dist\ymu.exe
create_release:
runs-on: ubuntu-latest
name: Delete Old Release
needs: build
steps:
- uses: actions/checkout@v4
- name: Delete Old Release
id: delete_ex_release
uses: actions/github-script@v7
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
// List all releases
const releases = await github.rest.repos.listReleases({
owner: owner,
repo: repo,
});
// Iterate over each release and delete it
for (const release of releases.data) {
await github.rest.repos.deleteRelease({
owner: owner,
repo: repo,
release_id: release.id,
});
console.log(`Deleted release with ID ${release.id}`);
}
// List all tags
const tags = await github.rest.repos.listTags({
owner: owner,
repo: repo,
});
- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: binary
- name: Increment Version
id: increment_version
uses: actions/github-script@v7
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
// Get the latest tag
const tags = await github.rest.repos.listTags({
owner: owner,
repo: repo,
});
let newVersion;
let oldTag;
if (tags.data.length === 0) {
// No tags found, start with a default version
console.log('No existing tags found. Starting with version v1.0.1');
newVersion = 'v1.0.1';
} else {
// Extract the latest tag name
const latestTag = tags.data[0].name;
const versionParts = latestTag.substring(1).split('.').map(Number);
versionParts[2] += 1; // Increment the patch version
newVersion = `v${versionParts.join('.')}`;
oldTag = latestTag;
}
core.setOutput("new_version", newVersion);
core.setOutput("old_tag", oldTag);
- name: Echo build_sha256
id: build_sha
run: |
sha256sum ymu.exe > sha256.checksum
echo "build_sha=$(cat sha256.checksum)" >> $GITHUB_OUTPUT
cat sha256.checksum
- name: Upload Release
uses: softprops/action-gh-release@v2
with:
name: YMU ${{ steps.increment_version.outputs.new_version }}
tag_name: ${{ steps.increment_version.outputs.new_version }}
body: |
**This automatic release was built by Github Actions**
[Link to build](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
files: |
ymu.exe