diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..3385ca5 --- /dev/null +++ b/.github/workflows/test.yml @@ -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" diff --git a/tests/Dockerfile.test-build-args b/tests/Dockerfile.test-build-args new file mode 100644 index 0000000..b067290 --- /dev/null +++ b/tests/Dockerfile.test-build-args @@ -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"]