From 24c19b435b2915be4d2748b2e53f1a6992104cbf Mon Sep 17 00:00:00 2001 From: rabi-siddique Date: Thu, 1 Aug 2024 15:51:18 +0500 Subject: [PATCH] ci: use pyTooling/Actions/with-post-step for commands in run and post-run --- .github/actions/restore-node/action.yml | 29 ++++--------------- .../actions/restore-node/check-git-status.sh | 16 ++++++++++ .github/actions/with-post-step/action.yml | 21 -------------- .github/actions/with-post-step/main.cjs | 22 -------------- 4 files changed, 21 insertions(+), 67 deletions(-) create mode 100644 .github/actions/restore-node/check-git-status.sh delete mode 100644 .github/actions/with-post-step/action.yml delete mode 100644 .github/actions/with-post-step/main.cjs diff --git a/.github/actions/restore-node/action.yml b/.github/actions/restore-node/action.yml index 6d7740325b3b..a06bc012b992 100644 --- a/.github/actions/restore-node/action.yml +++ b/.github/actions/restore-node/action.yml @@ -181,29 +181,10 @@ runs: mkdir -p node_modules/.cache/agoric date > node_modules/.cache/agoric/yarn-built - # Refs: https://github.com/orgs/community/discussions/45342 - - name: Validate Git Tree in Root Directory - if: inputs.path == '.' - uses: ./.github/actions/with-post-step + - name: Validate Git Tree Cleanliness + uses: pyTooling/Actions/with-post-step@v0.4.5 with: - main: echo "Checking Git tree for changes in the root directory..." + main: | + bash ${{ inputs.path }}/.github/actions/restore-node/check-git-status.sh ${{ inputs.path }} post: | - set -x - if [ -n "$(git status --porcelain | grep -vE 'junit.xml$' | grep -vE '^[?][?] endo-sha.txt$|^.'; true)" ]; then - git status - echo "Unexpected dirty git status in default path" 1>&2 - exit 1 - fi - - - name: Validate Git Tree in Agoric SDK Directory - if: inputs.path == './agoric-sdk' - uses: ./agoric-sdk/.github/actions/with-post-step - with: - main: echo "Checking Git tree for changes in the root directory..." - post: | - set -x - if [ -n "$(git status --porcelain | grep -vE 'junit.xml$' | grep -vE '^[?][?] endo-sha.txt$|^.'; true)" ]; then - git status - echo "Unexpected dirty git status in Agoric SDK path" 1>&2 - exit 1 - fi + bash ${{ inputs.path }}/.github/actions/restore-node/check-git-status.sh ${{ inputs.path }} diff --git a/.github/actions/restore-node/check-git-status.sh b/.github/actions/restore-node/check-git-status.sh new file mode 100644 index 000000000000..92475f04f7ff --- /dev/null +++ b/.github/actions/restore-node/check-git-status.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# Navigate to the specified directory +cd $1 +# Set verbose execution +set -x +# Check for unexpected changes +# Fail if git status detects changes, ignoring: +# - Files ending with 'junit.xml' +# - The untracked file 'endo-sha.txt' +# This setup ensures the Git status only flags unexpected modifications or untracked files outside these specified exceptions. +changes=$(git status --porcelain | grep -vE 'junit.xml$' | grep -vE '^\?\? endo-sha.txt$') +if [ -n "$changes" ]; then + git status + echo "Unexpected dirty git status in Agoric SDK path" + exit 1 +fi diff --git a/.github/actions/with-post-step/action.yml b/.github/actions/with-post-step/action.yml deleted file mode 100644 index 9e1295380c8a..000000000000 --- a/.github/actions/with-post-step/action.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: With Post Step - -description: > - JavaScript Action to run a main command and a subsequent post command. - -inputs: - main: - description: 'Primary command or script to execute.' - required: true - post: - description: 'Command or script to run after the main command.' - required: true - key: - description: 'State variable name to identify the post step.' - required: false - default: POST - -runs: - using: 'node20' - main: 'main.cjs' - post: 'main.cjs' diff --git a/.github/actions/with-post-step/main.cjs b/.github/actions/with-post-step/main.cjs deleted file mode 100644 index 15390bc4bb4a..000000000000 --- a/.github/actions/with-post-step/main.cjs +++ /dev/null @@ -1,22 +0,0 @@ -// Ref: https://github.com/pyTooling/Actions/blob/main/with-post-step/main.js -const { spawn } = require('child_process'); -const { appendFileSync } = require('fs'); -const { EOL } = require('os'); - -const run = cmd => { - const subprocess = spawn(cmd, { stdio: 'inherit', shell: true }); - subprocess.on('exit', exitCode => { - process.exitCode = exitCode; - }); -}; - -const key = process.env.INPUT_KEY.toUpperCase(); - -if (process.env[`STATE_${key}`] !== undefined) { - // Are we in the 'post' step? - run(process.env.INPUT_POST); -} else { - // Otherwise, this is the main step - appendFileSync(process.env.GITHUB_STATE, `${key}=true${EOL}`); - run(process.env.INPUT_MAIN); -}