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 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/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..f5e03a6 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,72 @@ +name: Continuous Integration + +on: + pull_request: + branches: + - main + push: + branches-ignore: + - main + +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/hello-world-docer-action:latest + + steps: + - name: Checkout + id: checkout + uses: actions/checkout@v4 + + - name: Setup Docker BuildX + id: setup-buildx + uses: docker/setup-buildx-action@v3 + with: + install: true + driver-opts: network=host + + - name: Build the Container + id: build + uses: docker/build-push-action@v5 + 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="${{ env.INPUT_WHO_TO_GREET }}" \ + --rm ${{ env.TEST_TAG }} + + test-action: + name: GitHub Actions Test + runs-on: ubuntu-latest + + steps: + - name: Checkout + id: checkout + uses: actions/checkout@v4 + + - 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.time }}" diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml new file mode 100644 index 0000000..6a46ad7 --- /dev/null +++ b/.github/workflows/linter.yml @@ -0,0 +1,31 @@ +name: Lint Code Base + +on: + pull_request: + branches: + - main + push: + branches: + - 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@v4 + + - name: Lint Code Base + id: super-linter + uses: super-linter/super-linter/slim@v5 + env: + DEFAULT_BRANCH: main + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 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 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" +} diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..a9802d7 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1,4 @@ +# Repository CODEOWNERS + +* @actions/actions-runtime +* @ncalteen diff --git a/Dockerfile b/Dockerfile index fa0188a..6b92e63 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,11 @@ -# Container image that runs your code -FROM alpine:3.10 +# Set the base image to use for subsequent instructions +FROM alpine:3.18 -# Copies your code file from your action repository to the filesystem path `/` of the container -COPY entrypoint.sh /entrypoint.sh +# Set the working directory inside the container +WORKDIR /usr/src -# Code file to execute when the docker container starts up (`entrypoint.sh`) -ENTRYPOINT ["/entrypoint.sh"] +# Copy any source file(s) required for the action +COPY entrypoint.sh . + +# Configure the container to be run as an executable +ENTRYPOINT ["/usr/src/entrypoint.sh"] diff --git a/LICENSE b/LICENSE index de88db8..a67dca8 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ -MIT License -Copyright (c) 2019 GitHub Actions +The MIT License (MIT) + +Copyright (c) 2018 GitHub, Inc. and contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -9,13 +10,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md index 70f4ce9..ead5d62 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,94 @@ -# Hello world docker action +# Hello, World! Docker Action -This action prints "Hello World" to the log or "Hello" + the name of a person to greet. To learn how this action was built, see "[Creating a Docker container action](https://docs.github.com/en/actions/creating-actions/creating-a-docker-container-action)" in the GitHub Docs. +[![GitHub Super-Linter](https://github.com/actions/hello-world-docker-action/actions/workflows/linter.yml/badge.svg)](https://github.com/super-linter/super-linter) +![CI](https://github.com/actions/hello-world-docker-action/actions/workflows/ci.yml/badge.svg) + +This action prints `Hello, World!` or `Hello, !` to the log. To +learn how this action was built, see +[Creating a Docker container action](https://docs.github.com/en/actions/creating-actions/creating-a-docker-container-action). + +## Usage + +Here's an example of how to use this action in a workflow file: + +```yaml +name: Example Workflow + +on: + workflow_dispatch: + inputs: + who-to-greet: + description: Who to greet in the log + required: true + default: 'World' + type: string + +jobs: + say-hello: + name: Say Hello + runs-on: ubuntu-latest + + steps: + # Change @main to a specific commit SHA or version tag, e.g.: + # actions/hello-world-docker-action@e76147da8e5c81eaf017dede5645551d4b94427b + # actions/hello-world-docker-action@v1.2.3 + - name: Print to Log + id: print-to-log + uses: actions/hello-world-docker-action@main + with: + who-to-greet: ${{ inputs.who-to-greet }} +``` + +For example workflow runs, check out the +[Actions tab](https://github.com/actions/hello-world-docker-action/actions)! +:rocket: ## Inputs -### `who-to-greet` - -**Required** The name of the person to greet. Default `"World"`. +| Input | Default | Description | +| -------------- | ------- | ------------------------------- | +| `who-to-greet` | `World` | The name of the person to greet | ## Outputs -### `time` +| Output | Description | +| ------ | ----------------------- | +| `time` | The time we greeted you | -The time we greeted you. +## Test Locally -## Example usage +After you've cloned the repository to your local machine or codespace, you'll +need to perform some initial setup steps before you can test your action. -```yaml -uses: actions/hello-world-docker-action@main -with: - who-to-greet: 'Mona the Octocat' -``` +> [!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/hello-world-docker-action` with an appropriate + label for your container. + + ```bash + docker build -t actions/hello-world-docker-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/hello-world-docker-action + ::notice file=entrypoint.sh,line=7::Hello, Mona Lisa Octocat! + ``` + + Or you can pass a file with environment variables using `--env-file`. + + ```bash + $ echo "INPUT_WHO_TO_GREET=\"Mona Lisa Octocat\"" > ./.env.test + + $ docker run --env-file ./.env.test actions/hello-world-docker-action + ::notice file=entrypoint.sh,line=7::Hello, Mona Lisa Octocat! + ``` diff --git a/action.yml b/action.yml index 9b136f8..f85ef94 100644 --- a/action.yml +++ b/action.yml @@ -1,15 +1,21 @@ -name: 'Hello World' -description: 'Greet someone and record the time' +name: Hello, World! +description: Greet someone and record the time +author: GitHub Actions + +# Define your inputs here. inputs: - who-to-greet: # id of input - description: 'Who to greet' + who-to-greet: + description: Who to greet required: true - default: 'World' + default: World + +# Define your outputs here. outputs: - time: # id of output - description: 'The time we greeted you' + time: + description: The time we greeted you + runs: - using: 'docker' - image: 'Dockerfile' - args: - - ${{ inputs.who-to-greet }} + using: docker + image: Dockerfile + env: + INPUT_WHO_TO_GREET: ${{ inputs.who-to-greet }} diff --git a/entrypoint.sh b/entrypoint.sh index 3fee027..22c9865 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,5 +1,12 @@ #!/bin/sh -l -echo "Hello $1" -time=$(date) -echo "time=$time" >> $GITHUB_OUTPUT +# 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