diff --git a/action.yaml b/action.yaml index 3553002..eedb59d 100644 --- a/action.yaml +++ b/action.yaml @@ -1,9 +1,6 @@ name: 'Superblocks Export' description: 'Pull application-specific components source code from Superblocks' inputs: - sha: - description: 'Commit to pull changes for' - default: 'HEAD' token: description: 'The Superblocks access token to use' required: true @@ -13,16 +10,18 @@ inputs: path: description: 'The relative path to the Superblocks config file' default: '.superblocks/superblocks.json' + sha: + description: 'Commit to pull changes for' + default: 'HEAD' runs: using: 'docker' image: 'Dockerfile' - args: - - ${{ inputs.sha }} - - ${{ inputs.token }} - - ${{ inputs.domain }} - - ${{ inputs.path }} env: SUPERBLOCKS_AUTHOR_NAME: 'superblocks-app[bot]' SUPERBLOCKS_AUTHOR_EMAIL: '142439023+superblocks-app[bot]@users.noreply.github.com' SUPERBLOCKS_COMMIT_MESSAGE_IDENTIFIER: '[superblocks ci]' + SUPERBLOCKS_TOKEN: ${{ inputs.token }} + SUPERBLOCKS_DOMAIN: ${{ inputs.domain }} + SUPERBLOCKS_CONFIG_PATH: ${{ inputs.path }} + SUPERBLOCKS_COMMIT_SHA: ${{ inputs.sha }} diff --git a/entrypoint.sh b/entrypoint.sh index 0f69a71..674063a 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -3,15 +3,19 @@ set -e set -o pipefail -SHA="$1" -TOKEN="$2" -DOMAIN="$3" -CONFIG_PATH="$4" - +COMMIT_SHA="${COMMIT_SHA:-HEAD}" +SUPERBLOCKS_DOMAIN="${SUPERBLOCKS_DOMAIN:-app.superblocks.com}" +SUPERBLOCKS_CONFIG_PATH="${SUPERBLOCKS_CONFIG_PATH:-.superblocks/superblocks.json}" SUPERBLOCKS_AUTHOR_NAME="${SUPERBLOCKS_AUTHOR_NAME:-superblocks-app[bot]}" SUPERBLOCKS_AUTHOR_EMAIL="${SUPERBLOCKS_AUTHOR_EMAIL:-142439023+superblocks-app[bot]@users.noreply.github.com}" SUPERBLOCKS_COMMIT_MESSAGE_IDENTIFIER="${SUPERBLOCKS_COMMIT_MESSAGE_IDENTIFIER:-[superblocks ci]}" +# Ensure that a Superblocks token is provided +if [ -z "$SUPERBLOCKS_TOKEN" ]; then + echo "The 'SUPERBLOCKS_TOKEN' environment variable is unset or empty. Exiting..." + exit 1 +fi + if [ -z "$REPO_DIR" ]; then REPO_DIR="$(pwd)" else @@ -21,8 +25,8 @@ fi git config --global --add safe.directory "$REPO_DIR" # Get the actor name and commit message the last commit -actor_name=$(git show -s --format='%an' "$SHA") -commit_message=$(git show -s --format='%B' "$SHA") +actor_name=$(git show -s --format='%an' "$COMMIT_SHA") +commit_message=$(git show -s --format='%B' "$COMMIT_SHA") # Skip pull if the commit was not made by Superblocks. To support multiple Git providers, we also # check for the commit message identifier used to identify Superblocks commits. @@ -39,8 +43,8 @@ if [ -n "$changed_files" ]; then # Login to Superblocks printf "\nLogging in to Superblocks...\n" - superblocks config set domain "$DOMAIN" - superblocks login -t "$TOKEN" + superblocks config set domain "$SUPERBLOCKS_DOMAIN" + superblocks login -t "$SUPERBLOCKS_TOKEN" else echo "No files changed since the last commit. Skipping pull..." exit 0 @@ -72,7 +76,7 @@ pull_and_commit() { } # Check if any Superblocks applications have changed -jq -r '.resources[] | select(.resourceType == "APPLICATION") | .location' "$CONFIG_PATH" | while read -r location; do +jq -r '.resources[] | select(.resourceType == "APPLICATION") | .location' "$SUPERBLOCKS_CONFIG_PATH" | while read -r location; do printf "\nChecking %s for changes...\n" "$location" pull_and_commit "$location" done