From 29984779a508110228e51dd0ac27bcd68e0cad5d Mon Sep 17 00:00:00 2001 From: Danielle Adams Date: Tue, 15 Nov 2022 10:33:03 -0700 Subject: [PATCH] ARCH-1617 - Updating action build --- .github/workflows/build.yml | 67 ++++++++++++++++++++++++++--------- README.md | 29 +++++++++++---- check-for-unstaged-changes.sh | 17 --------- package-lock.json | 22 ------------ package.json | 9 +---- 5 files changed, 74 insertions(+), 70 deletions(-) delete mode 100755 check-for-unstaged-changes.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 67af818..c7626ef 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,30 +4,65 @@ on: # access to the target repository from public forks. This should remain as a pull_request # trigger because checkout, build, format and checking for changes do not need elevated # permissions to the repository. The reduced permissions for public forks is adequate. + # Since this will commit readme/recompile changes back to the branch, special attention + # should be paid to changes made to this workflow when reviewing the PR and granting + # permission to first time contributors to run the workflow. pull_request: - # Don't include any specific paths here so we always get a build that produces a status - # check that our Branch Protection Rules can use. Having a status check also allows us - # to require that branches be up to date before they are merged. - + # Don't include any specific paths here so we always get a build that produces a status + # check that our Branch Protection Rules can use. Having a status check also allows us + # to require that branches be up to date before they are merged. + jobs: build: - runs-on: ${{ matrix.operating-system }} - strategy: - fail-fast: false - matrix: - operating-system: [ubuntu-latest, windows-latest, macOS-latest] - + runs-on: ubuntu-latest + steps: - name: Checkout uses: actions/checkout@v3 + with: + ref: ${{ github.head_ref }} + fetch-depth: 0 + - name: Setup Node.js 16 uses: actions/setup-node@v3 with: node-version: 16.x - - name: Build + + # If this step results in changes, they will be committed in the last step + - name: Recompile and Format action run: npm run build - - name: Format - run: npm run format - - name: Check for unstaged changes - if: runner.os != 'windows' - run: ./check-for-unstaged-changes.sh + + - name: Check for code changes to the action + id: action-code + uses: im-open/did-custom-action-code-change@v1.0.1 + with: + files-with-code: 'action.yml,package.json,package-lock.json' + folders-with-code: 'src,dist' + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Get the next version for the readme if there are code changes to the action + if: steps.action-code.outputs.HAS_CHANGES == 'true' + id: version + uses: im-open/git-version-lite@v2.1.2 + + - name: Update readme with next version if there are code changes to the action + if: steps.action-code.outputs.HAS_CHANGES == 'true' + uses: im-open/update-action-version-in-file@v1.0.0 + with: + file-to-update: './README.md' + action-name: ${{ github.repository }} + updated-version: ${{ steps.version.outputs.NEXT_VERSION }} + + - name: Commit unstaged readme/recompile changes if there are code changes to the action + if: steps.action-code.outputs.HAS_CHANGES == 'true' + run: | + if [[ "$(git status --porcelain)" != "" ]]; then + echo "There are changes to commit" + git config user.name github-actions + git config user.email github-actions@github.com + git add . + git commit -m "Update readme with latest version and/or recompile the action." + git push origin HEAD:${{ github.head_ref }} + else + echo "There were no changes to commit" + fi diff --git a/README.md b/README.md index c64af6c..e03cade 100644 --- a/README.md +++ b/README.md @@ -82,24 +82,39 @@ This action does not generate the code coverage reports itself, those must be cr ## Contributing When creating new PRs please ensure: -1. The action has been recompiled. See the [Recompiling](#recompiling) section below for more details. -2. For major or minor changes, at least one of the commit messages contains the appropriate `+semver:` keywords listed under [Incrementing the Version](#incrementing-the-version). -3. The `README.md` example has been updated with the new version. See [Incrementing the Version](#incrementing-the-version). -4. The action code does not contain sensitive information. -### Recompiling +1. For major or minor changes, at least one of the commit messages contains the appropriate `+semver:` keywords listed under [Incrementing the Version](#incrementing-the-version). +1. The action code does not contain sensitive information. -If changes are made to the action's code in this repository, or its dependencies, you will need to re-compile the action. +When a pull request is created and there are changes to code-specific files and folders, the build workflow will run and it will recompile the action and push a commit to the branch if the PR author has not done so. The usage examples in the README.md will also be updated with the next version if they have not been updated manually. The following files and folders contain action code and will trigger the automatic updates: + +- action.yml +- package.json +- package-lock.json +- src/\*\* +- dist/\*\* + +There may be some instances where the bot does not have permission to push changes back to the branch though so these steps should be done manually for those branches. See [Recompiling Manually](#recompiling-manually) and [Incrementing the Version](#incrementing-the-version) for more details. + +### Recompiling Manually + +If changes are made to the action's code in this repository, or its dependencies, the action can be re-compiled by running the following command: ```sh # Installs dependencies and bundles the code npm run build + +# Bundle the code (if dependencies are already installed) +npm run bundle ``` -These commands utilize [ncc](https://github.com/vercel/ncc) to bundle the action and its dependencies into a single file located in the `dist` folder. +These commands utilize [esbuild](https://esbuild.github.io/getting-started/#bundling-for-node) to bundle the action and +its dependencies into a single file located in the `dist` folder. ### Incrementing the Version +Both the build and PR merge workflows will use the strategies below to determine what the next version will be. If the build workflow was not able to automatically update the README.md action examples with the next version, the README.md should be updated manually as part of the PR using that calculated version. + This action uses [git-version-lite] to examine commit messages to determine whether to perform a major, minor or patch increment on merge. The following table provides the fragment that should be included in a commit message to active different increment strategies. | Increment Type | Commit Message Fragment | | -------------- | ------------------------------------------- | diff --git a/check-for-unstaged-changes.sh b/check-for-unstaged-changes.sh deleted file mode 100755 index 287290b..0000000 --- a/check-for-unstaged-changes.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -if [[ "$(git status --porcelain)" != "" ]]; then - echo ---------------------------------------- - echo git status - echo ---------------------------------------- - git status - echo ---------------------------------------- - echo git diff - echo ---------------------------------------- - git diff - echo ---------------------------------------- - echo Troubleshooting - echo ---------------------------------------- - echo "::error::Unstaged changes detected. Locally try running: git clean -ffdx && npm run build && npm run format" - exit 1 -fi \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 9b7a682..7caf44f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,6 @@ "devDependencies": { "@types/node": "^14.11.2", "@zeit/ncc": "^0.22.3", - "husky": "^7.0.1", "prettier": "^2.3.2", "typescript": "^4.0.3" } @@ -66,21 +65,6 @@ "ncc": "dist/ncc/cli.js" } }, - "node_modules/husky": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/husky/-/husky-7.0.1.tgz", - "integrity": "sha512-gceRaITVZ+cJH9sNHqx5tFwbzlLCVxtVZcusME8JYQ8Edy5mpGDOqD8QBCdMhpyo9a+JXddnujQ4rpY2Ff9SJA==", - "dev": true, - "bin": { - "husky": "lib/bin.js" - }, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/typicode" - } - }, "node_modules/prettier": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.3.2.tgz", @@ -166,12 +150,6 @@ "integrity": "sha512-jnCLpLXWuw/PAiJiVbLjA8WBC0IJQbFeUwF4I9M+23MvIxTxk5pD4Q8byQBSPmHQjz5aBoA7AKAElQxMpjrCLQ==", "dev": true }, - "husky": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/husky/-/husky-7.0.1.tgz", - "integrity": "sha512-gceRaITVZ+cJH9sNHqx5tFwbzlLCVxtVZcusME8JYQ8Edy5mpGDOqD8QBCdMhpyo9a+JXddnujQ4rpY2Ff9SJA==", - "dev": true - }, "prettier": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.3.2.tgz", diff --git a/package.json b/package.json index 0922be4..cccbdb1 100644 --- a/package.json +++ b/package.json @@ -4,16 +4,10 @@ "description": "", "main": "lib/reportgenerator.js", "scripts": { - "build": "npm ci && tsc && ncc build", + "build": "npm ci && tsc && ncc build && npm run format", "format": "prettier --write **/*.js", "format-check": "prettier --check **/*.js" }, - "husky": { - "hooks": { - "pre-commit": "npm run build && npm run format", - "pre-push": "npm run format-check" - } - }, "keywords": [ "code-coverage", "testing", @@ -30,7 +24,6 @@ "devDependencies": { "@types/node": "^14.11.2", "@zeit/ncc": "^0.22.3", - "husky": "^7.0.1", "prettier": "^2.3.2", "typescript": "^4.0.3" }