Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/action build update #131

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
17 changes: 17 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,32 @@ name: build

on:
workflow_dispatch:
workflow_call:
push:

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
Expand Down
13 changes: 10 additions & 3 deletions .github/workflows/generate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,26 @@ name: generate

on:
workflow_dispatch:
workflow_call:

jobs:
generate:
name: generate
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 @@ -47,6 +52,7 @@ jobs:
with:
repository: FAForever/nomads
path: nomads
ref: master
sparse-checkout-cone-mode: false
sparse-checkout: |
*.bp
Expand Down Expand Up @@ -77,17 +83,18 @@ 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

- name: Create artifact
uses: actions/upload-artifact@v4
with:
name: Generated files
name: spookydb-generated-files
path: |
app/data
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
Loading