Skip to content

Commit e1608fd

Browse files
authored
Merge pull request #2 from joshraphael/ci/template
Ci/template
2 parents 89f8ba0 + 5e72a1b commit e1608fd

File tree

8 files changed

+122
-2
lines changed

8 files changed

+122
-2
lines changed

.github/workflows/test.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Test action template file
2+
3+
on:
4+
push:
5+
branches:
6+
- '*'
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
template:
14+
name: template
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: Check template is correct
19+
run: bash ./scripts/check.sh

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
playground/

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
template:
2+
./scripts/template.sh > action.yml
3+
4+
check:
5+
./scripts/check.sh
6+
7+
hooks:
8+
./scripts/hooks.sh

action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: RAScript Audit
2-
description: Compiles an RAScript for RetroAchievements development and performs an audit on the code.
2+
description: Compile and review a RAScript achievement logic file for Retro Achievements
33
author: joshraphael
44

55
inputs:
@@ -8,7 +8,7 @@ inputs:
88
type: string
99
required: true
1010
game-id:
11-
description: "RetroAchievements game id"
11+
description: "Retro Achievements game id"
1212
type: number
1313
required: true
1414
rascript:

scripts/check.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
export PLAYGROUND="playground"
4+
export GENERATED_FILE="${PLAYGROUND}/action2.yml"
5+
export GE
6+
7+
rm -rf ${PLAYGROUND}
8+
mkdir -p ${PLAYGROUND}
9+
cp action.yml ${PLAYGROUND}
10+
./scripts/template.sh > ${GENERATED_FILE}
11+
12+
if cmp -s ${PLAYGROUND}/action.yml ${GENERATED_FILE}; then
13+
echo "The files are identical."
14+
exit 0
15+
fi
16+
17+
echo "The files are different."
18+
diff ${PLAYGROUND}/action.yml ${GENERATED_FILE}
19+
exit 1

scripts/hooks.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
export CHECK_SCRIPT="scripts/check.sh"
4+
export HOOKS_DIR=".git/hooks"
5+
export PRE_COMMIT_FILE="${HOOKS_DIR}/pre-commit"
6+
mkdir -p ${HOOKS_DIR}
7+
rm -rf ${PRE_COMMIT_FILE}
8+
cp ${CHECK_SCRIPT} ${PRE_COMMIT_FILE}

scripts/template.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
export CONTAINER_ID='$CONTAINER_ID'
4+
export RASCRIPT_AUDIT_IMG_VERSION="v0.0.4"
5+
6+
cat templates/action.template.yml | envsubst

templates/action.template.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: RAScript Audit
2+
description: Compile and review a RAScript achievement logic file for Retro Achievements
3+
author: joshraphael
4+
5+
inputs:
6+
id:
7+
description: "Unique identifier to prepend on the output file"
8+
type: string
9+
required: true
10+
game-id:
11+
description: "Retro Achievements game id"
12+
type: number
13+
required: true
14+
rascript:
15+
description: "The RAScript file name to compile"
16+
type: string
17+
required: true
18+
report:
19+
description: "Create a report of the audit"
20+
type: boolean
21+
required: false
22+
severity:
23+
description: "Level of severity to fail on"
24+
type: choice
25+
required: false
26+
options:
27+
- info
28+
- warn
29+
- error
30+
31+
branding:
32+
color: blue
33+
icon: award
34+
35+
runs:
36+
using: 'composite'
37+
steps:
38+
- name: Checkout repo
39+
uses: actions/checkout@v4
40+
- name: pull image
41+
if: ${{ 1 == 0 }} # this is a hack to pre-fetch the docker image to reduce the logs in the actual action
42+
uses: docker://ghcr.io/joshraphael/rascript-audit-img:${RASCRIPT_AUDIT_IMG_VERSION}
43+
- name: Run rascript-audit
44+
shell: bash
45+
run: |
46+
docker container rm -f rascript-audit-img
47+
mkdir -p container_home
48+
docker run --name rascript-audit-img -e GAME_ID=${{ inputs.game-id }} -e RASCRIPT_FILE="${{ inputs.rascript }}" -e REPORT=${{ inputs.report }} -e SEVERITY=${{ inputs.severity }} --mount type=bind,src=.,dst=/app/rascript -i --entrypoint=/app/entry.sh ghcr.io/joshraphael/rascript-audit-img:${RASCRIPT_AUDIT_IMG_VERSION}
49+
export CONTAINER_ID=$(docker ps -a --filter name=${{ inputs.name }} -q)
50+
docker cp $CONTAINER_ID:/app/home.txt container_home/
51+
docker cp $CONTAINER_ID:/app/copy.sh container_home/
52+
GAME_ID=${{ inputs.game-id }} REPORT=${{ inputs.report }} bash container_home/copy.sh
53+
rm -rf container_home/home.txt
54+
rm -rf container_home/copy.sh
55+
- name: Upload Audit
56+
uses: actions/upload-artifact@v4
57+
with:
58+
name: ${{ inputs.id }}-${{ inputs.game-id }}-audit
59+
path: container_home/

0 commit comments

Comments
 (0)