diff --git a/.github/default-labels.yml b/.github/default-labels.yml new file mode 100644 index 0000000..6dc35f4 --- /dev/null +++ b/.github/default-labels.yml @@ -0,0 +1,4 @@ +labels: + - use-deploys + - initialized + \ No newline at end of file diff --git a/.github/workflows/initialize-pr.yml b/.github/workflows/initialize-pr.yml new file mode 100644 index 0000000..028b74d --- /dev/null +++ b/.github/workflows/initialize-pr.yml @@ -0,0 +1,41 @@ +name: ⚙ Initialize PR + +on: + pull_request: + branches: [develop, main, shared/*] + types: [opened, reopened] +jobs: + init-pr: + name: Initialized + runs-on: ubuntu-latest + outputs: + drafted: ${{ steps.mark-draft.outputs.drafted || false }} + labeled: ${{ steps.default-label.outputs.labeled || false }} + steps: + - name: Mark as draft + id: mark-draft + shell: bash + continue-on-error: true + run: | + gh pr ready ${{ github.event.pull_request.number }} --undo --repo ${{ github.repository }} + echo "drafted=true" >> "$GITHUB_OUTPUT" + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - uses: actions/checkout@v4 + - name: Default labeling + id: default-label + shell: bash + continue-on-error: true + run: | + if [ -f $GITHUB_WORKSPACE/.github/default-labels.yml ]; then + labels=$(yq e '.labels[]' $GITHUB_WORKSPACE/.github/default-labels.yml) + for label in $labels; do + gh pr edit ${{ github.event.pull_request.number }} --add-label "$label" --repo ${{ github.repository }} + done + echo "labeled=true" >> "$GITHUB_OUTPUT" + else + echo "No default-labels.yml file found" + echo "labeled=false" >> "$GITHUB_OUTPUT" + fi + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/percy-on-demand.yml b/.github/workflows/percy-on-demand.yml new file mode 100644 index 0000000..7a467dd --- /dev/null +++ b/.github/workflows/percy-on-demand.yml @@ -0,0 +1,28 @@ +name: Percy On Demand Run + +on: + workflow_dispatch: + +jobs: + percy-check: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4.2.2 + + - name: Install Percy CLI + run: npm install -g @percy/cli + + - name: Run Percy check site1 + run: | + cd packages/site1 + percy snapshot --base-url https://site1-uwh-deploy-test.netlify.app snaplist.yml + env: + PERCY_TOKEN: ${{ secrets["PERCY_TOKEN_site1"] }} + - name: Run Percy check site2 + run: | + cd packages/site2 + percy snapshot --base-url https://site2-uwh-deploy-test.netlify.app snaplist.yml + env: + PERCY_TOKEN: ${{ secrets["PERCY_TOKEN_site2"] }} diff --git a/netlify-ignore.sh b/netlify-ignore.sh new file mode 100644 index 0000000..1ccacb7 --- /dev/null +++ b/netlify-ignore.sh @@ -0,0 +1,48 @@ +#! /bin/bash + +# netlify-ignore.sh +# logic based shell script for the Netlify based on enivonment variables +# exiting script with code 1 means build, code 0 means no changes so cancel + +# Optional Environmental Inputs: +# ALWAYS_BUILD: true,yes,on,1 +# forces an always build +# WATCHED_BUILD_PATHS: example ( "../../common" ) +# space separated paths to append to the default git diff statement + +# Required Inputs Supplied from Netlify build environment variables +# CACHED_COMMIT_REF +# COMMIT_REF +# SITE_NAME + +# Function to display usage +usage() { + echo -e "\033[1;33mUsage: $0 [--no-default-path]\033[0m" + echo -e "\033[1;33mDefault watch build path is set to '.' before other paths are included.\033[0m" + exit 0 # Exit script after printing usage and do not trigger a build +} + +# Parse optional flag +DEFAULT_WATCH_BUILD_PATH="." +while [[ "$1" != "" ]]; do + case $1 in + --no-default-path ) DEFAULT_WATCH_BUILD_PATH="" # remove default path + ;; + -h | --help ) usage + ;; + * ) usage + ;; + esac + shift +done + +set -x +shopt -s nocasematch +regex="^(build|deploy|build $SITE_NAME|deploy $SITE_NAME)$" + +if [[ ! "$WATCHED_BUILD_PATHS" =~ (false|no|off|0) ]]; then BUILD_PATHS="$WATCHED_BUILD_PATHS"; fi; +# shellcheck disable=SC2046 +if [[ "$ALWAYS_BUILD" =~ (true|yes|on|1) ]]; then (exit 1); +elif [ "$CACHED_COMMIT_REF" == "$COMMIT_REF" ]; then (exit 1); +elif [[ $(git rev-parse "$COMMIT_REF^{tree}") == $(git rev-parse "$COMMIT_REF^1^{tree}") && $(git -P show -s "$COMMIT_REF" --format=%s ) =~ $regex ]]; then (exit 1); +else git diff --quiet "$CACHED_COMMIT_REF" "$COMMIT_REF" $([[ -n "$DEFAULT_WATCH_BUILD_PATH" ]] && echo "$DEFAULT_WATCH_BUILD_PATH ")$([[ -n "$BUILD_PATHS" ]] && echo " $BUILD_PATHS"); fi; diff --git a/packages/site1/netlify.toml b/packages/site1/netlify.toml index c488343..d0a8d98 100644 --- a/packages/site1/netlify.toml +++ b/packages/site1/netlify.toml @@ -1,5 +1,5 @@ [build] - ignore = "echo $CACHED_COMMIT_REF && echo $COMMIT_REF && git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF . ../../common.md" + ignore = "bash ../../netlify-ignore.sh" #ignore = "exit 1" command = "sleep 3s && echo 'Site 1 finishes last by 3 seconds' && exit $BUILD_EXIT_CODE" #command = "echo $CACHED_COMMIT_REF && echo $COMMIT_REF" diff --git a/packages/site2/netlify.toml b/packages/site2/netlify.toml index d409d0c..05c5a62 100644 --- a/packages/site2/netlify.toml +++ b/packages/site2/netlify.toml @@ -1,5 +1,5 @@ [build] - ignore = "echo $CACHED_COMMIT_REF && echo $COMMIT_REF && git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF . ../../common.md" + ignore = "bash ../../netlify-ignore.sh" #ignore = "exit 0" command = "echo $CACHED_COMMIT_REF && echo $COMMIT_REF && exit $BUILD_EXIT_CODE" base = "packages/site2"