Skip to content

Fix Recipe (#49)

Fix Recipe (#49) #142

Workflow file for this run

name: Validate Schemas
on: [push, pull_request]
jobs:
generate-matrix:
name: Generate Job Matrix
runs-on: ubuntu-latest
outputs:
changed_schema: ${{ steps.check-schemas.outputs.changed_schema }}
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: tj-actions/changed-files@v40
id: changed-files
# Don't run if there are no changes in the Schemas folder
- name: Check for changes in Schemas folder
id: check-schemas
run: |
changed_schema=false
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
if [[ $file == *"Schemas"* ]]; then
changed_schema=true
fi
done
echo "changed_schema=$changed_schema"
echo "changed_schema=$changed_schema" >> $GITHUB_OUTPUT
# Create a list of all game versions with a changed schema.
# We manually create a JSON string here because that's the only way
# to get this info into the matrix for the next job
- name: Set Matrix
if: steps.check-schemas.outputs.changed_schema == 'true'
id: set-matrix
run: |
JSON="{\"gamever\":["
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
folder="$(basename "$(dirname "$file")")"
# do something with $folder
echo "$folder"
JSONline="\"$folder\","
# de-dupe and ignore non-game versions
if [[ "$JSON" != *"$JSONline"* ]]; then
# grep regex for \d{4}\.\d{2}\.\d{2}\.\d{4}\.\d{4}
if [[ $folder =~ ^[0-9]{4}\.[0-9]{2}\.[0-9]{2}\.[0-9]{4}\.[0-9]{4}$ ]]; then
JSON="$JSON$JSONline"
fi
fi
done
# Remove last "," and add the closing bracket
if [[ $JSON == *, ]]; then
JSON="${JSON%?}"
fi
JSON="$JSON]}"
echo $JSON
echo "matrix=$( echo "$JSON" )" >> $GITHUB_OUTPUT
validate:
name: Validate
# Crucially must run on a self-hosted runner with the expected setup in /opt/
# it is recommended that the self-hosted runner uses DirectoryManager on a schedule
# for automatic updates to the output and storage directories
# Expected "directory" (from EXDTools/DirectoryManager) directory: `/opt/exd/output/`
# Expected storage directory (same): `/opt/exd/storage/`
# Everything else is handled by the action.
runs-on: self-hosted
needs: generate-matrix
if: needs.generate-matrix.outputs.changed_schema == 'true'
strategy:
matrix: ${{fromJson(needs.generate-matrix.outputs.matrix)}}
steps:
- run: echo "Validating ${{ matrix.gamever }}"
- uses: actions/checkout@v4
# Fetch SchemaValidator from xivdev/EXDTools latest releases
- name: Download SchemaValidator
uses: robinraju/[email protected]
with:
repository: "xivdev/EXDTools"
latest: true
fileName: "SchemaValidator-linux-x64"
# Fetch Schema.json from xivdev/EXDTools latest releases
- name: Download Schema.json
uses: robinraju/[email protected]
with:
repository: "xivdev/EXDTools"
latest: true
fileName: "Schema.json"
- name: Run SchemaValidator
run: |
chmod +x SchemaValidator-linux-x64
./SchemaValidator-linux-x64 /opt/exd/output/${{ matrix.gamever }}.json /opt/exd/storage/ Schema.json Schemas/${{ matrix.gamever }}/ CI
- name: Process results
run: |
cat message
failureCount=$(cat failure)
if [[ $failureCount -gt 0 ]]; then
exit 1
fi
errorCount=$(cat error)
if [[ $errorCount -gt 0 ]]; then
exit 1
fi
# Publish a release if the validation was successful on main
publish:
name: Publish
runs-on: ubuntu-latest
needs: validate
if: github.ref == 'refs/heads/main'
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Define version
id: define-version
run: echo "version=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Create Artifacts
run: |
rm -rf release-out/
mkdir release-out/
cd Schemas
for d in * ; do
echo "Zipping $d"
zip -rq9 ../release-out/$d.zip $d
done
- name: Create Release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: release-out/**
name: Release for ${{ steps.define-version.outputs.version }}
tag_name: ${{ steps.define-version.outputs.version }}
- uses: dev-drprasad/[email protected]
with:
keep_latest: 1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}