Sub topic 3
Passing Inputs to a Container and Returning Outputs
Assume you know workflow syntax, basic Docker, shell commands, Git, and JavaScript packaging. A container action receives declared inputs as command-line arguments. It returns outputs by writing name=value lines to the file named by GITHUB_OUTPUT.
Pass values through the action
In action.yml, map an input to the container's arguments:
name: Hello container
description: Greet someone from a container
inputs:
who-to-greet:
description: Name to greet
required: true
default: World
outputs:
time:
description: UTC time of the greeting
runs:
using: docker
image: Dockerfile
args:
- ${{ inputs.who-to-greet }}The Dockerfile selects the entrypoint:
FROM alpine:3.20
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]The script reads $1 and publishes an output:
#!/bin/sh -l
set -eu
printf 'Hello %s\n' "$1"
printf 'time=%s\n' "$(date -u +%FT%TZ)" >> "$GITHUB_OUTPUT"Call the action from a workflow
Checkout is required before uses: ./ can find the action:
steps:
- uses: actions/checkout@v4
- id: greet
uses: ./
with:
who-to-greet: Mona
- run: echo "Greeted at ${{ steps.greet.outputs.time }}"The step id creates the namespace for its outputs.
Test, clean up, and release
Test the entrypoint with a shell test and test integration with a workflow. For setup and cleanup, JavaScript actions can declare runs.pre and runs.post, such as lib/setup.js and lib/cleanup.js. Use these for temporary credentials or files, and make cleanup tolerate partial setup.
Create an immutable release tag, such as v1.2.0, then move the major tag v1 to that commit. Consumers can choose stable major updates or pin an exact commit.
Treat inputs as untrusted. Quote shell variables, avoid eval, do not print secrets, request minimal permissions, and pin third-party actions to full commit SHAs.
Exercise
How does a later step read the container action's time output?
Show answer
Give the action step an id, such as greet, then use ${{ steps.greet.outputs.time }}.