Skip to content

Commit

Permalink
ci: check dirty git tree for jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
rabi-siddique committed Aug 6, 2024
1 parent fc07a0f commit fd78345
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 15 deletions.
41 changes: 26 additions & 15 deletions .github/actions/restore-node/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,29 @@ runs:
mkdir -p node_modules/.cache/agoric
date > node_modules/.cache/agoric/yarn-built
- name: git dirty check
working-directory: ${{ inputs.path }}
shell: bash
run: |-
set -x
# Fail if `git status` reports anything other than the following:
# * an untracked endo-sha.txt from above
# * work tree files that have been staged without further changes
# (e.g., package.json or yarn.lock) as indicated by the Y position
# in "XY PATH" being a space
if [ -n "$(git status --porcelain | grep -vE '^[?][?] endo-sha.txt$|^. '; true)" ]; then
git status
echo "Unexpected dirty git status" 1>&2
exit 1
fi
# Refs: https://github.com/orgs/community/discussions/45342
- name: Validate Git Tree in Root Directory
if: inputs.path == '.'
uses: ./.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 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
21 changes: 21 additions & 0 deletions .github/actions/with-post-step/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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'
22 changes: 22 additions & 0 deletions .github/actions/with-post-step/main.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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);
}

0 comments on commit fd78345

Please sign in to comment.