From 33cc656bfb044ac6a6577e21ea780dcd55117981 Mon Sep 17 00:00:00 2001 From: imawizard <1701648+imawizard@users.noreply.github.com> Date: Sat, 22 Jun 2024 21:49:07 +0200 Subject: [PATCH] feat(ci): Add manual release workflow (#27) * style(ci): Fix some indentation * chore(ci): Update AutoHotkey version * feat(ci): Add manual release workflow --- .github/actions/install-ahk/action.yml | 32 +++++++++++ .github/workflows/bundle-exe.yml | 35 ------------ .github/workflows/ci.yml | 34 ++++++++++++ .github/workflows/release.yml | 76 ++++++++++++++++++++++++++ scripts/embed.ps1 | 25 ++++----- 5 files changed, 152 insertions(+), 50 deletions(-) create mode 100644 .github/actions/install-ahk/action.yml delete mode 100644 .github/workflows/bundle-exe.yml create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/actions/install-ahk/action.yml b/.github/actions/install-ahk/action.yml new file mode 100644 index 0000000..4fdd58d --- /dev/null +++ b/.github/actions/install-ahk/action.yml @@ -0,0 +1,32 @@ +# See https://docs.github.com/en/actions/creating-actions/creating-a-composite-action + +name: Install AHK + +inputs: + ahk-v2-url: + default: https://github.com/AutoHotkey/AutoHotkey/releases/download/v2.0.11/AutoHotkey_2.0.11.zip + ahk2exe-url: + default: https://github.com/AutoHotkey/Ahk2Exe/releases/download/Ahk2Exe1.1.37.02a0/Ahk2Exe1.1.37.02a0.zip + +outputs: + ahk-path: + value: ${{ steps.extract.outputs.ahk-path }} + ahk2exe-path: + value: ${{ steps.extract.outputs.ahk2exe-path }} + +runs: + using: composite + steps: + - name: Download and extract AutoHotkey + id: extract + shell: pwsh + run: | + irm -OutFile autohotkey.zip $env:AHK_V2_URL + unzip autohotkey.zip -d autohotkey + irm -OutFile ahk2exe.zip $env:AHK2EXE_URL + unzip ahk2exe.zip -d autohotkey\Compiler + echo "ahk-path=$(pwd)\\autohotkey\AutoHotkey64.exe" >>$env:GITHUB_OUTPUT + echo "ahk2exe-path=$(pwd)\\autohotkey\\Compiler\\Ahk2Exe.exe" >>$env:GITHUB_OUTPUT + env: + AHK_V2_URL: ${{ inputs.ahk-v2-url }} + AHK2EXE_URL: ${{ inputs.ahk2exe-url }} diff --git a/.github/workflows/bundle-exe.yml b/.github/workflows/bundle-exe.yml deleted file mode 100644 index a1e21ee..0000000 --- a/.github/workflows/bundle-exe.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: mwm - -on: - push: - branches: - - ahk-v2 - -env: - AHK_V2_URL: https://github.com/AutoHotkey/AutoHotkey/releases/download/v2.0.2/AutoHotkey_2.0.2.zip - AHK2EXE_URL: https://github.com/AutoHotkey/Ahk2Exe/releases/download/Ahk2Exe1.1.36.02e3/Ahk2Exe1.1.36.02e.zip - -jobs: - build: - runs-on: windows-2019 - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Download and extract AutoHotkey - run: | - irm -OutFile autohotkey.zip $env:AHK_V2_URL - unzip autohotkey.zip -d autohotkey - irm -OutFile ahk2exe.zip $env:AHK2EXE_URL - unzip ahk2exe.zip -d autohotkey\Compiler - - - name: Embed script with Ahk2Exe - run: .\scripts\embed.ps1 - - - name: Upload artifact - uses: actions/upload-artifact@v3 - with: - name: mwm - path: | - build/mwm.exe - build/mwm.ahk diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..207f148 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,34 @@ +name: CI + +on: + push: + branches: + - ahk-v2 + pull_request: + branches: + - ahk-v2 + +jobs: + build: + runs-on: windows-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install AutoHotkey + id: install-ahk + uses: ./.github/actions/install-ahk + + - name: Embed script with Ahk2Exe + run: ./scripts/embed.ps1 + env: + AHK_STUB: ${{ steps.install-ahk.outputs.ahk-path }} + AHK2EXE: ${{ steps.install-ahk.outputs.ahk2exe-path }} + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: mwm + path: | + build/mwm.exe + build/mwm.ahk diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..8c6ff09 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,76 @@ +name: Release + +on: + workflow_dispatch: + inputs: + version: + description: Version + required: true + +jobs: + build: + runs-on: windows-latest + steps: + - name: Validate input + shell: bash + run: | + [[ $VERSION =~ v[0-9]+\.[0-9]+\.[0-9]+ ]] + env: + VERSION: ${{ inputs.version }} + + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install AutoHotkey + id: install-ahk + uses: ./.github/actions/install-ahk + + - name: Embed script with Ahk2Exe + run: ./scripts/embed.ps1 + env: + AHK_STUB: ${{ steps.install-ahk.outputs.ahk-path }} + AHK2EXE: ${{ steps.install-ahk.outputs.ahk2exe-path }} + VERSION: ${{ inputs.version }} + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: mwm + path: | + build/mwm.exe + build/mwm.ahk + + - name: Tag commit + shell: bash + run: | + git tag $VERSION + git push origin $VERSION + env: + VERSION: ${{ inputs.version }} + + publish: + runs-on: windows-latest + needs: build + steps: + - name: Download artifact + uses: actions/download-artifact@v4 + with: + name: mwm + + - name: Zip artifact + shell: pwsh + run: | + Compress-Archive ` + -Path mwm.exe, mwm.ahk ` + -DestinationPath mwm-$env:VERSION.zip + env: + VERSION: ${{ inputs.version }} + + - name: Create release + uses: softprops/action-gh-release@v2 + with: + draft: true + generate_release_notes: true + tag_name: ${{ inputs.version }} + files: | + mwm-*.zip diff --git a/scripts/embed.ps1 b/scripts/embed.ps1 index 1231b60..3fdc661 100644 --- a/scripts/embed.ps1 +++ b/scripts/embed.ps1 @@ -1,31 +1,26 @@ +$ico = ".\assets\togepī.ico" +$ahk = ".\mwm.ahk" +$out = ".\build" + $ahk2exe = ![string]::IsNullOrEmpty($env:AHK2EXE) ` - ? $env:AHK2EXE ` + ? $env:AHK2EXE ` : ".\autohotkey\Compiler\Ahk2Exe.exe" $base = ![string]::IsNullOrEmpty($env:AHK_STUB) ` - ? $env:AHK_STUB ` + ? $env:AHK_STUB ` : ".\autohotkey\AutoHotkey64.exe" -$ico = ".\assets\togepī.ico" -$ahk = ".\mwm.ahk" -$out = ".\build" +$version = ![string]::IsNullOrEmpty($env:VERSION) ` + ? $env:VERSION ` + : "$(git log -n1 --format='%h') (commit hash)" New-Item -Type Directory $out -Force | Out-Null -$date = $(git log -n1 --format='%cI') -$version = $(if ($date -match '\d\d\d(\d)-(\d\d)-(\d\d)') { - $Matches[1] ` - + "." ` - + ($Matches[2] -replace "^0", "") ` - + "." ` - + ($Matches[3] -replace "^0", "") ` -} else { "x.y.z "}) - (((Get-Content $ahk) -replace '^\s*#include (?:\*i )?(.+)$', { "#include $(Resolve-Path $_.Groups[1])" }) -match '^\s*#include .+$'), "MIGURU_VERSION := `"$version`"" | Join-String -Separator `n - | Out-File (Join-Path $out "autoload.ahk") + | Tee-Object -FilePath (Join-Path $out "autoload.ahk") Copy-Item $ahk (Join-Path $out "$(Split-Path $ahk -LeafBase).ahk")