From ed2fc6351948eb8ceac28a91e9ebd15f7655fa91 Mon Sep 17 00:00:00 2001 From: "(Jip) Willem Wijnia" Date: Fri, 31 May 2024 17:27:41 +0200 Subject: [PATCH] Add documentation to run the workflows locally --- .github/readme.md | 32 ++++++++++++++++++++++++++++++++ .github/workflows/build.yaml | 11 +++++++---- .github/workflows/generate.yaml | 10 ++++++++-- tools/index.ps1 | 20 ++++++++++++-------- 4 files changed, 59 insertions(+), 14 deletions(-) create mode 100644 .github/readme.md 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 f2b315b..cbcae2b 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -23,22 +23,25 @@ name: build on: workflow_dispatch: workflow_call: + push: jobs: - call-workflow-generate-in-local-repo: - uses: ./.github/workflows/generate.yaml + update: + uses: ./.github/workflows/generate.yaml build: - needs: [call-workflow-generate-in-local-repo] + 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 - uses: actions/download-artifact@v4 with: - name: spookydb-generated-files + name: spookydb-generated-files # 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 d0e5bce..edf25a6 100644 --- a/.github/workflows/generate.yaml +++ b/.github/workflows/generate.yaml @@ -30,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 @@ -48,6 +52,7 @@ jobs: with: repository: FAForever/nomads path: nomads + ref: master sparse-checkout-cone-mode: false sparse-checkout: | *.bp @@ -78,11 +83,12 @@ 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 + echo "pre-test" pwsh ./index.ps1 -target ../app -inputUnits "temp/units" -inputLua "temp/lua" + echo "post-test" # Store the created files 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 {