From f92ceaee7782d919b31e987e5be9b773381b5ae4 Mon Sep 17 00:00:00 2001 From: Nick Alteen Date: Fri, 1 Sep 2023 14:09:02 -0400 Subject: [PATCH 01/14] Add gitignore for common files --- .gitignore | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dcff431 --- /dev/null +++ b/.gitignore @@ -0,0 +1,25 @@ +# Logs +logs +*.log + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# dotenv environment variables file +.env +.env.test + +# OS metadata +.DS_Store +Thumbs.db + +# IDE files +.idea +.vscode +*.code-workspace From e85dcb39f5b543e2c35bcb30bcf4ec123b17e633 Mon Sep 17 00:00:00 2001 From: Nick Alteen Date: Fri, 1 Sep 2023 14:09:14 -0400 Subject: [PATCH 02/14] Add prettier configuration --- .prettierrc.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .prettierrc.json diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..a378146 --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,16 @@ +{ + "printWidth": 80, + "tabWidth": 2, + "useTabs": false, + "semi": false, + "singleQuote": true, + "quoteProps": "as-needed", + "jsxSingleQuote": false, + "trailingComma": "none", + "bracketSpacing": true, + "bracketSameLine": true, + "arrowParens": "avoid", + "proseWrap": "always", + "htmlWhitespaceSensitivity": "css", + "endOfLine": "lf" +} From dd2f5f03b8c9249dc5144306a31f411c496bbf88 Mon Sep 17 00:00:00 2001 From: Nick Alteen Date: Fri, 1 Sep 2023 14:09:25 -0400 Subject: [PATCH 03/14] Format and update CODEOWNERS --- CODEOWNERS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CODEOWNERS b/CODEOWNERS index 992d27f..a9802d7 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1 +1,4 @@ +# Repository CODEOWNERS + * @actions/actions-runtime +* @ncalteen From fd8511c33bbfbb1650d09544a6965128547913fe Mon Sep 17 00:00:00 2001 From: Nick Alteen Date: Fri, 1 Sep 2023 14:10:18 -0400 Subject: [PATCH 04/14] Add output and logging to container --- Dockerfile | 12 ++++++++---- action.yml | 27 ++++++++++++++++++--------- entrypoint.sh | 11 ++++++++++- 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index af66730..6b92e63 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,11 @@ -FROM alpine:3.10 +# Set the base image to use for subsequent instructions +FROM alpine:3.18 -COPY LICENSE README.md / +# Set the working directory inside the container +WORKDIR /usr/src -COPY entrypoint.sh /entrypoint.sh +# Copy any source file(s) required for the action +COPY entrypoint.sh . -ENTRYPOINT ["/entrypoint.sh"] +# Configure the container to be run as an executable +ENTRYPOINT ["/usr/src/entrypoint.sh"] diff --git a/action.yml b/action.yml index 008f0a9..c9603b1 100644 --- a/action.yml +++ b/action.yml @@ -1,12 +1,21 @@ -name: 'Container Action Template' -description: 'Get started with Container actions' -author: 'GitHub' +name: 'The name of your action here' +description: 'Provide a description here' +author: 'Your name or organization here' + +# Define your inputs here. inputs: - myInput: - description: 'Input to use' - default: 'world' + who-to-greet: + description: 'Your input description here' + required: true + default: 'World' + +# Define your outputs here. +outputs: + greeting: + description: 'Your output description here' + runs: - using: 'docker' - image: 'Dockerfile' + using: docker + image: Dockerfile args: - - ${{ inputs.myInput }} + - ${{ inputs.who-to-greet }} diff --git a/entrypoint.sh b/entrypoint.sh index 3b8cd2d..22c9865 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,3 +1,12 @@ #!/bin/sh -l -echo "hello $1" +# Use INPUT_ to get the value of an input +GREETING="Hello, $INPUT_WHO_TO_GREET!" + +# Use workflow commands to do things like set debug messages +echo "::notice file=entrypoint.sh,line=7::$GREETING" + +# Write outputs to the $GITHUB_OUTPUT file +echo "greeting=$GREETING" >> "$GITHUB_OUTPUT" + +exit 0 From b8b108ea6989231c6aefa2dc285f925cc9c57502 Mon Sep 17 00:00:00 2001 From: Nick Alteen Date: Fri, 1 Sep 2023 14:10:27 -0400 Subject: [PATCH 05/14] Set up dependabot --- .github/dependabot.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..70cb209 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,17 @@ +version: 2 +updates: + - package-ecosystem: github-actions + directory: / + labels: + - dependabot + - actions + schedule: + interval: daily + + - package-ecosystem: docker + directory: / + labels: + - dependabot + - docker + schedule: + interval: daily From 46013876086153c3030809cc33b78a361bff7c3c Mon Sep 17 00:00:00 2001 From: Nick Alteen Date: Fri, 1 Sep 2023 14:10:47 -0400 Subject: [PATCH 06/14] Add super-linter --- .github/linters/.markdown-lint.yml | 7 +++++++ .github/linters/.yaml-lint.yml | 10 ++++++++++ .github/workflows/linter.yml | 31 ++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 .github/linters/.markdown-lint.yml create mode 100644 .github/linters/.yaml-lint.yml create mode 100644 .github/workflows/linter.yml diff --git a/.github/linters/.markdown-lint.yml b/.github/linters/.markdown-lint.yml new file mode 100644 index 0000000..6d79773 --- /dev/null +++ b/.github/linters/.markdown-lint.yml @@ -0,0 +1,7 @@ +# Unordered list style +MD004: + style: dash + +# Ordered list item prefix +MD029: + style: one diff --git a/.github/linters/.yaml-lint.yml b/.github/linters/.yaml-lint.yml new file mode 100644 index 0000000..c975a33 --- /dev/null +++ b/.github/linters/.yaml-lint.yml @@ -0,0 +1,10 @@ +rules: + document-end: disable + document-start: + level: warning + present: false + line-length: + level: warning + max: 80 + allow-non-breakable-words: true + allow-non-breakable-inline-mappings: true diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml new file mode 100644 index 0000000..997d085 --- /dev/null +++ b/.github/workflows/linter.yml @@ -0,0 +1,31 @@ +name: Lint Code Base + +on: + pull_request: + branches: + - main + push: + branches-ignore: + - main + +jobs: + lint: + name: Lint Code Base + runs-on: ubuntu-latest + + permissions: + contents: read + packages: read + statuses: write + + steps: + - name: Checkout + id: checkout + uses: actions/checkout@v3 + + - name: Lint Code Base + id: super-linter + uses: super-linter/super-linter/slim@v5 + env: + DEFAULT_BRANCH: main + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From ac219b2dcbf31f65a009c59493523db14549ebdb Mon Sep 17 00:00:00 2001 From: Nick Alteen Date: Fri, 1 Sep 2023 14:10:55 -0400 Subject: [PATCH 07/14] Add initial CI workflow --- .github/workflows/ci.yml | 71 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..e956946 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,71 @@ +name: Continuous Integration + +on: + pull_request: + push: + branches: + - main + - 'releases/*' + +jobs: + test-docker: + name: Docker Tests + runs-on: ubuntu-latest + + # Run a local registry to push to + services: + registry: + image: registry:2 + ports: + - 5001:5000 + + env: + TEST_TAG: localhost:5001/actions/container-action:latest + + steps: + - name: Checkout + id: checkout + uses: actions/checkout@v3 + + - name: Setup Docker BuildX + id: setup-buildx + uses: docker/setup-buildx-action@v2 + with: + install: true + driver-opts: network=host + + - name: Build the Container + id: build + uses: docker/build-push-action@v4 + with: + context: . + push: true + tags: ${{ env.TEST_TAG }} + + - name: Run the Container + id: run + env: + INPUT_WHO_TO_GREET: Mona Lisa Octocat + run: | + docker run \ + --env INPUT_WHO_TO_GREET="Mona Lisa Octocat" \ + --rm ${{ env.TEST_TAG }} + + test-action: + name: GitHub Actions Test + runs-on: ubuntu-latest + + steps: + - name: Checkout + id: checkout + uses: actions/checkout@v3 + + - name: Test Local Action + id: test-action + uses: ./ + with: + who-to-greet: Mona Lisa Octocat + + - name: Print Output + id: output + run: echo "${{ steps.test-action.outputs.greeting }}" From 137e75c6a61e1e9634134aa6661577c44513cc54 Mon Sep 17 00:00:00 2001 From: Nick Alteen Date: Fri, 1 Sep 2023 14:11:08 -0400 Subject: [PATCH 08/14] Add steps and detail to README --- README.md | 219 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 217 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 25842b5..642b755 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,220 @@ # Container Action Template -To get started, click the `Use this template` button on this repository [which will create a new repository based on this template](https://github.blog/2019-06-06-generate-new-repositories-with-repository-templates/). +[![GitHub Super-Linter](https://github.com/actions/container-action/actions/workflows/linter.yml/badge.svg)](https://github.com/super-linter/super-linter) +![CI](https://github.com/actions/container-action/actions/workflows/ci.yml/badge.svg) -For info on how to build your first Container action, see the [toolkit docs folder](https://github.com/actions/toolkit/blob/master/docs/container-action.md). +Use this template to bootstrap the creation of a container action. :rocket: + +This template includes compilation support, tests, a validation workflow, +publishing, and versioning guidance. + +If you are new, there's also a simpler introduction in the +[Hello World Docker Action](https://github.com/actions/hello-world-docker-action) +repository. + +If you would like to use the +[GitHub Actions Toolkit](https://github.com/actions/toolkit) in your container +action, see the +[Container Toolkit Action](https://github.com/actions/container-toolkit-action) +repository. + +## Create Your Own Action + +To create your own action, you can use this repository as a template! Just +follow the below instructions: + +1. Click the **Use this template** button at the top of the repository +1. Select **Create a new repository** +1. Select an owner and name for your new repository +1. Click **Create repository** +1. Clone your new repository + +## Initial Setup + +After you've cloned the repository to your local machine or codespace, you'll +need to perform some initial setup steps before you can develop your action. + +> [!NOTE] +> +> You'll need to have a reasonably modern version of +> [Docker](https://www.docker.com/get-started/) handy (e.g. docker engine +> version 20 or later). + +1. :hammer_and_wrench: Build the container + + Make sure to replace `actions/container-action` with an appropriate label for + your container. + + ```bash + docker build -t actions/container-action . + ``` + +1. :white_check_mark: Test the container + + You can pass individual environment variables using the `--env` or `-e` flag. + + ```bash + $ 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! + ``` + +## Update the Action Metadata + +The [`action.yml`](action.yml) file defines metadata about your action, such as +input(s) and output(s). For details about this file, see +[Metadata syntax for GitHub Actions](https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions). + +When you copy this repository, update `action.yml` with the name, description, +inputs, and outputs for your action. + +## Update the Action Code + +In this template, the container action runs a shell script, +[`entrypoint.sh`](./entrypoint.sh), when the container is launched. Since you +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 +container actions: + +- Inputs are accessed using environment variables with the format + `INPUT_`. For example, this action has an input called + `who-to-greet`, which can be accessed in the entrypoint script using + `INPUT_WHO_TO_GREET`. + + ```bash + GREETING="Hello, $INPUT_WHO_TO_GREET!" + ``` + +- GitHub Actions supports a number of different workflow commands such as + creating outputs, setting environment variables, and more. These are + accomplished by writing to different `GITHUB_*` environment variables. For + more information, see + [Workflow commands](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions). + + | Scenario | Example | + | --------------------- | ----------------------------------------------- | + | Set environment vars | `echo "MY_VAR=my-value" >> "$GITHUB_ENV"` | + | Set outputs | `echo "greeting=$GREETING" >> "$GITHUB_OUTPUT"` | + | Prepend to `PATH` | `echo "$HOME/.local/bin" >> "$GITHUB_PATH"` | + | Set `pre`/`post` vars | `echo "MY_VAR=my-value" >> "$GITHUB_STATE"` | + | Set step summary | `echo "{markdown}" >> "$GITHUB_STEP_SUMMARY"` | + + You can write multiline strings using the following syntax: + + ```bash + { + echo "JSON_RESPONSE<> "$GITHUB_ENV" + ``` + +- Make sure that the script being run is executable! + + ```bash + git add entrypoint.sh + git update-index --chmod=+x entrypoint.sh + ``` + +So, what are you waiting for? Go ahead and start customizing your action! + +1. Create a new branch + + ```bash + git checkout -b releases/v1 + ``` + +1. Replace the contents of `entrypoint.sh` with your action code +1. Build and test the container + + ```bash + docker build -t actions/container-action . + docker run --env INPUT_WHO_TO_GREET="Mona Lisa Octocat" actions/container-action + ``` + +1. Commit your changes + + ```bash + git add . + git commit -m "My first action is ready!" + ``` + +1. Push them to your repository + + ```bash + git push -u origin releases/v1 + ``` + +1. Create a pull request and get feedback on your action +1. Merge the pull request into the `main` branch + +Your action is now published! :rocket: + +For information about versioning your action, see +[Versioning](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md) +in the GitHub Actions toolkit. + +## Validate the Action + +You can now validate the action by referencing it in a workflow file. For +example, [`ci.yml`](./.github/workflows/ci.yml) demonstrates how to reference an +action in the same repository. + +```yaml +steps: + - name: Checkout + id: checkout + uses: actions/checkout@v3 + + - name: Test Local Action + id: test-action + uses: ./ + with: + who-to-greet: Mona Lisa Octocat + + - name: Print Output + id: output + run: echo "${{ steps.test-action.outputs.greeting }}" +``` + +For example workflow runs, check out the +[Actions tab](https://github.com/actions/container-action/actions)! :rocket: + +## Usage + +After testing, you can create version tag(s) that developers can use to +reference different stable versions of your action. For more information, see +[Versioning](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md) +in the GitHub Actions toolkit. + +To include the action in a workflow in another repository, you can use the +`uses` syntax with the `@` symbol to reference a specific branch, tag, or commit +hash. + +```yaml +steps: + - name: Checkout + id: checkout + uses: actions/checkout@v3 + + - name: Test Local Action + id: test-action + uses: actions/container-action@v1 # Commit with the `v1` tag + with: + who-to-greet: Mona Lisa Octocat + + - name: Print Output + id: output + run: echo "${{ steps.test-action.outputs.greeting }}" +``` From e3750df6193f043d2a2395952e5de9190a0827a5 Mon Sep 17 00:00:00 2001 From: Nick Alteen Date: Fri, 1 Sep 2023 14:18:59 -0400 Subject: [PATCH 09/14] Correct input name --- .github/workflows/ci.yml | 4 ++-- README.md | 10 +++++----- entrypoint.sh | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e956946..a5cb308 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,10 +45,10 @@ jobs: - name: Run the Container id: run env: - INPUT_WHO_TO_GREET: Mona Lisa Octocat + INPUT_WHO-TO-GREET: Mona Lisa Octocat run: | docker run \ - --env INPUT_WHO_TO_GREET="Mona Lisa Octocat" \ + --env INPUT_WHO-TO-GREET="Mona Lisa Octocat" \ --rm ${{ env.TEST_TAG }} test-action: diff --git a/README.md b/README.md index 642b755..7a54870 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ need to perform some initial setup steps before you can develop your action. You can pass individual environment variables using the `--env` or `-e` flag. ```bash - $ docker run --env INPUT_WHO_TO_GREET="Mona Lisa Octocat" actions/container-action + $ docker run --env INPUT_WHO-TO-GREET="Mona Lisa Octocat" actions/container-action ::notice file=entrypoint.sh,line=7::Hello, Mona Lisa Octocat! ``` @@ -63,7 +63,7 @@ need to perform some initial setup steps before you can develop your action. ```bash $ cat ./.env.test - INPUT_WHO_TO_GREET="Mona Lisa Octocat" + INPUT_WHO-TO-GREET="Mona Lisa Octocat" $ docker run --env-file ./.env.test actions/container-action @@ -90,10 +90,10 @@ container actions: - Inputs are accessed using environment variables with the format `INPUT_`. For example, this action has an input called `who-to-greet`, which can be accessed in the entrypoint script using - `INPUT_WHO_TO_GREET`. + `INPUT_WHO-TO-GREET`. ```bash - GREETING="Hello, $INPUT_WHO_TO_GREET!" + GREETING="Hello, $INPUT_WHO-TO-GREET!" ``` - GitHub Actions supports a number of different workflow commands such as @@ -140,7 +140,7 @@ So, what are you waiting for? Go ahead and start customizing your action! ```bash docker build -t actions/container-action . - docker run --env INPUT_WHO_TO_GREET="Mona Lisa Octocat" actions/container-action + docker run --env INPUT_WHO-TO-GREET="Mona Lisa Octocat" actions/container-action ``` 1. Commit your changes diff --git a/entrypoint.sh b/entrypoint.sh index 22c9865..381820b 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,7 +1,7 @@ #!/bin/sh -l # Use INPUT_ to get the value of an input -GREETING="Hello, $INPUT_WHO_TO_GREET!" +GREETING="Hello, $INPUT_WHO-TO-GREET!" # Use workflow commands to do things like set debug messages echo "::notice file=entrypoint.sh,line=7::$GREETING" From f67457a744f0ca39a74ab1e08ae0ed18e874899b Mon Sep 17 00:00:00 2001 From: Nick Alteen Date: Fri, 1 Sep 2023 14:36:35 -0400 Subject: [PATCH 10/14] Replace named arg --- .github/workflows/ci.yml | 4 ++-- README.md | 26 +++++++------------------- entrypoint.sh | 2 +- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e956946..cec91b3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,8 +48,8 @@ jobs: INPUT_WHO_TO_GREET: Mona Lisa Octocat run: | docker run \ - --env INPUT_WHO_TO_GREET="Mona Lisa Octocat" \ - --rm ${{ env.TEST_TAG }} + --rm ${{ env.TEST_TAG }} \ + ${{ env.INPUT_WHO_TO_GREET }} test-action: name: GitHub Actions Test diff --git a/README.md b/README.md index 642b755..adb15fb 100644 --- a/README.md +++ b/README.md @@ -51,21 +51,10 @@ need to perform some initial setup steps before you can develop your action. 1. :white_check_mark: Test the container - You can pass individual environment variables using the `--env` or `-e` flag. + You can pass input arguments in the `docker run` call. ```bash - $ 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 + $ docker run actions/container-action "Mona Lisa Octocat" ::notice file=entrypoint.sh,line=7::Hello, Mona Lisa Octocat! ``` @@ -87,13 +76,12 @@ 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 container actions: -- Inputs are accessed using environment variables with the format - `INPUT_`. For example, this action has an input called - `who-to-greet`, which can be accessed in the entrypoint script using - `INPUT_WHO_TO_GREET`. +- Inputs are accessed using argument identifiers. For example, the first input + to this action, `who-to-greet`, can be accessed in the entrypoint script using + `$1`. ```bash - GREETING="Hello, $INPUT_WHO_TO_GREET!" + GREETING="Hello, $1!" ``` - GitHub Actions supports a number of different workflow commands such as @@ -140,7 +128,7 @@ So, what are you waiting for? Go ahead and start customizing your action! ```bash docker build -t actions/container-action . - docker run --env INPUT_WHO_TO_GREET="Mona Lisa Octocat" actions/container-action + docker run actions/container-action "Mona Lisa Octocat" ``` 1. Commit your changes diff --git a/entrypoint.sh b/entrypoint.sh index 22c9865..42e39ea 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,7 +1,7 @@ #!/bin/sh -l # Use INPUT_ to get the value of an input -GREETING="Hello, $INPUT_WHO_TO_GREET!" +GREETING="Hello, $1!" # Use workflow commands to do things like set debug messages echo "::notice file=entrypoint.sh,line=7::$GREETING" From db66df907be027b4284bf65fe4869fbee957c369 Mon Sep 17 00:00:00 2001 From: Nick Alteen Date: Fri, 1 Sep 2023 14:41:15 -0400 Subject: [PATCH 11/14] Quote input arg --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index c9603b1..3cbcd3d 100644 --- a/action.yml +++ b/action.yml @@ -18,4 +18,4 @@ runs: using: docker image: Dockerfile args: - - ${{ inputs.who-to-greet }} + - '${{ inputs.who-to-greet }}' From 11b982c2534d8b69793755be7599c98790625c9f Mon Sep 17 00:00:00 2001 From: Nick Alteen Date: Fri, 1 Sep 2023 14:47:27 -0400 Subject: [PATCH 12/14] Switch to env var for input --- .github/workflows/ci.yml | 4 ++-- README.md | 20 +++++++++++++++----- action.yml | 4 ++-- entrypoint.sh | 2 +- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cec91b3..4a4950e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,8 +48,8 @@ jobs: INPUT_WHO_TO_GREET: Mona Lisa Octocat 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: name: GitHub Actions Test diff --git a/README.md b/README.md index adb15fb..a8b8b90 100644 --- a/README.md +++ b/README.md @@ -51,11 +51,20 @@ need to perform some initial setup steps before you can develop your action. 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 - $ 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! ``` @@ -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 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 - `$1`. + the `$INPUT_WHO_TO_GREET` environment variable. ```bash - GREETING="Hello, $1!" + GREETING="Hello, $INPUT_WHO_TO_GREET!" ``` - GitHub Actions supports a number of different workflow commands such as diff --git a/action.yml b/action.yml index 3cbcd3d..6a12f41 100644 --- a/action.yml +++ b/action.yml @@ -17,5 +17,5 @@ outputs: runs: using: docker image: Dockerfile - args: - - '${{ inputs.who-to-greet }}' + env: + INPUT_WHO_TO_GREET: ${{ inputs.who-to-greet }} diff --git a/entrypoint.sh b/entrypoint.sh index 42e39ea..22c9865 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,7 +1,7 @@ #!/bin/sh -l # Use INPUT_ 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 echo "::notice file=entrypoint.sh,line=7::$GREETING" From ee3fad0374784fe0304da29b5c635c465497b918 Mon Sep 17 00:00:00 2001 From: Nick Alteen Date: Fri, 1 Sep 2023 14:48:47 -0400 Subject: [PATCH 13/14] Update linter triggers --- .github/workflows/linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 997d085..d52f232 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -5,7 +5,7 @@ on: branches: - main push: - branches-ignore: + branches: - main jobs: From 7986406bd86edf43950df0bc32dc703527c3db22 Mon Sep 17 00:00:00 2001 From: Nick Alteen Date: Fri, 1 Sep 2023 14:49:09 -0400 Subject: [PATCH 14/14] Update CI triggers --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4a4950e..3de6711 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,10 +2,11 @@ name: Continuous Integration on: pull_request: + branches: + - main push: branches: - main - - 'releases/*' jobs: test-docker: