From ff44fc504e4837f79be1afcf2ecb2a4c0c87506c Mon Sep 17 00:00:00 2001 From: Theo Cranmore Date: Sun, 17 Mar 2024 01:59:06 +0000 Subject: [PATCH 01/17] output backend environment name --- action.yml | 2 ++ entrypoint.sh | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 3728faa..8d4bb8c 100644 --- a/action.yml +++ b/action.yml @@ -29,6 +29,8 @@ inputs: outputs: status: description: 'The result of the build.' + backend_environment: + description: 'The name of the backend environment' runs: using: 'docker' image: 'Dockerfile' diff --git a/entrypoint.sh b/entrypoint.sh index c1e9d42..f2b41c7 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -45,7 +45,7 @@ fi get_status () { local status; - status=$(aws amplify list-jobs --app-id "$1" --branch-name "$2" | jq -r ".jobSummaries[] | select(.commitId == \"$3\") | .status") + status=$(aws amplify list-jobs --app-id "$APP_ID" --branch-name "$BRANCH_NAME" | jq -r ".jobSummaries[] | select(.commitId == \"$COMMIT_ID\") | .status") exit_status=$? # it seems like sometimes status ends up with a new line in it? # strip it out @@ -104,8 +104,23 @@ if [[ -z $STATUS ]]; then seconds=$(( $TIMEOUT * 60 )) count=0 +get_backend_env_name () { + local env_name; + local env_arn; + # get backendEnvironmentArn from get branch first + env_arn=$(aws amplify get-branch --app-id "$APP_ID" --branch-name "$BRANCH_NAME" | jq -r ".branch.backendEnvironmentArn") + # search the list of backend environments for the environment name + env_name=$(aws amplify list-backend-environments --app-id "$APP_ID" | jq -r ".backendEnvironments[] | select(.backendEnvironmentArn == \"$env_arn\") | .environmentName") + exit_status=$? + env_name=$(echo $env_name | tr '\n' ' ') + echo "$env_name" + return $exit_status +} + if [[ "$WAIT" == "false" ]]; then + env_name=$(get_backend_env_name) echo "status=$STATUS" >> $GITHUB_OUTPUT + echo "environment_name=$env_name" >> $GITHUB_OUTPUT exit 0 elif [[ "$WAIT" == "true" ]]; then while [[ $STATUS != "SUCCEED" ]]; do @@ -121,6 +136,8 @@ elif [[ "$WAIT" == "true" ]]; then fi if [[ $STATUS == "FAILED" ]]; then echo "Build Failed!" + env_name=$(get_backend_env_name) + echo "environment_name=$env_name" >> $GITHUB_OUTPUT echo "status=$STATUS" >> $GITHUB_OUTPUT no_fail_check else @@ -129,5 +146,7 @@ elif [[ "$WAIT" == "true" ]]; then count=$(( $count + 30 )) done echo "Build Succeeded!" + env_name=$(get_backend_env_name) + echo "environment_name=$env_name" >> $GITHUB_OUTPUT echo "status=$STATUS" >> $GITHUB_OUTPUT fi From bceea0131e69d9d4186ebce6a877f1ac88e737f0 Mon Sep 17 00:00:00 2001 From: Theo Cranmore Date: Thu, 28 Mar 2024 11:55:21 +0000 Subject: [PATCH 02/17] echo the env name --- entrypoint.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/entrypoint.sh b/entrypoint.sh index f2b41c7..2efe87d 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -147,6 +147,7 @@ elif [[ "$WAIT" == "true" ]]; then done echo "Build Succeeded!" env_name=$(get_backend_env_name) + echo "Found environment name: $env_name" echo "environment_name=$env_name" >> $GITHUB_OUTPUT echo "status=$STATUS" >> $GITHUB_OUTPUT fi From 3b69b74f921135fde9e0d5e50d1699f7c6c5f596 Mon Sep 17 00:00:00 2001 From: Theo Cranmore Date: Thu, 28 Mar 2024 14:14:12 +0000 Subject: [PATCH 03/17] improve write output flow --- entrypoint.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 2efe87d..1fea7ea 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -71,11 +71,11 @@ fi if [[ $STATUS == "SUCCEED" ]]; then echo "Build Succeeded!" - echo "status=$STATUS" >> $GITHUB_OUTPUT + echo $(write_output) exit 0 elif [[ $STATUS == "FAILED" ]]; then echo "Build Failed!" - echo "status=$STATUS" >> $GITHUB_OUTPUT + echo $(write_output) no_fail_check fi @@ -117,10 +117,15 @@ get_backend_env_name () { return $exit_status } -if [[ "$WAIT" == "false" ]]; then - env_name=$(get_backend_env_name) +write_output () { echo "status=$STATUS" >> $GITHUB_OUTPUT + env_name=$(get_backend_env_name) + echo "Found environment name: $env_name" echo "environment_name=$env_name" >> $GITHUB_OUTPUT +} + +if [[ "$WAIT" == "false" ]]; then + echo $(write_output) exit 0 elif [[ "$WAIT" == "true" ]]; then while [[ $STATUS != "SUCCEED" ]]; do @@ -136,9 +141,7 @@ elif [[ "$WAIT" == "true" ]]; then fi if [[ $STATUS == "FAILED" ]]; then echo "Build Failed!" - env_name=$(get_backend_env_name) - echo "environment_name=$env_name" >> $GITHUB_OUTPUT - echo "status=$STATUS" >> $GITHUB_OUTPUT + echo $(write_output) no_fail_check else echo "Build in progress... Status: $STATUS" @@ -146,8 +149,5 @@ elif [[ "$WAIT" == "true" ]]; then count=$(( $count + 30 )) done echo "Build Succeeded!" - env_name=$(get_backend_env_name) - echo "Found environment name: $env_name" - echo "environment_name=$env_name" >> $GITHUB_OUTPUT - echo "status=$STATUS" >> $GITHUB_OUTPUT + echo $(write_output) fi From e3185cc4594fafd74c7f30ee33dde05a806db72c Mon Sep 17 00:00:00 2001 From: Theo Cranmore Date: Thu, 28 Mar 2024 14:48:04 +0000 Subject: [PATCH 04/17] re-arrange functions --- entrypoint.sh | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 1fea7ea..9863f0f 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -43,6 +43,26 @@ if [[ $TIMEOUT -lt 0 ]]; then exit 1 fi +get_backend_env_name () { + local env_name; + local env_arn; + # get backendEnvironmentArn from get branch first + env_arn=$(aws amplify get-branch --app-id "$APP_ID" --branch-name "$BRANCH_NAME" | jq -r ".branch.backendEnvironmentArn") + # search the list of backend environments for the environment name + env_name=$(aws amplify list-backend-environments --app-id "$APP_ID" | jq -r ".backendEnvironments[] | select(.backendEnvironmentArn == \"$env_arn\") | .environmentName") + exit_status=$? + env_name=$(echo $env_name | tr '\n' ' ') + echo "$env_name" + return $exit_status +} + +write_output () { + echo "status=$STATUS" >> $GITHUB_OUTPUT + env_name=$(get_backend_env_name) + echo "Found environment name: $env_name" + echo "environment_name=$env_name" >> $GITHUB_OUTPUT +} + get_status () { local status; status=$(aws amplify list-jobs --app-id "$APP_ID" --branch-name "$BRANCH_NAME" | jq -r ".jobSummaries[] | select(.commitId == \"$COMMIT_ID\") | .status") @@ -104,26 +124,6 @@ if [[ -z $STATUS ]]; then seconds=$(( $TIMEOUT * 60 )) count=0 -get_backend_env_name () { - local env_name; - local env_arn; - # get backendEnvironmentArn from get branch first - env_arn=$(aws amplify get-branch --app-id "$APP_ID" --branch-name "$BRANCH_NAME" | jq -r ".branch.backendEnvironmentArn") - # search the list of backend environments for the environment name - env_name=$(aws amplify list-backend-environments --app-id "$APP_ID" | jq -r ".backendEnvironments[] | select(.backendEnvironmentArn == \"$env_arn\") | .environmentName") - exit_status=$? - env_name=$(echo $env_name | tr '\n' ' ') - echo "$env_name" - return $exit_status -} - -write_output () { - echo "status=$STATUS" >> $GITHUB_OUTPUT - env_name=$(get_backend_env_name) - echo "Found environment name: $env_name" - echo "environment_name=$env_name" >> $GITHUB_OUTPUT -} - if [[ "$WAIT" == "false" ]]; then echo $(write_output) exit 0 From 1b30ab03e82b514455f7d004bc1bcd5a6c768011 Mon Sep 17 00:00:00 2001 From: Theo Cranmore Date: Sat, 30 Mar 2024 18:57:09 +0000 Subject: [PATCH 05/17] output the graphql endpoint --- action.yml | 2 ++ entrypoint.sh | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/action.yml b/action.yml index 8d4bb8c..de9540c 100644 --- a/action.yml +++ b/action.yml @@ -31,6 +31,8 @@ outputs: description: 'The result of the build.' backend_environment: description: 'The name of the backend environment' + graphql_endpoint: + description: 'The graphql endpoint for the backend' runs: using: 'docker' image: 'Dockerfile' diff --git a/entrypoint.sh b/entrypoint.sh index 9863f0f..1e1321b 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -56,11 +56,26 @@ get_backend_env_name () { return $exit_status } +get_backend_graphql_endpoint () { + local endpoint; + local env_name; + env_name=$(get_backend_env_name) + endpoint=$(aws amplifybackend get-backend --app-id "$APP_ID" --backend-environment-name "$env_name" | jq -r ".AmplifyMetaConfig" | jq -r ".api.platelet.output.GraphQLAPIEndpointOutput") + exit_status=$? + endpoint=$(echo $endpoint | tr '\n' ' ') + echo "$endpoint" + return $exit_status +} + + write_output () { echo "status=$STATUS" >> $GITHUB_OUTPUT env_name=$(get_backend_env_name) + graphql_endpoint=$(get_backend_graphql_endpoint) echo "Found environment name: $env_name" + echo "Found graphql endpoint: $graphql_endpoint" echo "environment_name=$env_name" >> $GITHUB_OUTPUT + echo "graphql_endpoint=$graphql_endpoint" >> $GITHUB_OUTPUT } get_status () { From 332dd7f7cb38a7686bd10cb8d8252354be9d42d8 Mon Sep 17 00:00:00 2001 From: Theo Cranmore Date: Sat, 30 Mar 2024 19:19:27 +0000 Subject: [PATCH 06/17] use nexttoken when getting env name --- entrypoint.sh | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 1e1321b..603efc2 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -46,12 +46,25 @@ fi get_backend_env_name () { local env_name; local env_arn; + local next_token = ""; + local list_result; # get backendEnvironmentArn from get branch first env_arn=$(aws amplify get-branch --app-id "$APP_ID" --branch-name "$BRANCH_NAME" | jq -r ".branch.backendEnvironmentArn") # search the list of backend environments for the environment name - env_name=$(aws amplify list-backend-environments --app-id "$APP_ID" | jq -r ".backendEnvironments[] | select(.backendEnvironmentArn == \"$env_arn\") | .environmentName") + while : ; do + list_result=$(aws amplify list-backend-environments --app-id "$APP_ID" --next-token "$next_token") + env_name=$(echo $list_result | jq -r ".backendEnvironments[] | select(.backendEnvironmentArn == \"$env_arn\") | .environmentName") + if [[ -n $env_name ]]; then + break + fi + env_name=$(echo $env_name | tr '\n' ' ') + next_token=$(echo $list_result | jq -r ".nextToken") + next_token=$(echo $next_token | tr '\n' ' ') + if [[ -z $next_token ]] || [[ $next_token == "null" ]]; then + break + fi + done exit_status=$? - env_name=$(echo $env_name | tr '\n' ' ') echo "$env_name" return $exit_status } From 0cdc9d299499d5508ef9070d3daa389e83a54e17 Mon Sep 17 00:00:00 2001 From: Theo Cranmore Date: Sat, 30 Mar 2024 20:05:31 +0000 Subject: [PATCH 07/17] extra logging --- entrypoint.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index 603efc2..f8d38ad 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -73,8 +73,11 @@ get_backend_graphql_endpoint () { local endpoint; local env_name; env_name=$(get_backend_env_name) + echo "Found env name getting graphql endpoint: $env_name" >&2 endpoint=$(aws amplifybackend get-backend --app-id "$APP_ID" --backend-environment-name "$env_name" | jq -r ".AmplifyMetaConfig" | jq -r ".api.platelet.output.GraphQLAPIEndpointOutput") exit_status=$? + echo "Exit status: $exit_status" >&2 + echo "Endpoint: $endpoint" >&2 endpoint=$(echo $endpoint | tr '\n' ' ') echo "$endpoint" return $exit_status @@ -82,6 +85,8 @@ get_backend_graphql_endpoint () { write_output () { + local env_name; + local graphql_endpoint; echo "status=$STATUS" >> $GITHUB_OUTPUT env_name=$(get_backend_env_name) graphql_endpoint=$(get_backend_graphql_endpoint) From e3755eddcdef0612466e41d4745dacff1ac160be Mon Sep 17 00:00:00 2001 From: Theo Cranmore Date: Sat, 30 Mar 2024 20:24:10 +0000 Subject: [PATCH 08/17] fix bad assignment --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index f8d38ad..1f86cd9 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -46,7 +46,7 @@ fi get_backend_env_name () { local env_name; local env_arn; - local next_token = ""; + local next_token=""; local list_result; # get backendEnvironmentArn from get branch first env_arn=$(aws amplify get-branch --app-id "$APP_ID" --branch-name "$BRANCH_NAME" | jq -r ".branch.backendEnvironmentArn") From e36c570b3825d0cfcb286824456ae00a8b816a6d Mon Sep 17 00:00:00 2001 From: Theo Cranmore Date: Sat, 30 Mar 2024 20:30:42 +0000 Subject: [PATCH 09/17] fix not properly stripping whitespace --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 1f86cd9..4973920 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -55,9 +55,9 @@ get_backend_env_name () { list_result=$(aws amplify list-backend-environments --app-id "$APP_ID" --next-token "$next_token") env_name=$(echo $list_result | jq -r ".backendEnvironments[] | select(.backendEnvironmentArn == \"$env_arn\") | .environmentName") if [[ -n $env_name ]]; then + env_name=$(echo $env_name | tr '\n' ' ') break fi - env_name=$(echo $env_name | tr '\n' ' ') next_token=$(echo $list_result | jq -r ".nextToken") next_token=$(echo $next_token | tr '\n' ' ') if [[ -z $next_token ]] || [[ $next_token == "null" ]]; then From d8c85a796fef74866c6ec38f77702ab016dd098d Mon Sep 17 00:00:00 2001 From: Theo Cranmore Date: Sat, 30 Mar 2024 20:33:30 +0000 Subject: [PATCH 10/17] test logging --- entrypoint.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index 4973920..d04b170 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -72,8 +72,12 @@ get_backend_env_name () { get_backend_graphql_endpoint () { local endpoint; local env_name; + local test; env_name=$(get_backend_env_name) echo "Found env name getting graphql endpoint: $env_name" >&2 + test=$(aws amplifybackend get-backend --app-id "$APP_ID" --backend-environment-name "$env_name") + echo "Test: $test" >&2 + endpoint=$(aws amplifybackend get-backend --app-id "$APP_ID" --backend-environment-name "$env_name" | jq -r ".AmplifyMetaConfig" | jq -r ".api.platelet.output.GraphQLAPIEndpointOutput") exit_status=$? echo "Exit status: $exit_status" >&2 From 4f4910ea6f24c370d83be8f8baa4597e10b36cb6 Mon Sep 17 00:00:00 2001 From: Theo Cranmore Date: Sat, 30 Mar 2024 20:36:49 +0000 Subject: [PATCH 11/17] test logging --- entrypoint.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index d04b170..d77e2aa 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,5 +1,7 @@ #!/bin/sh -l +set -e + APP_ID=$1 BRANCH_NAME=$2 COMMIT_ID=$3 @@ -75,6 +77,7 @@ get_backend_graphql_endpoint () { local test; env_name=$(get_backend_env_name) echo "Found env name getting graphql endpoint: $env_name" >&2 + echo $(aws --version) >&2 test=$(aws amplifybackend get-backend --app-id "$APP_ID" --backend-environment-name "$env_name") echo "Test: $test" >&2 From a4a8a312bc61dbd10a4f42f722242ee44ade56de Mon Sep 17 00:00:00 2001 From: Theo Cranmore Date: Sat, 30 Mar 2024 21:50:44 +0000 Subject: [PATCH 12/17] try update aws cli --- entrypoint.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index d77e2aa..606b804 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -51,10 +51,10 @@ get_backend_env_name () { local next_token=""; local list_result; # get backendEnvironmentArn from get branch first - env_arn=$(aws amplify get-branch --app-id "$APP_ID" --branch-name "$BRANCH_NAME" | jq -r ".branch.backendEnvironmentArn") + env_arn=$(/usr/local/bin/aws amplify get-branch --app-id "$APP_ID" --branch-name "$BRANCH_NAME" | jq -r ".branch.backendEnvironmentArn") # search the list of backend environments for the environment name while : ; do - list_result=$(aws amplify list-backend-environments --app-id "$APP_ID" --next-token "$next_token") + list_result=$(/usr/local/bin/aws amplify list-backend-environments --app-id "$APP_ID" --next-token "$next_token") env_name=$(echo $list_result | jq -r ".backendEnvironments[] | select(.backendEnvironmentArn == \"$env_arn\") | .environmentName") if [[ -n $env_name ]]; then env_name=$(echo $env_name | tr '\n' ' ') @@ -77,11 +77,11 @@ get_backend_graphql_endpoint () { local test; env_name=$(get_backend_env_name) echo "Found env name getting graphql endpoint: $env_name" >&2 - echo $(aws --version) >&2 - test=$(aws amplifybackend get-backend --app-id "$APP_ID" --backend-environment-name "$env_name") + echo $(/usr/local/bin/aws --version) >&2 + test=$(/usr/local/bin/aws amplifybackend get-backend --app-id "$APP_ID" --backend-environment-name "$env_name") echo "Test: $test" >&2 - endpoint=$(aws amplifybackend get-backend --app-id "$APP_ID" --backend-environment-name "$env_name" | jq -r ".AmplifyMetaConfig" | jq -r ".api.platelet.output.GraphQLAPIEndpointOutput") + endpoint=$(/usr/local/bin/aws amplifybackend get-backend --app-id "$APP_ID" --backend-environment-name "$env_name" | jq -r ".AmplifyMetaConfig" | jq -r ".api.platelet.output.GraphQLAPIEndpointOutput") exit_status=$? echo "Exit status: $exit_status" >&2 echo "Endpoint: $endpoint" >&2 @@ -105,7 +105,7 @@ write_output () { get_status () { local status; - status=$(aws amplify list-jobs --app-id "$APP_ID" --branch-name "$BRANCH_NAME" | jq -r ".jobSummaries[] | select(.commitId == \"$COMMIT_ID\") | .status") + status=$(/usr/local/bin/aws amplify list-jobs --app-id "$APP_ID" --branch-name "$BRANCH_NAME" | jq -r ".jobSummaries[] | select(.commitId == \"$COMMIT_ID\") | .status") exit_status=$? # it seems like sometimes status ends up with a new line in it? # strip it out From 476ad355748e36ea2debd76e36798a320c2bc2e3 Mon Sep 17 00:00:00 2001 From: Theo Cranmore Date: Sat, 30 Mar 2024 21:53:24 +0000 Subject: [PATCH 13/17] try update aws cli --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 51578e9..7aa63c9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Container image that runs your code -FROM alpine:3.16 +FROM alpine:latest RUN apk add aws-cli jq From 1b20a6741613f07d66212136d6ad394cf5828706 Mon Sep 17 00:00:00 2001 From: Theo Cranmore Date: Sat, 30 Mar 2024 21:54:04 +0000 Subject: [PATCH 14/17] Revert "try update aws cli" This reverts commit a4a8a312bc61dbd10a4f42f722242ee44ade56de. --- entrypoint.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 606b804..d77e2aa 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -51,10 +51,10 @@ get_backend_env_name () { local next_token=""; local list_result; # get backendEnvironmentArn from get branch first - env_arn=$(/usr/local/bin/aws amplify get-branch --app-id "$APP_ID" --branch-name "$BRANCH_NAME" | jq -r ".branch.backendEnvironmentArn") + env_arn=$(aws amplify get-branch --app-id "$APP_ID" --branch-name "$BRANCH_NAME" | jq -r ".branch.backendEnvironmentArn") # search the list of backend environments for the environment name while : ; do - list_result=$(/usr/local/bin/aws amplify list-backend-environments --app-id "$APP_ID" --next-token "$next_token") + list_result=$(aws amplify list-backend-environments --app-id "$APP_ID" --next-token "$next_token") env_name=$(echo $list_result | jq -r ".backendEnvironments[] | select(.backendEnvironmentArn == \"$env_arn\") | .environmentName") if [[ -n $env_name ]]; then env_name=$(echo $env_name | tr '\n' ' ') @@ -77,11 +77,11 @@ get_backend_graphql_endpoint () { local test; env_name=$(get_backend_env_name) echo "Found env name getting graphql endpoint: $env_name" >&2 - echo $(/usr/local/bin/aws --version) >&2 - test=$(/usr/local/bin/aws amplifybackend get-backend --app-id "$APP_ID" --backend-environment-name "$env_name") + echo $(aws --version) >&2 + test=$(aws amplifybackend get-backend --app-id "$APP_ID" --backend-environment-name "$env_name") echo "Test: $test" >&2 - endpoint=$(/usr/local/bin/aws amplifybackend get-backend --app-id "$APP_ID" --backend-environment-name "$env_name" | jq -r ".AmplifyMetaConfig" | jq -r ".api.platelet.output.GraphQLAPIEndpointOutput") + endpoint=$(aws amplifybackend get-backend --app-id "$APP_ID" --backend-environment-name "$env_name" | jq -r ".AmplifyMetaConfig" | jq -r ".api.platelet.output.GraphQLAPIEndpointOutput") exit_status=$? echo "Exit status: $exit_status" >&2 echo "Endpoint: $endpoint" >&2 @@ -105,7 +105,7 @@ write_output () { get_status () { local status; - status=$(/usr/local/bin/aws amplify list-jobs --app-id "$APP_ID" --branch-name "$BRANCH_NAME" | jq -r ".jobSummaries[] | select(.commitId == \"$COMMIT_ID\") | .status") + status=$(aws amplify list-jobs --app-id "$APP_ID" --branch-name "$BRANCH_NAME" | jq -r ".jobSummaries[] | select(.commitId == \"$COMMIT_ID\") | .status") exit_status=$? # it seems like sometimes status ends up with a new line in it? # strip it out From 33daa306eb297755f103473d270b5545e73f88b1 Mon Sep 17 00:00:00 2001 From: Theo Cranmore Date: Sat, 30 Mar 2024 21:58:29 +0000 Subject: [PATCH 15/17] strip all whitespace from env name --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index d77e2aa..7efdd5c 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -57,7 +57,7 @@ get_backend_env_name () { list_result=$(aws amplify list-backend-environments --app-id "$APP_ID" --next-token "$next_token") env_name=$(echo $list_result | jq -r ".backendEnvironments[] | select(.backendEnvironmentArn == \"$env_arn\") | .environmentName") if [[ -n $env_name ]]; then - env_name=$(echo $env_name | tr '\n' ' ') + env_name=$(echo $env_name | tr -d " \t\n\r") break fi next_token=$(echo $list_result | jq -r ".nextToken") From 03a43428f312377f6da84f2ae53b80da16c47250 Mon Sep 17 00:00:00 2001 From: Theo Cranmore Date: Sat, 30 Mar 2024 22:14:52 +0000 Subject: [PATCH 16/17] strip whitespace. remove logging --- entrypoint.sh | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 7efdd5c..14ce73e 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -61,7 +61,7 @@ get_backend_env_name () { break fi next_token=$(echo $list_result | jq -r ".nextToken") - next_token=$(echo $next_token | tr '\n' ' ') + next_token=$(echo $next_token | tr -d " \t\n\r") if [[ -z $next_token ]] || [[ $next_token == "null" ]]; then break fi @@ -77,15 +77,9 @@ get_backend_graphql_endpoint () { local test; env_name=$(get_backend_env_name) echo "Found env name getting graphql endpoint: $env_name" >&2 - echo $(aws --version) >&2 - test=$(aws amplifybackend get-backend --app-id "$APP_ID" --backend-environment-name "$env_name") - echo "Test: $test" >&2 - endpoint=$(aws amplifybackend get-backend --app-id "$APP_ID" --backend-environment-name "$env_name" | jq -r ".AmplifyMetaConfig" | jq -r ".api.platelet.output.GraphQLAPIEndpointOutput") exit_status=$? - echo "Exit status: $exit_status" >&2 - echo "Endpoint: $endpoint" >&2 - endpoint=$(echo $endpoint | tr '\n' ' ') + endpoint=$(echo $endpoint | tr -d " \t\n\r") echo "$endpoint" return $exit_status } @@ -109,7 +103,7 @@ get_status () { exit_status=$? # it seems like sometimes status ends up with a new line in it? # strip it out - status=$(echo $status | tr '\n' ' ') + status=$(echo $status | tr -d " \t\n\r") echo "$status" return $exit_status } From 57e118fb280f6970422b5ff06b43fdfb9f744ea4 Mon Sep 17 00:00:00 2001 From: Theo Cranmore Date: Wed, 10 Apr 2024 20:26:19 +0100 Subject: [PATCH 17/17] update readme --- README.md | 18 +++++++++++++++--- action.yml | 4 ++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f2ddbf3..14f269f 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Example: ``` - name: Wait for Amplify to finish remote build - uses: duckbytes/amplify-build-status@v1.1 + uses: duckbytes/amplify-build-status@v2 with: app-id: ${{ secrets.AMPLIFY_APP_ID }} branch-name: ${{ github.ref_name }} @@ -31,7 +31,7 @@ Click on *Edit backend* and copy the appId value. ### Inputs -`app-id`, `branch-name` and `commit-id` are all required input. You also must set `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` and `AWS_REGION` in your environnment variables. +`app-id`, `branch-name` and `commit-id` are all required input. You also must set `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` and `AWS_REGION` in your environment variables. Other inputs are: @@ -41,8 +41,20 @@ Other inputs are: ### Outputs - `status` # The build status output according to the AWS CLI. +- `backend_environment` # The environment name. +- `graphql_endpoint` # The GraphQL endpoint. + +You can access these values later in your workflow like this: + +`${{ steps.amplify_status.outputs.environment_name }}` ## Known issues +Sometimes the Amplify console doesn't automatically associate a backend with a new deployment. + +Amplify will successfully complete the new build, but it is necessary click `(Edit)` next to "Continuous deploys set up" and set it to the correct backend before the action can return the environment name and GraphQL endpoint. + +**only on V1** + If you are connecting a branch to Amplify for the first time, the commit-id may be `HEAD` instead of the commit sha. -Any subsequent bulds triggered by commits will use the actual commit sha. +Any subsequent builds triggered by commits will use the actual commit sha. diff --git a/action.yml b/action.yml index de9540c..2e5afce 100644 --- a/action.yml +++ b/action.yml @@ -30,9 +30,9 @@ outputs: status: description: 'The result of the build.' backend_environment: - description: 'The name of the backend environment' + description: 'The environment name' graphql_endpoint: - description: 'The graphql endpoint for the backend' + description: 'The GraphQL endpoint.' runs: using: 'docker' image: 'Dockerfile'