Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch positional arguments to environment variables #10

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 }}
24 changes: 14 additions & 10 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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