Create 474507D1 - Shutoko Battle X.patch.toml (#282) #833
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: | |
branches-ignore: [wip, nohash] | |
paths: | |
- '.github/workflows/ci.yml' | |
- 'package.json' | |
- 'patches/*.patch.toml' | |
pull_request: | |
branches-ignore: [wip, nohash] | |
jobs: | |
lint: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Setup | |
run: | | |
npm i -D --no-fund | |
sudo apt -y install pcregrep | |
- name: Lint | |
id: lint | |
run: | | |
npx eslint patches/*.patch.toml || patch_errored_fatal=1 | |
patch_check() { | |
local grep_result=$(pcregrep -Mno "$1" <<<"$2") | |
if [[ ( -z "$grep_result" && $3 = nomatch ) || ( -n "$grep_result" && $3 = match ) ]]; then | |
local patch_errored=1 | |
if [[ -z $patch_errored_fatal ]]; then | |
patch_errored_fatal=1 | |
fi | |
fi | |
if [ -n "$patch_errored" ]; then | |
case $3 in | |
match) | |
local grep_result_lines=($(grep -oP '[0-9]+(?=:)' <<<"$grep_result")) | |
for grep_result_line in "${grep_result_lines[@]}"; do | |
if [ -n "$5" ]; then | |
local grep_result_line_end=",endLine=$(( grep_result_line + $5 ))" | |
fi | |
echo "::error file=${patch},line=${grep_result_line}${grep_result_line_end}::$4" | |
done;; | |
nomatch) | |
echo "::error file=${patch}::$4";; | |
esac | |
fi | |
} | |
for patch in patches/*.patch.toml; do | |
patch_content="$(cat "$patch")" | |
patch_check 'patches\/[0-9A-F]{8} - .+\.patch\.toml' "$patch" nomatch "Filename is invalid!" | |
patch_check 'title_name = ".+"' "$patch_content" nomatch "title_name is invalid or missing!" | |
patch_check 'title_id = "[0-9A-F]{8}" # [A-Z]{2}-[0-9]{4,5}' "$patch_content" nomatch "title_id is invalid or missing!" | |
patch_check 'hash = ("[0-9A-F]{16}" # .+|\[.*\n {4}"[0-9A-F]{16}".*(\n#? {4}"[0-9A-F]{16}".*)*\n])|#hash = (""|\[(\n# {4}"".*)+\n#])' "$patch_content" nomatch "hash is invalid or missing!" | |
patch_check '#hash = (""|\[\n# {4}"").*' "$patch_content" match "hash is empty." | |
patch_check '#media_id = ("[0-9A-F]{8}".*|\[( # .+)?\n# {4}"[0-9A-F]{8}".*(\n# {4}"[0-9A-F]{8}".*)*\n#])|#media_id = ""' "$patch_content" nomatch "media_id is invalid or missing!" | |
patch_check '#media_id = ""' "$patch_content" match "media_id is empty." | |
patch_check '\[\[patch]]' "$patch_content" nomatch "[[patch]] is missing!" | |
patch_check ' {4}name = ".+"' "$patch_content" nomatch "name is invalid or missing!" | |
patch_check ' {4}desc = ""' "$patch_content" match "Unneeded empty description!" | |
patch_check ' {4}author = ".+"' "$patch_content" nomatch "author is invalid or missing!" | |
patch_check ' {4}is_enabled = ' "$patch_content" nomatch "is_enabled is missing!" | |
patch_check ' {4}is_enabled = true' "$patch_content" match "Patch is enabled!" | |
patch_check ' {8}address = 0x[0-9a-f]{8}' "$patch_content" nomatch "address is invalid or missing!" | |
patch_check ' {8}value = ' "$patch_content" nomatch "value is invalid or missing!" | |
patch_check ' {8}address = 0x[0-9a-f]{1,15}[A-F]+' "$patch_content" match "Hex can't be uppercase!" | |
patch_check ' {8}value = 0x"?[0-9a-f]{1,15}[A-F]+' "$patch_content" match "Hex can't be uppercase!" | |
patch_check ' {4}\[\[patch\.be8]]\n {8}address = 0x[0-9a-f]{8}\n {8}value = 0x([0-9a-f]?$|[0-9a-f]{3,})' "$patch_content" match "value length is wrong! be8 is supposed to be 1 byte." 2 | |
patch_check ' {4}\[\[patch\.be16]]\n {8}address = 0x[0-9a-f]{8}\n {8}value = 0x([0-9a-f]{0,3}$|[0-9a-f]{5,})' "$patch_content" match "value length is wrong! be16 is supposed to be 2 bytes." 2 | |
patch_check ' {4}\[\[patch\.be32]]\n {8}address = 0x[0-9a-f]{8}\n {8}value = 0x([0-9a-f]{0,7}$|[0-9a-f]{9,})' "$patch_content" match "value length is wrong! be32 is supposed to be 4 bytes." 2 | |
patch_check ' {4}\[\[patch\.be64]]\n {8}address = 0x[0-9a-f]{8}\n {8}value = 0x([0-9a-f]{0,15}$|[0-9a-f]{17,})' "$patch_content" match "value length is wrong! be64 is supposed to be 8 bytes." 2 | |
done | |
if [ -n "$patch_errored_fatal" ]; then | |
echo "Linting completed with errors!" | |
exit 1 | |
fi | |
- name: Release | |
if: | | |
steps.lint.conclusion == 'success' && | |
github.event_name == 'push' && | |
github.ref == 'refs/heads/main' && | |
github.repository == 'xenia-canary/game-patches' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
mkdir -p assets | |
echo -n $GITHUB_SHA > assets/version.txt | |
7z a assets/game-patches.zip patches | |
tag=latest | |
git tag -d $tag || true | |
git push --delete origin $tag || true | |
gh release delete $tag || true | |
gh release create $tag assets/* --target $GITHUB_SHA -t $tag | |
# workflow_dispatch: | |
# if: | | |
# github.event_name == 'push' && | |
# github.ref == 'refs/heads/main' && | |
# github.repository == 'xenia-canary/game-patches' | |
# needs: lint | |
# runs-on: ubuntu-latest | |
# steps: | |
# - uses: actions/checkout@v3 | |
# with: | |
# repository: xenia-canary/xenia-canary.github.io | |
# - name: Workflow dispatch | |
# env: | |
# GITHUB_TOKEN: ${{ secrets.WORKFLOW }} | |
# run: gh workflow run jekyll.yml |