My goal is to use an image as a GitHub Action, and controlling the boolean flags.
I have a Docker image which has in its entry a binary. This is part of the Dockerfile:
# Stage 2 - Create tiny final image
FROM scratch
# Copy binary and CA certs
COPY --from=builder /app/binary /binary
# Set working directory
WORKDIR /
# Define entrypoint
ENTRYPOINT ["/binary"]
After that I push the image to Docker Hub.
I tried to create action.yml
in binary-scan:
name: Zanadir Action
description: Scan your GitHub repository using Zanadir tool
inputs:
dir:
description: 'Path to the GitHub repository directory (required)'
required: true
excluded-categories:
description: 'List of excluded categories (optional)'
required: false
enforce:
description: 'Fails the CI process when at least one rule is met (optional)'
required: false
debug:
description: 'Run the tool using debug mode (optional)'
required: false
output:
description: 'Output format of the tool (Table, Json) (optional)'
required: false
runs:
using: "docker"
image: "docker://mustachecase/zanadir:latest"
args:
- "scan"
- "--dir"
- "${{ inputs.dir }}"
- "--excluded-categories"
- "${{ inputs.excluded-categories }}"
- "--output"
- "${{ inputs.output }}"
- "--debug"
- "${{ inputs.debug }}"
- "--enforce"
- "${{ inputs.enforce }}"
I'm having issues with the flags "enforce" and "debug" which are booleans. In both cases they are included in the command. If debug/enforce or any other boolean flag is false, I don't want it to be part of the command.
the answer is:
- ${{ inputs.debug == 'true' && '--debug' || '' }}
- ${{ inputs.enforce == 'true' && '--enforce' || '' }}