fix build LuaJIT for Windows on GitHub Actions #331
This file contains 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: Go | |
on: [push] | |
jobs: | |
Build: | |
strategy: | |
matrix: | |
lua-version: [lua51, lua52, lua53, lua54, luajit] | |
os: [macos, ubuntu, windows] | |
runs-on: ${{ matrix.os }}-latest | |
steps: | |
- name: Set up Go | |
uses: actions/setup-go@v3 | |
with: | |
go-version: 1.21 | |
id: go | |
- uses: msys2/setup-msys2@v2 | |
if: matrix.os == 'windows' | |
with: | |
update: true | |
msystem: MINGW64 | |
install: mingw-w64-x86_64-gcc mingw-w64-x86_64-make make curl unzip | |
- name: Check out code into the Go module directory | |
uses: actions/checkout@v2 | |
- name: Build Lua on Unix | |
if: matrix.os != 'windows' | |
run: | | |
cd golua/lua | |
./buildlua.sh | |
cd - | |
- name: Build on Unix | |
if: matrix.os != 'macos' && matrix.os != 'windows' | |
run: | | |
go build -ldflags="-s -w -X main.sha1ver=$(git rev-parse --short HEAD) -X 'main.buildTime=$(date)'" -tags ${{ matrix.lua-version }} -o getnovel . | |
mkdir ${{ matrix.os }}-amd64 | |
cp getnovel ${{ matrix.os }}-amd64/ | |
cp -r pdfpresets ${{ matrix.os }}-amd64/ | |
cp -r handlers ${{ matrix.os }}-amd64/ | |
cp -r lua ${{ matrix.os }}-amd64/ | |
- name: Build on macOS | |
if: matrix.os == 'macos' | |
run: | | |
env CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w -X main.sha1ver=$(git rev-parse --short HEAD) -X 'main.buildTime=$(date)'" -tags ${{ matrix.lua-version }} -o getnovel-amd64 . | |
if [ "${{ matrix.lua-version }}" == "luajit" ]; then | |
mv getnovel-amd64 getnovel | |
else | |
env CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w -X main.sha1ver=$(git rev-parse --short HEAD) -X 'main.buildTime=$(date)'" -tags ${{ matrix.lua-version }} -o getnovel-arm64 . | |
lipo -create -output getnovel getnovel-amd64 getnovel-arm64 | |
fi | |
curl -sSL -o kindlegen.zip https://github.com/ystyle/kaf-cli/releases/download/kindlegen/KindleGen_Mac_64bit_v2_9.zip | |
unzip kindlegen.zip | |
mkdir ${{ matrix.os }}-amd64 | |
cp getnovel ${{ matrix.os }}-amd64/ | |
cp kindlegen ${{ matrix.os }}-amd64/ | |
cp -r pdfpresets ${{ matrix.os }}-amd64/ | |
cp -r handlers ${{ matrix.os }}-amd64/ | |
cp -r lua ${{ matrix.os }}-amd64/ | |
- name: Build Lua on Windows | |
if: matrix.os == 'windows' | |
shell: msys2 {0} | |
run: | | |
cd golua/lua | |
env MSYSTEM=MINGW64 PATH=$PATH:/mingw64/bin ./buildlua.sh | |
cd - | |
- name: Build GetNovel on Windows | |
if: matrix.os == 'windows' | |
shell: cmd | |
run: | | |
set PATH=D:\a\_temp\msys64\mingw64\bin;%PATH% | |
for /F "tokens=*" %%R in ('git rev-parse --short HEAD') do set REV=%%R | |
for /F "tokens=*" %%A in ('date /T') do set TODAY=%%A | |
go build -ldflags="-s -w -X main.sha1ver=%REV% -X 'main.buildTime=%TODAY%'" -tags ${{ matrix.lua-version }} -o getnovel.exe . | |
- name: copy files on Windows | |
if: matrix.os == 'windows' | |
shell: msys2 {0} | |
run: | | |
curl -sSL -o kindlegen.zip https://github.com/ystyle/kaf-cli/releases/download/kindlegen/kindlegen_win32_v2_9.zip | |
unzip kindlegen.zip | |
mkdir ${{ matrix.os }}-amd64 | |
cp getnovel.exe ${{ matrix.os }}-amd64/ | |
cp kindlegen.exe ${{ matrix.os }}-amd64/ | |
cp -r pdfpresets ${{ matrix.os }}-amd64/ | |
cp -r handlers ${{ matrix.os }}-amd64/ | |
cp -r lua ${{ matrix.os }}-amd64/ | |
- name: Upload artifact getnovel-${{ matrix.os }}-amd64 | |
uses: actions/[email protected] | |
with: | |
name: getnovel-${{ matrix.os }}-${{ matrix.lua-version }} | |
path: ${{ matrix.os }}-amd64 | |
- name: Pack release | |
if: startsWith(github.event.ref, 'refs/tags/') | |
uses: vimtor/[email protected] | |
with: | |
files: ${{ matrix.os }}-amd64/ | |
recursive: true | |
dest: getnovel-${{ matrix.os }}-${{ matrix.lua-version }}.zip | |
- name: upload Release | |
if: startsWith(github.event.ref, 'refs/tags/') | |
uses: svenstaro/upload-release-action@v2 | |
with: | |
repo_token: ${{ secrets.GH_TOKEN }} | |
file: getnovel-${{ matrix.os }}-${{ matrix.lua-version }}.zip | |
asset_name: getnovel-${{ matrix.os }}-${{ matrix.lua-version }}.zip | |
tag: ${{ github.ref }} | |
overwrite: true |