Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ci): Add manual release workflow #27

Merged
merged 3 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/actions/install-ahk/action.yml
Original file line number Diff line number Diff line change
@@ -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 }}
35 changes: 0 additions & 35 deletions .github/workflows/bundle-exe.yml

This file was deleted.

34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
76 changes: 76 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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
25 changes: 10 additions & 15 deletions scripts/embed.ps1
Original file line number Diff line number Diff line change
@@ -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")

Expand Down