Skip to content

Commit

Permalink
Merge pull request #692 from alerque/as-gh-action
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque authored Aug 24, 2022
2 parents 2c6f027 + 3dc706d commit 829e23a
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,16 @@ jobs:
rockspecs: ${{ needs.affected.outputs.rockspecs }}
secrets:
apikey: ${{ secrets.LUAROCKS_APIKEY }}

docker:
if: >-
${{
github.repository == 'lunarmodules/busted' &&
( github.ref_name == 'master' || startsWith(github.ref, 'refs/tags/') )
}}
uses: lunarmodules/.github/.github/workflows/docker_ghcr_deploy.yml@main
with:
username: ${{ github.actor }}
tag: ${{ github.ref_name }}
secrets:
token: ${{ secrets.GHCR_PAT }}
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#syntax=docker/dockerfile:1.2

FROM akorn/luarocks:lua5.4-alpine AS builder

RUN apk add --no-cache -X http://dl-cdn.alpinelinux.org/alpine/edge/testing \
dumb-init gcc libc-dev

COPY ./ /src
WORKDIR /src

RUN luarocks --tree /pkgdir/usr/local make
RUN find /pkgdir -type f -exec sed -i -e 's!/pkgdir!!g' {} \;

FROM akorn/luarocks:lua5.4-alpine AS final

RUN apk add --no-cache -X http://dl-cdn.alpinelinux.org/alpine/edge/testing \
dumb-init

LABEL org.opencontainers.image.title="Busted"
LABEL org.opencontainers.image.description="A containerized version of Busted, a unit testing framework for Lua."
LABEL org.opencontainers.image.authors="Caleb Maclennan <[email protected]>"
LABEL org.opencontainers.image.licenses="MIT"
LABEL org.opencontainers.image.url="https://github.com/lunarmodules/busted/pkgs/container/busted"
LABEL org.opencontainers.image.source="https://github.com/lunarmodules/busted"

COPY --from=builder /pkgdir /
RUN busted --version

WORKDIR /data

ENTRYPOINT ["busted", "--verbose"]
73 changes: 73 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,79 @@ luarocks make
busted spec
```

Docker
------

Alternatively Busted can be run as a standalone docker container.
This approach is somewhat limited because many projects will require extra dependencies which will need to be installed inside the Docker container.
Luarocks is provided in the container so many dependencies can be added.
The images are based on Alpine Linux so you can also use `apk add` to install system dependencies if needed.
The Docker use case is probably most advantageous for pure-Lua projects with no dependencies: i.g. small libraries not large apps.

The usage of docker is fairly simple.
You can either build your own or download a prebuilt version.
To build your own, execute the following command from the source directory of this project:

```console
$ docker build -t ghcr.io/lunarmodules/busted:HEAD .
```

To use a prebuilt one, download it from the GitHub Container Registry.
Here we use the one tagged *latest*, but you can substitute *latest* for any tagged release.

```console
$ docker pull ghcr.io/lunarmodules/busted:latest
```

Once you have a container you can run it on one file or a source tree (substitute *latest* with *HEAD* if you built your own or with the tagged version you want if applicable):

```console
# Run on an entire project
$ docker run -v "$(pwd):/data" ghcr.io/lunarmodules/busted:latest

# Run on one directory:
$ docker run -v "$(pwd):/data" ghcr.io/lunarmodules/busted:latest specs
```

A less verbose way to run it in most shells is with at alias:

```console
# In a shell or in your shell's RC file:
$ alias busted='docker run -v "$(pwd):/data" ghcr.io/lunarmodules/busted:latest'

# Thereafter just run:
$ busted
```
### Use as a CI job

There are actually many ways to run Busted remotely as part of a CI work flow.
Because packages are available for many platforms, one way would be to just use your platforms native package installation system to pull them into whatever CI runner environment you already use.
Another way is to pull in the prebuilt Docker container and run that.

As a case study, here is how a workflow could be setup in GitHub Actions:

```yaml
name: Busted
on: [push, pull_request]
jobs:
sile:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Run Busted
uses: lunarmodules/busted@v0
```
By default the GH Action is configured to run `busted --verbose`, but you can also pass it your own `args` to replace the default input of `.`.

```yaml
- name: Run Busted
uses: lunarmodules/busted@v0
with:
args: --tags=MYTAGS
```

License
-------

Expand Down
17 changes: 17 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Busted
description: Busted
inputs:
args:
description: Arguments passed to busted
required: false
default: "."
runs:
using: docker
image: docker://ghcr.io/lunarmodules/busted:v2.0.0
entrypoint: sh
args:
- -c
- busted ${{ inputs.args }}
branding:
icon: check
color: yellow

0 comments on commit 829e23a

Please sign in to comment.