Skip to content

Commit

Permalink
Add documentation to run the workflows locally
Browse files Browse the repository at this point in the history
  • Loading branch information
Garanas committed May 31, 2024
1 parent 43ef288 commit ed2fc63
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 14 deletions.
32 changes: 32 additions & 0 deletions .github/readme.md
Original file line number Diff line number Diff line change
@@ -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)
11 changes: 7 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/generate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -48,6 +52,7 @@ jobs:
with:
repository: FAForever/nomads
path: nomads
ref: master
sparse-checkout-cone-mode: false
sparse-checkout: |
*.bp
Expand Down Expand Up @@ -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

Expand Down
20 changes: 12 additions & 8 deletions tools/index.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -53,7 +57,7 @@ Function Create-Version {

$version = lua getVersion.lua "$luaVersionFile"

echo "{ `"version`": `"$version`" }"
Write-Output "{ `"version`": `"$version`" }"
}

Function Run {
Expand Down

0 comments on commit ed2fc63

Please sign in to comment.