From aac62b98c3818d049e6f39ca738ddae76223a6f2 Mon Sep 17 00:00:00 2001 From: Ian Lewis Date: Mon, 3 Oct 2022 01:22:54 +0000 Subject: [PATCH] Update pre-submits Signed-off-by: Ian Lewis --- .github/workflows/pre-submit.actions.yml | 28 ++++++++-------- .github/workflows/pre-submit.lint.yml | 18 +++++++++++ actions/installer/Makefile | 41 ++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/pre-submit.lint.yml create mode 100644 actions/installer/Makefile diff --git a/.github/workflows/pre-submit.actions.yml b/.github/workflows/pre-submit.actions.yml index 63a6f4efc..97df0c1dc 100644 --- a/.github/workflows/pre-submit.actions.yml +++ b/.github/workflows/pre-submit.actions.yml @@ -1,27 +1,26 @@ name: Actions pre submits -on: [pull_request, workflow_dispatch] + +on: + pull_request: + branches: [main] + workflow_dispatch: permissions: read-all jobs: - action-presubmit: + check-dist: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2 + - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2 - - name: Setup Node.js 16 - uses: actions/setup-node@969bd2663942d722d85b6a8626225850c2f7be4b # tag=v3.5.0 + - name: Set Node.js 16 + uses: actions/setup-node@2fddd8803e2f5c9604345a0b591c3020ee971a93 # tag=v3.4.1 with: node-version: 16 - - name: Install dependencies - working-directory: actions/installer - run: npm ci - - - name: Run build and tests + - name: Rebuild the dist/ directory working-directory: actions/installer - run: npm run all + run: make package - name: Compare the expected and actual dist/ directories working-directory: actions/installer @@ -34,10 +33,9 @@ jobs: exit 1 fi - # If there are uncommited changes in dist/, upload the directory - - name: Upload dist/ + # If index.js was different from expected, upload the expected version as an artifact + - uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 if: ${{ failure() && steps.diff.conclusion == 'failure' }} - uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # tag=v3.1.0 with: name: dist path: dist/ diff --git a/.github/workflows/pre-submit.lint.yml b/.github/workflows/pre-submit.lint.yml new file mode 100644 index 000000000..3f1ace748 --- /dev/null +++ b/.github/workflows/pre-submit.lint.yml @@ -0,0 +1,18 @@ +name: Lint + +on: [pull_request] + +permissions: + # Needed to check out the repo. + contents: read + +jobs: + eslint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2 + - uses: actions/setup-node@v3 + with: + node-version: 16 + - working-directory: actions/installer + run: make lint diff --git a/actions/installer/Makefile b/actions/installer/Makefile new file mode 100644 index 000000000..642a2b6e1 --- /dev/null +++ b/actions/installer/Makefile @@ -0,0 +1,41 @@ +SHELL := /bin/bash +OUTPUT_FORMAT = $(shell if [ "${GITHUB_ACTIONS}" == "true" ]; then echo "github"; else echo ""; fi) + +.PHONY: help +help: ## Shows all targets and help from the Makefile (this message). + @echo "installer Makefile" + @echo "Usage: make [COMMAND]" + @echo "" + @grep --no-filename -E '^([/a-z.A-Z0-9_%-]+:.*?|)##' $(MAKEFILE_LIST) | \ + awk 'BEGIN {FS = "(:.*?|)## ?"}; { \ + if (length($$1) > 0) { \ + printf " \033[36m%-20s\033[0m %s\n", $$1, $$2; \ + } else { \ + if (length($$2) > 0) { \ + printf "%s\n", $$2; \ + } \ + } \ + }' + +node_modules/.installed: package.json package-lock.json + npm ci + touch node_modules/.installed + +.PHONY: action +action: node_modules/.installed ## Builds the action. + npm run build + +.PHONY: package +package: node_modules/.installed ## Builds the distribution package. + npm run all + +.PHONY: clean +clean: + rm -rf dist lib node_modules + +## Testing +##################################################################### + +.PHONY: lint +lint: node_modules/.installed ## Runs eslint. + npm run lint