Skip to content

publish-executable

publish-executable #1

name: publish-executable
on:
workflow_dispatch: null
push:
paths:
- 'cal.py'
branches:
- master
jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- 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 pyinstaller
shell: pwsh
- name: Build executable
run: pyinstaller --onefile cal.py
shell: pwsh
- name: Get latest release tag
id: latest_release
run: |
$response = Invoke-RestMethod -Uri "https://api.github.com/repos/$env:GITHUB_REPOSITORY/releases/latest" -Headers @{Authorization = "Bearer $env:GITHUB_TOKEN"}
$old_tag = $response.tag_name
echo "::set-output name=tag_old::$old_tag"
$tag = ($response.tag_name -replace 'v', '').split(".")
$new_tag = ([int]$tag[0] + 1).ToString()+'.0.0'
echo "::set-output name=tag::v$new_tag"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Write new release body
id: new_release_body
run: |
$date_str = Get-Date
$body_str = 'New release as of ' + $date_str.ToString()
echo "::set-output name=content::$body_str"
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.latest_release.outputs.tag }}
release_name: ${{ steps.latest_release.outputs.tag }}
body: ${{ steps.new_release_body.outputs.content }}
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./dist/cal.exe
asset_name: cal.exe
asset_content_type: application/octet-stream
- name: Update README.md
run: |
sed -i "s/${{ steps.latest_release.outputs.tag_old }}/${{ steps.latest_release.outputs.tag }}/g" README.md
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git commit -am "Updated README with installation of v${{ steps.latest_release.outputs.tag }}"
git push