diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 18c132e5..0dc0a642 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,11 +2,11 @@ ## Setup local environment -* [Install Docker](https://docs.docker.com/get-docker/) +* Install bash 4 or later, curl, jq and python3 ## Running the tests -The tests run the action's Docker image against a mock Teamwork API (`tests/mock-teamwork.py`) and check what it sends: +The tests run the action against a mock Teamwork API (`tests/mock-teamwork.py`) and check what it sends: ``` ./tests/run.sh diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 6eaa2ae4..00000000 --- a/Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -FROM alpine:3.24 - -RUN apk add --no-cache bash curl jq - -ADD entrypoint.sh /entrypoint.sh -ADD src /src - -ENTRYPOINT ["/entrypoint.sh"] diff --git a/README.md b/README.md index e7e3553e..a4339553 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,8 @@ Create the next environment vars in your repository: **Please Note:** The Teamwork account associated with this API key is the account which these comments will be created under. If this user does not have permission to access a task's project, that task will be skipped and the workflow run will be marked as failed. ### Installation +The action runs on any runner with bash 4 or later, curl and jq. GitHub-hosted Ubuntu runners have them. + Create a new file `/.github/workflows/teamwork.yml` with the following: ```yaml diff --git a/action.yml b/action.yml index 0c27db6c..4d760a04 100644 --- a/action.yml +++ b/action.yml @@ -46,20 +46,18 @@ inputs: required: false default: '' runs: - using: 'docker' - image: 'Dockerfile' - # Secrets stay out of args, which show up in the runner's process list. The - # Teamwork token is read from its INPUT_TEAMWORK_API_TOKEN env var instead, - # and the empty slots keep the other args in place. - args: - - '' - - ${{ inputs.TEAMWORK_URI }} - - '' - - ${{ inputs.AUTOMATIC_TAGGING }} - - ${{ inputs.WORKFLOW_STAGE_OPENED }} - - ${{ inputs.WORKFLOW_STAGE_MERGED }} - - ${{ inputs.WORKFLOW_STAGE_CLOSED }} - - ${{ inputs.LIGHTWEIGHT_COMMENT }} - - ${{ inputs.BOARD_COLUMN_OPENED }} - - ${{ inputs.BOARD_COLUMN_MERGED }} - - ${{ inputs.BOARD_COLUMN_CLOSED }} + using: 'composite' + steps: + - shell: bash + run: bash "$GITHUB_ACTION_PATH/entrypoint.sh" + env: + INPUT_TEAMWORK_URI: ${{ inputs.TEAMWORK_URI }} + INPUT_TEAMWORK_API_TOKEN: ${{ inputs.TEAMWORK_API_TOKEN }} + INPUT_AUTOMATIC_TAGGING: ${{ inputs.AUTOMATIC_TAGGING }} + INPUT_WORKFLOW_STAGE_OPENED: ${{ inputs.WORKFLOW_STAGE_OPENED }} + INPUT_WORKFLOW_STAGE_MERGED: ${{ inputs.WORKFLOW_STAGE_MERGED }} + INPUT_WORKFLOW_STAGE_CLOSED: ${{ inputs.WORKFLOW_STAGE_CLOSED }} + INPUT_LIGHTWEIGHT_COMMENT: ${{ inputs.LIGHTWEIGHT_COMMENT }} + INPUT_BOARD_COLUMN_OPENED: ${{ inputs.BOARD_COLUMN_OPENED }} + INPUT_BOARD_COLUMN_MERGED: ${{ inputs.BOARD_COLUMN_MERGED }} + INPUT_BOARD_COLUMN_CLOSED: ${{ inputs.BOARD_COLUMN_CLOSED }} diff --git a/entrypoint.sh b/entrypoint.sh index 9b3edd58..c8883be6 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -3,15 +3,11 @@ set -euo pipefail PROJECT_HOME="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" -if [ "$PROJECT_HOME" == "/" ]; then - PROJECT_HOME="" -fi - export PROJECT_HOME # shellcheck disable=SC1090 source "$PROJECT_HOME/src/main.sh" -main "$@" +main exit $? diff --git a/src/ensure.sh b/src/ensure.sh index 3bec16a0..4f14f122 100644 --- a/src/ensure.sh +++ b/src/ensure.sh @@ -6,3 +6,10 @@ ensure::env_variable_exist() { exit 1 fi } + +ensure::command_exist() { + if ! command -v "$1" >/dev/null 2>&1; then + log::error "The command $1 is required. Install it on the runner." + exit 1 + fi +} diff --git a/src/github.sh b/src/github.sh index b3932a08..76f26fa6 100644 --- a/src/github.sh +++ b/src/github.sh @@ -10,7 +10,7 @@ github::get_action() { github::get_pr_body() { jq --raw-output .pull_request.body "$GITHUB_EVENT_PATH" |\ - awk '/^[[:space:]]*(```|~~~)/ { fenced = !fenced } !fenced { sub(/^#{1,3} /, "#### ") } { print }' + awk '/^[[:space:]]*(```|~~~)/ { fenced = !fenced } !fenced { sub(/^##?#? /, "#### ") } { print }' } github::get_head_ref() { @@ -26,7 +26,7 @@ github::get_pr_url() { } github::get_pr_title() { - jq --raw-output '.pull_request.title | trim' "$GITHUB_EVENT_PATH" + jq --raw-output '.pull_request.title | sub("^\\s+"; "") | sub("\\s+$"; "")' "$GITHUB_EVENT_PATH" } github::get_pr_patch_stats() { diff --git a/src/main.sh b/src/main.sh index 0cc5af6f..3d66786b 100644 --- a/src/main.sh +++ b/src/main.sh @@ -9,25 +9,25 @@ source "$PROJECT_HOME/src/teamwork.sh" main() { log::message "Running the process..." - # Ensure env vars and args exist + # Ensure env vars and tools exist ensure::env_variable_exist "GITHUB_REPOSITORY" ensure::env_variable_exist "GITHUB_EVENT_PATH" ensure::env_variable_exist "GITHUB_EVENT_NAME" - # $1 used to be GITHUB_TOKEN, which was never needed. The Teamwork token comes - # from the env var GitHub creates for the input, so it isn't on the command - # line; $3 is the fallback for running the image by hand. - export TEAMWORK_URI="$2" - export TEAMWORK_API_TOKEN="${INPUT_TEAMWORK_API_TOKEN:-$3}" - export AUTOMATIC_TAGGING="$4" - export WORKFLOW_STAGE_OPENED="$5" - export WORKFLOW_STAGE_MERGED="$6" - export WORKFLOW_STAGE_CLOSED="$7" - export LIGHTWEIGHT_COMMENT="$8" + ensure::command_exist "curl" + ensure::command_exist "jq" + + export TEAMWORK_URI="${INPUT_TEAMWORK_URI:-}" + export TEAMWORK_API_TOKEN="${INPUT_TEAMWORK_API_TOKEN:-}" + export AUTOMATIC_TAGGING="${INPUT_AUTOMATIC_TAGGING:-}" + export WORKFLOW_STAGE_OPENED="${INPUT_WORKFLOW_STAGE_OPENED:-}" + export WORKFLOW_STAGE_MERGED="${INPUT_WORKFLOW_STAGE_MERGED:-}" + export WORKFLOW_STAGE_CLOSED="${INPUT_WORKFLOW_STAGE_CLOSED:-}" + export LIGHTWEIGHT_COMMENT="${INPUT_LIGHTWEIGHT_COMMENT:-}" # BOARD_COLUMN_* are deprecated aliases kept for backwards compatibility. - export BOARD_COLUMN_OPENED="${9:-}" - export BOARD_COLUMN_MERGED="${10:-}" - export BOARD_COLUMN_CLOSED="${11:-}" + export BOARD_COLUMN_OPENED="${INPUT_BOARD_COLUMN_OPENED:-}" + export BOARD_COLUMN_MERGED="${INPUT_BOARD_COLUMN_MERGED:-}" + export BOARD_COLUMN_CLOSED="${INPUT_BOARD_COLUMN_CLOSED:-}" # Fall back to the deprecated BOARD_COLUMN_* inputs when their WORKFLOW_STAGE_* # replacements are not set. diff --git a/tests/cases/bearer-token/event.json b/tests/cases/bearer-token/event.json index 5f80ac3b..581268f0 100644 --- a/tests/cases/bearer-token/event.json +++ b/tests/cases/bearer-token/event.json @@ -4,7 +4,7 @@ "pull_request": { "number": 42, "title": "Add OAuth login", - "body": "Task: http://teamwork:8080/app/tasks/1001", + "body": "Task: http://localhost:8080/app/tasks/1001", "html_url": "https://github.com/acme/webapp/pull/42", "head": { "ref": "feature/oauth", diff --git a/tests/cases/closed-merged-lightweight/event.json b/tests/cases/closed-merged-lightweight/event.json index 97732713..97858fd0 100644 --- a/tests/cases/closed-merged-lightweight/event.json +++ b/tests/cases/closed-merged-lightweight/event.json @@ -4,7 +4,7 @@ "pull_request": { "number": 42, "title": "Add OAuth login", - "body": "Task: http://teamwork:8080/app/tasks/1001", + "body": "Task: http://localhost:8080/app/tasks/1001", "html_url": "https://github.com/acme/webapp/pull/42", "head": { "ref": "feature/oauth", diff --git a/tests/cases/closed-merged/event.json b/tests/cases/closed-merged/event.json index 97732713..97858fd0 100644 --- a/tests/cases/closed-merged/event.json +++ b/tests/cases/closed-merged/event.json @@ -4,7 +4,7 @@ "pull_request": { "number": 42, "title": "Add OAuth login", - "body": "Task: http://teamwork:8080/app/tasks/1001", + "body": "Task: http://localhost:8080/app/tasks/1001", "html_url": "https://github.com/acme/webapp/pull/42", "head": { "ref": "feature/oauth", diff --git a/tests/cases/closed-unmerged-lightweight/event.json b/tests/cases/closed-unmerged-lightweight/event.json index 09ccdcd9..6537de4e 100644 --- a/tests/cases/closed-unmerged-lightweight/event.json +++ b/tests/cases/closed-unmerged-lightweight/event.json @@ -4,7 +4,7 @@ "pull_request": { "number": 42, "title": "Add OAuth login", - "body": "Task: http://teamwork:8080/app/tasks/1001", + "body": "Task: http://localhost:8080/app/tasks/1001", "html_url": "https://github.com/acme/webapp/pull/42", "head": { "ref": "feature/oauth", diff --git a/tests/cases/closed-unmerged/event.json b/tests/cases/closed-unmerged/event.json index 09ccdcd9..6537de4e 100644 --- a/tests/cases/closed-unmerged/event.json +++ b/tests/cases/closed-unmerged/event.json @@ -4,7 +4,7 @@ "pull_request": { "number": 42, "title": "Add OAuth login", - "body": "Task: http://teamwork:8080/app/tasks/1001", + "body": "Task: http://localhost:8080/app/tasks/1001", "html_url": "https://github.com/acme/webapp/pull/42", "head": { "ref": "feature/oauth", diff --git a/tests/cases/comment-fails/event.json b/tests/cases/comment-fails/event.json index dd7b97e2..a3217d4c 100644 --- a/tests/cases/comment-fails/event.json +++ b/tests/cases/comment-fails/event.json @@ -4,7 +4,7 @@ "pull_request": { "number": 42, "title": "Add OAuth login", - "body": "Task: http://teamwork:8080/app/tasks/1003", + "body": "Task: http://localhost:8080/app/tasks/1003", "html_url": "https://github.com/acme/webapp/pull/42", "head": { "ref": "feature/oauth", diff --git a/tests/cases/deprecated-board-column-closed/event.json b/tests/cases/deprecated-board-column-closed/event.json index 09ccdcd9..6537de4e 100644 --- a/tests/cases/deprecated-board-column-closed/event.json +++ b/tests/cases/deprecated-board-column-closed/event.json @@ -4,7 +4,7 @@ "pull_request": { "number": 42, "title": "Add OAuth login", - "body": "Task: http://teamwork:8080/app/tasks/1001", + "body": "Task: http://localhost:8080/app/tasks/1001", "html_url": "https://github.com/acme/webapp/pull/42", "head": { "ref": "feature/oauth", diff --git a/tests/cases/deprecated-board-column/event.json b/tests/cases/deprecated-board-column/event.json index 5f80ac3b..581268f0 100644 --- a/tests/cases/deprecated-board-column/event.json +++ b/tests/cases/deprecated-board-column/event.json @@ -4,7 +4,7 @@ "pull_request": { "number": 42, "title": "Add OAuth login", - "body": "Task: http://teamwork:8080/app/tasks/1001", + "body": "Task: http://localhost:8080/app/tasks/1001", "html_url": "https://github.com/acme/webapp/pull/42", "head": { "ref": "feature/oauth", diff --git a/tests/cases/ignored-project/event.json b/tests/cases/ignored-project/event.json index a68d412c..6537e020 100644 --- a/tests/cases/ignored-project/event.json +++ b/tests/cases/ignored-project/event.json @@ -4,7 +4,7 @@ "pull_request": { "number": 42, "title": "Add OAuth login", - "body": "Tasks: http://teamwork:8080/app/tasks/1001 and http://teamwork:8080/app/tasks/1002", + "body": "Tasks: http://localhost:8080/app/tasks/1001 and http://localhost:8080/app/tasks/1002", "html_url": "https://github.com/acme/webapp/pull/42", "head": { "ref": "feature/oauth", diff --git a/tests/cases/opened-lightweight/event.json b/tests/cases/opened-lightweight/event.json index d524f93d..818b4a30 100644 --- a/tests/cases/opened-lightweight/event.json +++ b/tests/cases/opened-lightweight/event.json @@ -4,7 +4,7 @@ "pull_request": { "number": 42, "title": "Handle \"null\" in C:\\temp", - "body": "Task: http://teamwork:8080/app/tasks/1001", + "body": "Task: http://localhost:8080/app/tasks/1001", "html_url": "https://github.com/acme/webapp/pull/42", "head": { "ref": "feature/oauth", diff --git a/tests/cases/opened/event.json b/tests/cases/opened/event.json index f3579555..1874bb16 100644 --- a/tests/cases/opened/event.json +++ b/tests/cases/opened/event.json @@ -4,7 +4,7 @@ "pull_request": { "number": 42, "title": "Add \"OAuth\" login", - "body": "## Summary\r\nAdds OAuth login for http://teamwork:8080/app/tasks/1001\r\n\r\n```sh\r\n# configure the \"client\" secret\r\nexport CONFIG_DIR=C:\\Users\\dev\\config\r\n```", + "body": "## Summary\r\nAdds OAuth login for http://localhost:8080/app/tasks/1001\r\n\r\n```sh\r\n# configure the \"client\" secret\r\nexport CONFIG_DIR=C:\\Users\\dev\\config\r\n```", "html_url": "https://github.com/acme/webapp/pull/42", "head": { "ref": "feature/oauth", diff --git a/tests/cases/opened/expected b/tests/cases/opened/expected index 319ba31d..ec8c9afe 100644 --- a/tests/cases/opened/expected +++ b/tests/cases/opened/expected @@ -13,7 +13,7 @@ POST /tasks/1001/comments.json -> 201 | --- | | #### Summary␍ - | Adds OAuth login for http://teamwork:8080/app/tasks/1001␍ + | Adds OAuth login for http://localhost:8080/app/tasks/1001␍ | ␍ | ```sh␍ | # configure the "client" secret␍ diff --git a/tests/cases/review-approved-lightweight/event.json b/tests/cases/review-approved-lightweight/event.json index 48e8f8f7..4e9a0f42 100644 --- a/tests/cases/review-approved-lightweight/event.json +++ b/tests/cases/review-approved-lightweight/event.json @@ -4,7 +4,7 @@ "pull_request": { "number": 42, "title": "Add OAuth login", - "body": "Task: http://teamwork:8080/app/tasks/1001", + "body": "Task: http://localhost:8080/app/tasks/1001", "html_url": "https://github.com/acme/webapp/pull/42", "head": { "ref": "feature/oauth", diff --git a/tests/cases/review-approved-no-body/event.json b/tests/cases/review-approved-no-body/event.json index ef9793c8..129b5865 100644 --- a/tests/cases/review-approved-no-body/event.json +++ b/tests/cases/review-approved-no-body/event.json @@ -4,7 +4,7 @@ "pull_request": { "number": 42, "title": "Add OAuth login", - "body": "Task: http://teamwork:8080/app/tasks/1001", + "body": "Task: http://localhost:8080/app/tasks/1001", "html_url": "https://github.com/acme/webapp/pull/42", "head": { "ref": "feature/oauth", diff --git a/tests/cases/review-approved/event.json b/tests/cases/review-approved/event.json index 3e77ae9d..35077f74 100644 --- a/tests/cases/review-approved/event.json +++ b/tests/cases/review-approved/event.json @@ -4,7 +4,7 @@ "pull_request": { "number": 42, "title": "Add OAuth login", - "body": "Task: http://teamwork:8080/app/tasks/1001", + "body": "Task: http://localhost:8080/app/tasks/1001", "html_url": "https://github.com/acme/webapp/pull/42", "head": { "ref": "feature/oauth", diff --git a/tests/cases/review-commented/event.json b/tests/cases/review-commented/event.json index aa67d482..92139088 100644 --- a/tests/cases/review-commented/event.json +++ b/tests/cases/review-commented/event.json @@ -4,7 +4,7 @@ "pull_request": { "number": 42, "title": "Add OAuth login", - "body": "Task: http://teamwork:8080/app/tasks/1001", + "body": "Task: http://localhost:8080/app/tasks/1001", "html_url": "https://github.com/acme/webapp/pull/42", "head": { "ref": "feature/oauth", diff --git a/tests/cases/review-dismissed/event.json b/tests/cases/review-dismissed/event.json index 3ad66cf5..31653287 100644 --- a/tests/cases/review-dismissed/event.json +++ b/tests/cases/review-dismissed/event.json @@ -4,7 +4,7 @@ "pull_request": { "number": 42, "title": "Add OAuth login", - "body": "Task: http://teamwork:8080/app/tasks/1001", + "body": "Task: http://localhost:8080/app/tasks/1001", "html_url": "https://github.com/acme/webapp/pull/42", "head": { "ref": "feature/oauth", diff --git a/tests/cases/stage-not-found/event.json b/tests/cases/stage-not-found/event.json index 5f80ac3b..581268f0 100644 --- a/tests/cases/stage-not-found/event.json +++ b/tests/cases/stage-not-found/event.json @@ -4,7 +4,7 @@ "pull_request": { "number": 42, "title": "Add OAuth login", - "body": "Task: http://teamwork:8080/app/tasks/1001", + "body": "Task: http://localhost:8080/app/tasks/1001", "html_url": "https://github.com/acme/webapp/pull/42", "head": { "ref": "feature/oauth", diff --git a/tests/cases/tagging-disabled/event.json b/tests/cases/tagging-disabled/event.json index 97732713..97858fd0 100644 --- a/tests/cases/tagging-disabled/event.json +++ b/tests/cases/tagging-disabled/event.json @@ -4,7 +4,7 @@ "pull_request": { "number": 42, "title": "Add OAuth login", - "body": "Task: http://teamwork:8080/app/tasks/1001", + "body": "Task: http://localhost:8080/app/tasks/1001", "html_url": "https://github.com/acme/webapp/pull/42", "head": { "ref": "feature/oauth", diff --git a/tests/cases/task-links/event.json b/tests/cases/task-links/event.json index 94875ab9..a701e0d0 100644 --- a/tests/cases/task-links/event.json +++ b/tests/cases/task-links/event.json @@ -4,7 +4,7 @@ "pull_request": { "number": 42, "title": "Add OAuth login", - "body": "Linked twice: [http://teamwork:8080/app/tasks/1001](http://teamwork:8080/app/tasks/1001)\nUpper case, old route: HTTP://TEAMWORK:8080/#/tasks/1002\nAgain: http://teamwork:8080/#tasks/1001\nNot task links: subtasks/5, https://github.com/acme/webapp/blob/main/scripts/tasks/2024_cleanup.py\nAnother Teamwork site: https://acme.teamwork.com/app/tasks/1003\nLook-alike host: http://evil-teamwork:8080/app/tasks/1003", + "body": "Linked twice: [http://localhost:8080/app/tasks/1001](http://localhost:8080/app/tasks/1001)\nUpper case, old route: HTTP://LOCALHOST:8080/#/tasks/1002\nAgain: http://localhost:8080/#tasks/1001\nNot task links: subtasks/5, https://github.com/acme/webapp/blob/main/scripts/tasks/2024_cleanup.py\nAnother Teamwork site: https://acme.teamwork.com/app/tasks/1003\nLook-alike host: http://evil-localhost:8080/app/tasks/1003", "html_url": "https://github.com/acme/webapp/pull/42", "head": { "ref": "feature/oauth", diff --git a/tests/cases/task-not-found/event.json b/tests/cases/task-not-found/event.json index c9ba3a23..641213ca 100644 --- a/tests/cases/task-not-found/event.json +++ b/tests/cases/task-not-found/event.json @@ -4,7 +4,7 @@ "pull_request": { "number": 42, "title": "Add OAuth login", - "body": "Tasks: http://teamwork:8080/app/tasks/9999 and http://teamwork:8080/app/tasks/1001", + "body": "Tasks: http://localhost:8080/app/tasks/9999 and http://localhost:8080/app/tasks/1001", "html_url": "https://github.com/acme/webapp/pull/42", "head": { "ref": "feature/oauth", diff --git a/tests/cases/unsupported-event/event.json b/tests/cases/unsupported-event/event.json index da136fb5..ee0fb746 100644 --- a/tests/cases/unsupported-event/event.json +++ b/tests/cases/unsupported-event/event.json @@ -4,7 +4,7 @@ "pull_request": { "number": 42, "title": "Add OAuth login", - "body": "Task: http://teamwork:8080/app/tasks/1001", + "body": "Task: http://localhost:8080/app/tasks/1001", "html_url": "https://github.com/acme/webapp/pull/42", "head": { "ref": "feature/oauth", diff --git a/tests/cases/wrong-bearer-token/event.json b/tests/cases/wrong-bearer-token/event.json index 5f80ac3b..581268f0 100644 --- a/tests/cases/wrong-bearer-token/event.json +++ b/tests/cases/wrong-bearer-token/event.json @@ -4,7 +4,7 @@ "pull_request": { "number": 42, "title": "Add OAuth login", - "body": "Task: http://teamwork:8080/app/tasks/1001", + "body": "Task: http://localhost:8080/app/tasks/1001", "html_url": "https://github.com/acme/webapp/pull/42", "head": { "ref": "feature/oauth", diff --git a/tests/cases/wrong-token/event.json b/tests/cases/wrong-token/event.json index 5f80ac3b..581268f0 100644 --- a/tests/cases/wrong-token/event.json +++ b/tests/cases/wrong-token/event.json @@ -4,7 +4,7 @@ "pull_request": { "number": 42, "title": "Add OAuth login", - "body": "Task: http://teamwork:8080/app/tasks/1001", + "body": "Task: http://localhost:8080/app/tasks/1001", "html_url": "https://github.com/acme/webapp/pull/42", "head": { "ref": "feature/oauth", diff --git a/tests/run.sh b/tests/run.sh index f2cd198c..707ae64c 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Runs the action's Docker image against a mock Teamwork API +# Runs the action against a mock Teamwork API # (tests/mock-teamwork.py) for every case in tests/cases, and compares the exit # code, stderr and requests the mock received with the case's expected file. # @@ -16,9 +16,6 @@ set -euo pipefail ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -IMAGE=github-sync:test -NETWORK=github-sync-test -MOCK=github-sync-teamwork update=false filter= @@ -30,80 +27,37 @@ for arg in "$@"; do fi done -stop_mock() { - docker rm --force "$MOCK" >/dev/null 2>&1 || true - docker network rm "$NETWORK" >/dev/null 2>&1 || true -} - +mock_pid= work=$(mktemp -d) -trap 'stop_mock; rm -rf "$work"' EXIT - -# The action's args, in action.yml order, as the input each one comes from -# (empty for the '' placeholders). The GitHub runner builds them the same way. -arg_inputs=() -while IFS= read -r item || [ -n "$item" ]; do - case $item in - "''") arg_inputs+=("") ;; - "\${{ inputs."*" }}") - item=${item#"\${{ inputs."} - arg_inputs+=("${item%" }}"}") ;; - *) - echo "Unsupported item in action.yml's runs.args: $item" >&2 - exit 1 ;; - esac -done < <(sed -n '/^ args:/,/^[^ #]/ s/^ - //p' "$ROOT/action.yml") +trap '[ -n "$mock_pid" ] && kill "$mock_pid" 2>/dev/null; rm -rf "$work"' EXIT # Runs the action for the case in $1 the way GitHub does: inputs as INPUT_* env -# vars, passed by name only, and as positional args built from action.yml. -run_case() ( +# vars, with nothing else from this shell's environment but PATH and HOME. +run_case() { local -r dir=$1 - export INPUT_TEAMWORK_URI=http://teamwork:8080 - export INPUT_TEAMWORK_API_TOKEN=test-token - local env_names=(INPUT_TEAMWORK_URI INPUT_TEAMWORK_API_TOKEN) + local env_vars=(PATH="$PATH" HOME="$HOME" GITHUB_REPOSITORY=acme/webapp GITHUB_EVENT_PATH="$dir/event.json" + INPUT_TEAMWORK_URI=http://localhost:8080 INPUT_TEAMWORK_API_TOKEN=test-token) local line while IFS= read -r line || [ -n "$line" ]; do case $line in ''|'#'*) continue ;; esac - export "${line%%=*}=${line#*=}" - env_names+=("${line%%=*}") + env_vars+=("$line") done < "$dir/inputs" - local docker_args=(--rm --network "$NETWORK" --volume "$dir/event.json:/github/workflow/event.json:ro" - --env GITHUB_REPOSITORY=acme/webapp --env GITHUB_EVENT_PATH=/github/workflow/event.json) - local env_name - for env_name in "${env_names[@]}"; do - docker_args+=(--env "$env_name") - done - - local action_args=() input value - for input in "${arg_inputs[@]}"; do - value= - if [ -n "$input" ]; then - env_name="INPUT_$input" - value=${!env_name:-} - fi - action_args+=("$value") - done - - docker run "${docker_args[@]}" "$IMAGE" "${action_args[@]}" -) - -docker build --quiet --tag "$IMAGE" "$ROOT" >/dev/null + env -i "${env_vars[@]}" bash "$ROOT/entrypoint.sh" +} -stop_mock -docker network create "$NETWORK" >/dev/null -docker run --detach --name "$MOCK" --network "$NETWORK" --network-alias teamwork \ - --volume "$ROOT/tests/mock-teamwork.py:/mock-teamwork.py:ro" --volume "$work:/out" \ - python:3.13-alpine python /mock-teamwork.py /out/requests >/dev/null +python3 "$ROOT/tests/mock-teamwork.py" "$work/requests" > "$work/mock.log" 2>&1 & +mock_pid=$! for _ in $(seq 50); do - if docker logs "$MOCK" 2>&1 | grep -q listening; then + if grep -q listening "$work/mock.log"; then break fi sleep 0.1 done -if ! docker logs "$MOCK" 2>&1 | grep -q listening; then +if ! grep -q listening "$work/mock.log"; then echo "The mock Teamwork API didn't start:" >&2 - docker logs "$MOCK" >&2 + cat "$work/mock.log" >&2 exit 1 fi