Skip to content

Commit

Permalink
(#3) Path and Wesnoth version parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
czyzby committed Jan 12, 2022
1 parent 178b5b9 commit 9da9208
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 22 deletions.
13 changes: 1 addition & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
FROM python:3.10
FROM python:3.10-slim

RUN apt-get update >/dev/null && \
apt-get upgrade -y >/dev/null && \
apt-get install -y git

RUN echo "Cloning Wesnoth ${WESNOTH_VERSION:-master}." && \
git clone \
--depth 1 \
--filter=blob:none \
--sparse \
--single-branch --branch ${WESNOTH_VERSION:-master} \
https://github.com/wesnoth/wesnoth \
/wesnoth
WORKDIR /wesnoth
RUN git sparse-checkout set data/tools/

COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ Add a workflow that triggers this action. For more info, see
the following examples of GitHub workflows.

The Wesnoth version that the WML files are checked against can
be specified with the `WESNOTH_VERSION` environment variable.
It can match any Wesnoth [branch](https://github.com/wesnoth/wesnoth/branches)
be specified with the `wesnoth-version` parameter. It can match
any Wesnoth [branch](https://github.com/wesnoth/wesnoth/branches)
or [tag](https://github.com/wesnoth/wesnoth/tags).

The folder or file that should be validated can be specified with
the `path` parameter.

### Examples

A workflow that verifies WML files on every push to the repository,
Expand All @@ -32,12 +35,12 @@ jobs:
steps:
- name: Repository checkout
uses: actions/checkout@v2
- name: WML Lint
- name: Lint WML
uses: czyzby/wesnoth-wml-linter@v1
```
A workflow that verifies WML files against Wesnoth 1.16 tools
on every push or pull request to a specific branch:
A workflow that verifies WML files in the `units/` folder against
Wesnoth 1.16 tools on every push or pull request to a specific branch:

```yaml
name: lint
Expand All @@ -55,10 +58,11 @@ jobs:
steps:
- name: Repository checkout
uses: actions/checkout@v2
- name: WML Lint
- name: Lint WML
uses: czyzby/wesnoth-wml-linter@v1
env:
WESNOTH_VERSION: 1.16
with:
path: units/
wesnoth-version: 1.16
```

## Notes
Expand Down
12 changes: 12 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
name: 'WML Linter'
description: 'Runs wmllint and wmlindent to verify the WML files.'
inputs:
path:
description: 'Path to file or directory that should be validated.'
required: true
default: .
wesnoth-version:
description: 'Wesnoth repository branch or tag to check against.'
required: false
default: master
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.path }}
- ${{ inputs.wesnoth-version }}
15 changes: 13 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
#!/bin/bash -l

echo "Cloning Wesnoth ${2:-master}."
git clone \
--depth 1 \
--filter=blob:none \
--sparse \
--single-branch --branch ${2:-master} \
-c advice.detachedHead=false \
https://github.com/wesnoth/wesnoth \
/wesnoth
(cd /wesnoth && git sparse-checkout set data/tools/)

# Capturing Python script stdout.
exec 5>&1

echo "Running wmllint."
lint=$(python /wesnoth/data/tools/wmllint -d -S . 2>&1 | tee >(cat - >&5))
lint=$(python /wesnoth/data/tools/wmllint -d -S $1 2>&1 | tee >(cat - >&5))

echo "Running wmlindent."
indent=$(python /wesnoth/data/tools/wmlindent -d . 2>&1 | tee >(cat - >&5))
indent=$(python /wesnoth/data/tools/wmlindent -d $1 2>&1 | tee >(cat - >&5))

if [[ -z $indent && -z $lint ]]; then
exit 0
Expand Down

0 comments on commit 9da9208

Please sign in to comment.