Skip to content

Commit

Permalink
Merge pull request #10 from pl-strflt/feat/add-test
Browse files Browse the repository at this point in the history
feat: add test for build-args
  • Loading branch information
galargh authored Aug 31, 2023
2 parents e744ac6 + e8d4f3d commit 940dab4
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Test
on:
push:
branches:
- main
pull_request:
jobs:
test-build-args:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: build the container and run it
id: run
uses: ./
with:
repository: ${{ github.repository }}
ref: ${{ github.sha }}
dockerfile: tests/Dockerfile.test-build-args
build-args: |
ARG_1:hello
ARG_2:foo
ARG_3:world
- name: check the output
env:
OUTPUTS: ${{steps.run.outputs.outputs }}
ARG_1: ${{ fromJSON(steps.run.outputs.outputs).arg-1 }}
ARG_2: ${{ fromJSON(steps.run.outputs.outputs).arg-2 }}
ARG_3: ${{ fromJSON(steps.run.outputs.outputs).arg-3 }}
run: |
echo ${OUTPUTS}
if [[ "$ARG_1" != "hello" ]]; then
echo "ARG_1 is not hello"
exit 1
fi
if [[ "$ARG_2" != "foo" ]]; then
echo "ARG_2 is not foo"
exit 1
fi
if [[ "$ARG_3" != "world" ]]; then
echo "ARG_3 is not world"
exit 1
fi
echo "all good"
17 changes: 17 additions & 0 deletions tests/Dockerfile.test-build-args
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# a simple container that takes 3 args and generate a shell script that prints them
FROM alpine:3.12.0

ARG ARG_1=default_1
ARG ARG_2=default_2
ARG ARG_3=default_3

RUN echo "#!/bin/sh" > /script.sh
RUN echo 'GITHUB_FILE_COMMANDS="$(dirname "$GITHUB_OUTPUT")"' >> /script.sh
RUN echo 'OUTPUT="${GITHUB_OUTPUT/"$GITHUB_FILE_COMMANDS"/"/github/file_commands"}"' >> /script.sh
RUN echo "echo \"arg-1=$ARG_1\" | tee -a \$OUTPUT" >> /script.sh
RUN echo "echo \"arg-2=$ARG_2\" | tee -a \$OUTPUT" >> /script.sh
RUN echo "echo \"arg-3=$ARG_3\" | tee -a \$OUTPUT" >> /script.sh

RUN chmod +x /script.sh

ENTRYPOINT ["/script.sh"]

0 comments on commit 940dab4

Please sign in to comment.