Switch to env var for input

This commit is contained in:
Nick Alteen 2023-09-01 14:47:27 -04:00
parent db66df907b
commit 11b982c253
4 changed files with 20 additions and 10 deletions

View File

@ -48,8 +48,8 @@ jobs:
INPUT_WHO_TO_GREET: Mona Lisa Octocat INPUT_WHO_TO_GREET: Mona Lisa Octocat
run: | run: |
docker run \ docker run \
--rm ${{ env.TEST_TAG }} \ --env INPUT_WHO_TO_GREET="${{ env.INPUT_WHO_TO_GREET }}" \
${{ env.INPUT_WHO_TO_GREET }} --rm ${{ env.TEST_TAG }}
test-action: test-action:
name: GitHub Actions Test name: GitHub Actions Test

View File

@ -51,11 +51,20 @@ need to perform some initial setup steps before you can develop your action.
1. :white_check_mark: Test the container 1. :white_check_mark: Test the container
You can pass input arguments in the `docker run` call. You can pass individual environment variables using the `--env` or `-e` flag.
```bash ```bash
$ docker run actions/container-action "Mona Lisa Octocat" $ docker run --env INPUT_WHO_TO_GREET="Mona Lisa Octocat" actions/container-action
::notice file=entrypoint.sh,line=7::Hello, Mona Lisa Octocat!
```
Or you can pass a file with environment variables using `--env-file`.
```bash
$ cat ./.env.test
INPUT_WHO_TO_GREET="Mona Lisa Octocat"
$ docker run --env-file ./.env.test actions/container-action
::notice file=entrypoint.sh,line=7::Hello, Mona Lisa Octocat! ::notice file=entrypoint.sh,line=7::Hello, Mona Lisa Octocat!
``` ```
@ -76,12 +85,13 @@ can choose any base Docker image and language you like, you can change this to
suite your needs. There are a few main things to remember when writing code for suite your needs. There are a few main things to remember when writing code for
container actions: container actions:
- Inputs are accessed using argument identifiers. For example, the first input - Inputs are accessed using argument identifiers or environment variables
(depending on what you set in your `action.yml`). For example, the first input
to this action, `who-to-greet`, can be accessed in the entrypoint script using to this action, `who-to-greet`, can be accessed in the entrypoint script using
`$1`. the `$INPUT_WHO_TO_GREET` environment variable.
```bash ```bash
GREETING="Hello, $1!" GREETING="Hello, $INPUT_WHO_TO_GREET!"
``` ```
- GitHub Actions supports a number of different workflow commands such as - GitHub Actions supports a number of different workflow commands such as

View File

@ -17,5 +17,5 @@ outputs:
runs: runs:
using: docker using: docker
image: Dockerfile image: Dockerfile
args: env:
- '${{ inputs.who-to-greet }}' INPUT_WHO_TO_GREET: ${{ inputs.who-to-greet }}

View File

@ -1,7 +1,7 @@
#!/bin/sh -l #!/bin/sh -l
# Use INPUT_<INPUT_NAME> to get the value of an input # Use INPUT_<INPUT_NAME> to get the value of an input
GREETING="Hello, $1!" GREETING="Hello, $INPUT_WHO_TO_GREET!"
# Use workflow commands to do things like set debug messages # Use workflow commands to do things like set debug messages
echo "::notice file=entrypoint.sh,line=7::$GREETING" echo "::notice file=entrypoint.sh,line=7::$GREETING"