diff --git a/.github/readme.md b/.github/readme.md new file mode 100644 index 0000000..aaa5aa0 --- /dev/null +++ b/.github/readme.md @@ -0,0 +1,32 @@ +# Debug workflows locally + +## Prerequisites + +- (1) [Github CLI](https://github.com/cli/cli) + +Verify that Github CLI is installed and available via `gh --version`. You need to authorize yourself via `gh login`. Once authorised, verify that `gh auth token` returns a value. You'll need that token to authorize yourself through `act`. + +- (2) [Act](https://github.com/nektos/act) + +Verify that act is installed and available via `act --version`. There are [various ways](https://nektosact.com/installation/index.html) to install it via a tool, downloading the artifact that matches your OS and adding it to the path is sufficient however. + +- (3) [Docker](https://www.docker.com/products/docker-desktop/) + +Verify that docker is installed and available via `docker --version`. Act uses docker containers to containerize your workflows. You'll need to start the `Docker Desktop` application to guarantee that the docker engine is running. + +## Debug a workflow + +The tool `act` only works on workflows that have the `push` event. Add the `push` event to the workflow that you want to test if it is missing. + +```bash + # # Non-standard image that has `pwsh` installed # Workflow to debug # Token to authorize + act -P 'ubuntu-latest=ghcr.io/catthehacker/ubuntu:pwsh-22.04' -W '.github/workflows/build.yaml' -s GITHUB_TOKEN="$(gh auth token)" + + # for repeated tests # do not pull (-p) the docker image each time + act -P 'ubuntu-latest=ghcr.io/catthehacker/ubuntu:pwsh-22.04' -W '.github/workflows/build.yaml' -s GITHUB_TOKEN="$(gh auth token)" -p=false +``` + +Useful references: + +- [Documentation about act](https://nektosact.com/introduction.html) +- [List of all official docker images](https://github.com/catthehacker/docker_images) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 9afe5fb..54bfc11 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -22,15 +22,31 @@ name: build on: workflow_dispatch: + workflow_call: jobs: + update: + uses: ./.github/workflows/generate.yaml build: + needs: [update] name: build application runs-on: ubuntu-latest steps: # https://github.com/actions/checkout/tree/v4/ - name: Checkout spooky db code uses: actions/checkout@v4 + with: + ref: master + + - name: Remove existing unit information + run: | + rm app/data/*.json + + - name: Download recent unit information + uses: actions/download-artifact@v4 + with: + name: spookydb-generated-files + path: app/data # https://github.com/actions/setup-node/tree/main - name: Use Node.js 20.x diff --git a/.github/workflows/generate.yaml b/.github/workflows/generate.yaml index 71c2a15..14b156a 100644 --- a/.github/workflows/generate.yaml +++ b/.github/workflows/generate.yaml @@ -22,6 +22,7 @@ name: generate on: workflow_dispatch: + workflow_call: jobs: generate: @@ -29,14 +30,18 @@ jobs: permissions: write-all runs-on: ubuntu-latest steps: + # Checking repositories - name: Checkout spooky db code uses: actions/checkout@v4 + with: + ref: master - name: Checkout FAForever blueprints and lua files uses: actions/checkout@v4 with: repository: FAForever/fa path: fa + ref: deploy/faf sparse-checkout-cone-mode: false sparse-checkout: | *.bp @@ -47,6 +52,7 @@ jobs: with: repository: FAForever/nomads path: nomads + ref: master sparse-checkout-cone-mode: false sparse-checkout: | *.bp @@ -77,10 +83,9 @@ jobs: mv fa/lua/version.lua tools/temp/lua/version.lua - name: Run the script - shell: pwsh + shell: bash working-directory: tools # script expects this directory run: | - lua -v pwsh ./index.ps1 -target ../app -inputUnits "temp/units" -inputLua "temp/lua" # Store the created files @@ -88,6 +93,6 @@ jobs: - name: Create artifact uses: actions/upload-artifact@v4 with: - name: Generated files + name: spookydb-generated-files path: | app/data diff --git a/tools/index.ps1 b/tools/index.ps1 index 0ccf103..7d1e637 100644 --- a/tools/index.ps1 +++ b/tools/index.ps1 @@ -11,6 +11,10 @@ param ( [string]$inputLua = "" ) +Write-Output "target: $target" +Write-Output "inputUnits: $inputUnits" +Write-Output "inputLua: $inputLua" + $env:Path -split ';' Function Create-UnitIndex { @@ -21,29 +25,29 @@ Function Create-UnitIndex { $version = lua getVersion.lua "$luaVersionFile" - echo '{' - echo "`"version`": `"$version`"," + Write-Output '{' + Write-Output "`"version`": `"$version`"," $blueprints = Get-ChildItem "$unitDir\**\*_unit.bp" $count = 1 $total = $blueprints.Count - echo '"units": ' - echo '[' + Write-Output '"units": ' + Write-Output '[' $blueprints | Foreach-Object { $file = $_.BaseName Write-Progress -Activity "Parsing $file" -Status "($count/$total)" lua blueprint2json.lua $_.FullName if ($count -lt $total) { - echo ',' + Write-Output ',' } $count++ } - echo ']' + Write-Output ']' - echo '}' + Write-Output '}' } Function Create-Version { @@ -53,7 +57,7 @@ Function Create-Version { $version = lua getVersion.lua "$luaVersionFile" - echo "{ `"version`": `"$version`" }" + Write-Output "{ `"version`": `"$version`" }" } Function Run {