From 941db205d830d7e5d5629606964eb218decefaf3 Mon Sep 17 00:00:00 2001 From: Adam Bovill Date: Thu, 26 Oct 2023 02:04:22 +0000 Subject: [PATCH] feat(lint): lint now checks release notes This adds support for checking release notes to lint. Also, we have updated how the action READMEs are generated. They now use a pre-commit hook to call action-docs. --- .github/workflows/ci.yaml | 19 ++++------------- .github/workflows/release.yaml | 4 ++-- .pre-commit-config.yaml | 7 ++++++ check-build/README.md | 27 +++++++++++++++++------ lint/README.md | 39 ++++++++++++++++++++++++---------- lint/action.yaml | 8 ++++++- release/README.md | 37 ++++++++++++++++++++------------ release/action.yaml | 4 ++-- script/update-action-readme | 14 ++++++++++++ test/README.md | 35 ++++++++++++++++-------------- test/action.yaml | 2 +- 11 files changed, 128 insertions(+), 68 deletions(-) create mode 100755 script/update-action-readme diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 76533bc..a865a0d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,26 +1,15 @@ name: CI on: - push: + pull_request: {} jobs: - release-notes: - name: Release notes preview - runs-on: ubuntu-latest - if: github.ref != 'refs/heads/main' - steps: - - uses: open-turo/actions-release/release-notes-preview@v2 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - extra-plugins: | - @open-turo/semantic-release-config - lint: name: Lint runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 - name: Lint @@ -33,7 +22,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Test uses: ./test with: @@ -44,7 +33,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 - name: Release diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 5c54da3..0f3964f 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 - name: Lint @@ -25,7 +25,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 - name: Release diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 58918a0..3b56d10 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -27,3 +27,10 @@ repos: rev: v1.6.25 hooks: - id: actionlint + - repo: local + hooks: + - id: update-action-readme + name: update-action-readme + entry: ./script/update-action-readme + language: script + files: '.*/action\.yaml$' diff --git a/check-build/README.md b/check-build/README.md index d3fbb05..c638338 100644 --- a/check-build/README.md +++ b/check-build/README.md @@ -17,16 +17,29 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} ``` +## Dist check + +Runs `npm run prepare` and checks to see if there are uncommitted changes. + + + ## Inputs -| parameter | description | required | default | -| ------------ | ------------------------------------------------------------------------- | -------- | ------- | -| github-token | GitHub token that can create/delete comments. e.g. 'secrets.GITHUB_TOKEN' | `true` | | +| parameter | description | required | default | +| --- | --- | --- | --- | +| github-token | GitHub token that can create/delete comments. e.g. 'secrets.GITHUB_TOKEN' | `true` | | + -## Runs + -This action is an `composite` action. + -## Dist check + +## Runs -Runs `npm run prepare` and checks to see if there are uncommitted changes. +This action is a `composite` action. + + + + + diff --git a/lint/README.md b/lint/README.md index 8a9ed94..f7ecf43 100644 --- a/lint/README.md +++ b/lint/README.md @@ -1,8 +1,12 @@ # GitHub Action Lint + + ## Description GitHub Action that runs lint on a GitHub Action + + ## Usage @@ -16,17 +20,6 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} ``` -## Inputs - -| parameter | description | required | default | -| ------------- | ------------------------------------------------------------------------------ | -------- | ------- | -| checkout-repo | Perform checkout as first step of action | `false` | true | -| github-token | GitHub token that can create/delete comments. Usually - 'secrets.GITHUB_TOKEN' | `true` | | - -## Runs - -This action is an `composite` action. - ## Lint Checks This action runs the following lint checks: @@ -41,3 +34,27 @@ This action runs the following lint checks: - It will execute `npm ci` before running the `pre-commit` step. - It will run the `check-build` action. - This expects that `.commitlintrc.yaml` will be present at the root level of the consumer repository to enforce [`conventional-commit`](https://github.com/wagoid/commitlint-github-action). + + + +## Inputs + +| parameter | description | required | default | +| --- | --- | --- | --- | +| checkout-repo | Perform checkout as first step of action | `false` | true | +| github-token | GitHub token that can create/delete comments. Usually - 'secrets.GITHUB_TOKEN' | `true` | | + + + + + + + +## Runs + +This action is a `composite` action. + + + + + diff --git a/lint/action.yaml b/lint/action.yaml index 56bac6b..db6b0fc 100644 --- a/lint/action.yaml +++ b/lint/action.yaml @@ -12,10 +12,13 @@ runs: using: composite steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 if: inputs.checkout-repo == 'true' with: fetch-depth: 0 + - uses: actions/setup-node@v3 + with: + node-version: 18 - name: Run npm ci if needed if: hashFiles('package-lock.json') != '' shell: bash @@ -31,3 +34,6 @@ runs: if: hashFiles('package-lock.json') != '' with: github-token: ${{ inputs.github-token }} + - name: Check release notes on pull_request + if: github.event_name == 'pull_request' + uses: open-turo/actions-release/lint-release-notes@v4 diff --git a/release/README.md b/release/README.md index 0eb2656..b3e123b 100644 --- a/release/README.md +++ b/release/README.md @@ -23,28 +23,39 @@ steps: ``` **IMPORTANT**: `GITHUB_TOKEN` does not have the required permissions to operate on protected branches. -If you are using this action for protected branches, replace `GITHUB_TOKEN` with [Personal Access Token](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line). If using the `@semantic-release/git` plugin for protected branches, avoid persisting credentials as part of `actions/checkout@v3` by setting the parameter `persist-credentials: false`. This credential does not have the required permission to operate on protected branches. +If you are using this action for protected branches, replace `GITHUB_TOKEN` with [Personal Access Token](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line). If using the `@semantic-release/git` plugin for protected branches, avoid persisting credentials as part of `actions/checkout@v4` by setting the parameter `persist-credentials: false`. This credential does not have the required permission to operate on protected branches. + + ## Inputs -| parameter | description | required | default | -| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ---------------------------------- | -| checkout-repo | Perform checkout as first step of action | `false` | true | -| dry-run | Whether to run semantic release in `dry-run` mode. It will override the `dryRun` attribute in your configuration file | `false` | | -| extra-plugins | Extra plugins for pre-install. You can also specify specifying version range for the extra plugins if you prefer. Defaults to install @open-turo/semantic-release-config. | `false` | @open-turo/semantic-release-config | -| github-token | GitHub token that can create/delete comments. e.g. 'secrets.GITHUB_TOKEN' | `false` | | +| parameter | description | required | default | +| --- | --- | --- | --- | +| checkout-repo | Perform checkout as first step of action | `false` | true | +| dry-run | Whether to run semantic release in `dry-run` mode. It will override the `dryRun` attribute in your configuration file | `false` | | +| extra-plugins | Extra plugins for pre-install. You can also specify specifying version range for the extra plugins if you prefer. Defaults to install @open-turo/semantic-release-config. | `false` | @open-turo/semantic-release-config | +| github-token | GitHub token that can create/delete comments. e.g. 'secrets.GITHUB_TOKEN' | `false` | | + + ## Outputs -| parameter | description | -| ------------------------- | ----------------------------------- | -| new-release-published | Whether a new release was published | -| new-release-version | Version of the new release | -| new-release-major-version | Major version of the new release | +| parameter | description | +| --- | --- | +| new-release-published | Whether a new release was published | +| new-release-version | Version of the new release | +| new-release-major-version | Major version of the new release | + + ## Runs -This action is an `composite` action. +This action is a `composite` action. + + + + + ## Additional Examples diff --git a/release/action.yaml b/release/action.yaml index d393720..1fbe23b 100644 --- a/release/action.yaml +++ b/release/action.yaml @@ -33,13 +33,13 @@ runs: using: composite steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 if: inputs.checkout-repo == 'true' with: fetch-depth: 0 - name: Semantic release id: release - uses: open-turo/actions-release/semantic-release@v2 + uses: open-turo/actions-release/semantic-release@v4 env: GITHUB_TOKEN: ${{ inputs.github-token || env.GITHUB_TOKEN }} with: diff --git a/script/update-action-readme b/script/update-action-readme new file mode 100755 index 0000000..00247ce --- /dev/null +++ b/script/update-action-readme @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +set -e + +for i in $*; do + # ignore if the file does not end with /action.yaml + if [[ "$i" != *"/action.yaml" ]]; then + echo "skipping: ${i}" + continue + fi + readme_file=$(dirname "$i")/README.md + echo "npx action-docs --no-banner -a "${i}" --update-readme "${readme_file}"" + npx action-docs --no-banner -a "${i}" --update-readme "${readme_file}" +done diff --git a/test/README.md b/test/README.md index 252ab91..87b5b54 100644 --- a/test/README.md +++ b/test/README.md @@ -16,27 +16,30 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} ``` -## Inputs +## Notes -| parameter | description | required | default | -| ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ------- | -| checkout-repo | Perform checkout as first step of action | `false` | true | -| github-token | GitHub token passed to coveralls. Usually - 'secrets.GITHUB_TOKEN'. Coveralls uses this token to verify the posted coverage data on the consumer repo and create a new check based on the results. It is built into Github Actions and does not need to be manually specified in your secrets store. | `true` | | +- By default, this action will perform actions/checkout as its first step. -## Runs + + +## Inputs -This action is an `composite` action. +| parameter | description | required | default | +| --- | --- | --- | --- | +| checkout-repo | Perform checkout as first step of action | `false` | true | +| github-token | GitHub token passed to coveralls. Usually - 'secrets.GITHUB_TOKEN'. Coveralls uses this token to verify the posted coverage data on the consumer repo and create a new check based on the results. It is built into Github Actions and does not need to be manually specified in your secrets store. | `true` | | + -## Test + -For node based actions, it will run: + -```shell -npm ci -npm test -- --coverage -coveralls -``` + +## Runs -## Notes +This action is a `composite` action. + -- By default, this action will perform actions/checkout as its first step. + + + diff --git a/test/action.yaml b/test/action.yaml index 3fa47e9..0bc9c3d 100644 --- a/test/action.yaml +++ b/test/action.yaml @@ -12,7 +12,7 @@ runs: using: composite steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 if: inputs.checkout-repo == 'true' - name: Test node if: hashFiles('package-lock.json') != ''