ci #1172
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: ci | |
on: | |
push: | |
schedule: | |
- cron: '00 01 * * *' | |
jobs: | |
test: | |
name: test | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
build: | |
- linux | |
- macos | |
- win-msvc | |
include: | |
- build: linux | |
os: ubuntu-20.04 | |
- build: macos | |
os: macos-latest | |
- build: win-msvc | |
os: windows-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/checkout@v3 | |
name: Clone tokens | |
with: | |
path: assets/ | |
repository: pdx-tools/tokens | |
token: ${{secrets.GH_PAT}} | |
- name: Cache saves | |
uses: actions/cache@v3 | |
with: | |
path: assets/saves | |
key: assets/saves | |
- name: Set cargo environment variables | |
shell: bash | |
run: | | |
echo "EU4_IRONMAN_TOKENS=$current_dir/assets/tokens/eu4.txt" >> $GITHUB_ENV | |
echo "CK3_IRONMAN_TOKENS=$current_dir/assets/tokens/ck3.txt" >> $GITHUB_ENV | |
echo "IMPERATOR_TOKENS=$current_dir/assets/tokens/imperator.txt" >> $GITHUB_ENV | |
echo "HOI4_IRONMAN_TOKENS=$current_dir/assets/tokens/hoi4.txt" >> $GITHUB_ENV | |
echo "VIC3_IRONMAN_TOKENS=$current_dir/assets/tokens/vic3.txt" >> $GITHUB_ENV | |
env: | |
current_dir: ${{ github.workspace }} | |
- name: Build | |
run: cargo build --all --verbose --release | |
- name: create save assets directory | |
shell: bash | |
run: mkdir -p assets/saves | |
- name: Retrieve assets | |
shell: bash | |
run: | | |
[ ! -f kandy2.bin.eu4 ] && curl -O https://eu4saves-test-cases.s3.us-west-002.backblazeb2.com/kandy2.bin.eu4 || true | |
[ ! -f af_Munso_867_Ironman.ck3 ] && curl -O https://ck3saves-test-cases.s3.us-west-002.backblazeb2.com/af_Munso_867_Ironman.ck3 || true | |
[ ! -f observer1.5.rome ] && curl -O https://imperator-test-cases.s3.us-west-002.backblazeb2.com/observer1.5.rome || true | |
[ ! -f 1.10-ironman.zip ] && curl -O https://hoi4saves-test-cases.s3.us-west-002.backblazeb2.com/1.10-ironman.zip && unzip 1.10-ironman.zip || true | |
working-directory: ./assets/saves | |
- name: Run verifier | |
if: matrix.os == 'ubuntu-20.04' | |
working-directory: ./target | |
run: | | |
set -eou | |
cp ../sample.cpp . | |
cp ./release/librakaly.so . | |
g++ sample.cpp -o melter -std=c++17 -Werror -Wall -Wextra -O2 librakaly.so | |
LD_LIBRARY_PATH=. ./melter save ../assets/saves/kandy2.bin.eu4 > /dev/null | |
LD_LIBRARY_PATH=. ./melter save ../assets/saves/af_Munso_867_Ironman.ck3 > /dev/null | |
LD_LIBRARY_PATH=. ./melter save ../assets/saves/observer1.5.rome > /dev/null | |
LD_LIBRARY_PATH=. ./melter save ../assets/saves/1.10-ironman.hoi4 > /dev/null | |
- uses: ilammy/msvc-dev-cmd@v1 | |
- name: Run verifier (windows) | |
if: matrix.os == 'windows-latest' | |
working-directory: ./target | |
run: | | |
cp ..\sample.cpp . | |
cp .\release\rakaly* . | |
cl /EHsc sample.cpp /std:c++17 /link rakaly.dll.lib /out:melter.exe | |
.\melter.exe save ..\assets\saves\kandy2.bin.eu4 > NUL | |
.\melter.exe save ..\assets\saves\af_Munso_867_Ironman.ck3 > NUL | |
.\melter.exe save ..\assets\saves\observer1.5.rome > NUL | |
.\melter.exe save ..\assets\saves\1.10-ironman.hoi4 > NUL | |
- name: Stage Release | |
shell: bash | |
run: | | |
if [[ "${GITHUB_REF}" = *refs/tags/* ]]; then | |
VERSION="${GITHUB_REF#refs/tags/}" | |
else | |
VERSION="vnightly" | |
fi | |
echo "version is $VERSION" | |
STAGING="librakaly-${VERSION:1}" | |
echo "STAGING DIR: $STAGING" | |
mkdir $STAGING | |
if [[ "${{ matrix.os }}" = windows* ]]; then | |
cp target/release/rakaly.{dll,dll.lib} "$STAGING/" | |
cp target/rakaly.h "$STAGING/" | |
else | |
find target/release -maxdepth 1 -name "librakaly.so" -o -name "librakaly.dylib" | xargs -I{} cp {} "$STAGING/" | |
fi | |
echo "ASSET=$STAGING" >> $GITHUB_ENV | |
- uses: actions/upload-artifact@v3 | |
with: | |
path: ${{ env.ASSET }} | |
name: ${{ env.ASSET }} | |
if-no-files-found: error | |
release: | |
needs: test | |
runs-on: ubuntu-20.04 | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/download-artifact@v3 | |
with: | |
path: artifacts-temp | |
- name: Flatten artifacts | |
run: | | |
mkdir artifacts | |
cd artifacts-temp | |
for i in *; do | |
if [[ "$i" = *windows* ]]; then | |
7z a "../artifacts/$(basename "$i").zip" "$i" | |
else | |
tar czf "../artifacts/$(basename "$i").tar.gz" "$i" | |
fi | |
done | |
ls -lR ../artifacts | |
- name: Create Release | |
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
console.log('environment', process.versions); | |
const fs = require('fs').promises; | |
const { repo: { owner, repo }, sha } = context; | |
console.log({ owner, repo, sha }); | |
const tag_name = process.env.GITHUB_REF.split("/")[2]; | |
const release = await github.rest.repos.createRelease({ | |
owner, repo, | |
tag_name, | |
draft: false, | |
target_commitish: sha | |
}); | |
console.log('created release', { release }); | |
for (let file of await fs.readdir('artifacts')) { | |
console.log('uploading', file); | |
await github.rest.repos.uploadReleaseAsset({ | |
owner, repo, | |
release_id: release.data.id, | |
name: file, | |
data: await fs.readFile(`artifacts/${file}`) | |
}); | |
} |