Update build.yaml #26
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build | |
on: | |
pull_request: | |
push: | |
branches: [main] | |
env: | |
CARGO_TERM_COLOR: always | |
PROJECT_NAME: waspinput | |
NAME_WIN32: waspinput32.dll | |
NAME_WIN64: waspinput64.dll | |
jobs: | |
update_version: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get commit hash | |
id: commit-hash | |
run: echo "COMMIT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV | |
- name: Replace version hash | |
run: | | |
HASH=$(git rev-parse --short HEAD) | |
sed -i "s/^const VERSION: &str = \".*\";/const VERSION: &str = \"${HASH}\";/" src/shared/memory.rs | |
- name: Commit updated version | |
run: | | |
git config --global user.name "Wasp Bot" | |
git config --global user.email "[email protected]" | |
git add src/shared/memory.rs | |
git commit -m "Bump version" | |
git push | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
build: | |
needs: update_version | |
runs-on: windows-latest | |
strategy: | |
matrix: | |
target: [i686-pc-windows-msvc, x86_64-pc-windows-msvc] | |
steps: | |
- name: Checkout source | |
uses: actions/[email protected] | |
- name: Install Rust toolchain | |
uses: actions-rs/toolchain@v1 | |
with: | |
profile: minimal | |
toolchain: stable | |
target: ${{ matrix.target }} | |
override: true | |
- name: Build for ${{ matrix.target }} | |
run: cargo build --release --target=${{ matrix.target }} | |
- name: Rename output DLL | |
run: | | |
$target = "${{ matrix.target }}" | |
$original = "target\$target\release\$env:PROJECT_NAME.dll" | |
if ($target -eq "i686-pc-windows-msvc") { | |
$renamed = "target\$target\release\$env:NAME_WIN32" | |
} else { | |
$renamed = "target\$target\release\$env:NAME_WIN64" | |
} | |
if (Test-Path $original) { | |
Move-Item $original $renamed -Force | |
Write-Host "Renamed $original to $renamed" | |
} else { | |
Write-Host "DLL not found: $original" | |
exit 1 | |
} | |
shell: pwsh | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ matrix.target }}-dll | |
path: | | |
target/${{ matrix.target }}/release/${{ matrix.target == 'i686-pc-windows-msvc' && env.NAME_WIN32 || env.NAME_WIN64 }} | |
version: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Git | |
run: | | |
git config --global user.name "Wasp Bot" | |
git config --global user.email "[email protected]" | |
- name: Get current date and commit hash | |
run: | | |
echo "CURRENT_YEAR=$(date +'%Y')" >> $GITHUB_ENV | |
echo "CURRENT_MONTH=$(date +'%m')" >> $GITHUB_ENV | |
echo "CURRENT_DAY=$(date +'%d')" >> $GITHUB_ENV | |
echo "COMMIT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV | |
TAG_NAME="$(date +'%Y').$(date +'%m').$(date +'%d')-$(git rev-parse --short HEAD)" | |
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV | |
echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT | |
- name: Create tag | |
run: | | |
git tag ${{ env.TAG_NAME }} | |
git push origin ${{ env.TAG_NAME }} | |
- name: Download build artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
path: artifacts | |
- name: Create release | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
gh release create ${{ env.TAG_NAME }} \ | |
artifacts/i686-pc-windows-msvc-dll/${{ env.NAME_WIN32 }} \ | |
artifacts/x86_64-pc-windows-msvc-dll/${{ env.NAME_WIN64 }} \ | |
--title "${{ env.TAG_NAME }}" \ | |
--notes "Automated plugin release" |