diff --git a/.github/workflows/default.yml b/.github/workflows/default.yml new file mode 100644 index 0000000..b373edf --- /dev/null +++ b/.github/workflows/default.yml @@ -0,0 +1,64 @@ +on: + workflow_dispatch: + pull_request: + push: + branches: + - main + +jobs: + test-default: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - id: run + uses: ./ + + - run: test -n "${{ steps.run.outputs.node-build-version }}" + - run: test "${{ steps.run.outputs.node-version }}" = "$(< .node-version)" + + test-with-path: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - id: run + uses: ./ + with: + node-version-path: .nvmrc + + - run: test -n "${{ steps.run.outputs.node-build-version }}" + - run: test "${{ steps.run.outputs.node-version }}" = "$(< .nvmrc)" + + test-with-version: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - id: run + continue-on-error: true + uses: ./ + with: + node-version: 999.999.999 + + - run: test -n "${{ steps.run.outputs.node-build-version }}" + - run: test "${{ steps.run.outputs.node-version }}" = "999.999.999" + - run: test "${{ steps.run.outcome }}" = "failure" + + release: + needs: + - test-default + - test-with-path + - test-with-version + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: cycjimmy/semantic-release-action@v4 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - uses: Actions-R-Us/actions-tagger@v2 + with: + publish_latest_tag: true diff --git a/.node-version b/.node-version new file mode 100644 index 0000000..6569dfa --- /dev/null +++ b/.node-version @@ -0,0 +1 @@ +20.8.1 diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..6569dfa --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +20.8.1 diff --git a/README.md b/README.md new file mode 100644 index 0000000..9c94326 --- /dev/null +++ b/README.md @@ -0,0 +1,57 @@ +[![Test](https://github.com/matzkoh/check-node-version/actions/workflows/test.yml/badge.svg)](https://github.com/matzkoh/check-node-version/actions/workflows/test.yml) + +# matzkoh/check-node-version + +This GitHub Action checks if commands like `nodenv install` will definitely succeed. + +It checks the `node-build` repository, which is the source of the installation, and fails if the target version does not exist. + +## Examples + +### Basic + +```yaml +steps: + - uses: actions/checkout@v4 + with: + sparse-checkout: /.node-version + sparse-checkout-cone-mode: false + + - uses: matzkoh/check-node-version@v1 +``` + +### Optional + +```yaml +steps: + - uses: actions/checkout@v4 + with: + sparse-checkout: /.node-version + sparse-checkout-cone-mode: false + + - id: check-node-version + continue-on-error: true # continue even if the node version is not yet released + uses: matzkoh/check-node-version@v1 + with: + node-version-path: .nvmrc # use a file other than `.node-version` if desired + + - run: echo ${{ steps.check-node-version.outcome == 'success' && 'released 😀' || 'not yet released 😢' }} +``` + +## Inputs + +See [action.yml](action.yml) + +| Name | Description | Default | Required | +| ------------------- | ------------------------------------------------------------------- | --------------- | -------- | +| `node-version-path` | Path to the file containing the node version to check | `.node-version` | ❌ | +| `node-version` | Node version to check. If not specified, it will be read from file. | | ❌ | + +## Outputs + +See [action.yml](action.yml) + +| Name | Description | +| -------------------- | -------------------------------------------------------------------- | +| `node-version` | Same as `node-version` input. Checked version. | +| `node-build-version` | Latest release version of brew `node-build` formula used for checks. | diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..96b8a6a --- /dev/null +++ b/action.yml @@ -0,0 +1,37 @@ +name: check-node-version +description: GitHub Actions to check if node-version has been released and is available via brew node-build. +author: matzkoh + +inputs: + node-version: + description: The version to check + node-version-path: + description: The path to the .node-version file + default: .node-version + +runs: + using: composite + steps: + - id: check + shell: bash + run: | + if [ -n "${{ inputs.node-version }}" ]; then + node-version=${{ inputs.node-version }} + else + node-version=$(< ${{ inputs.node-version-path }}) + fi + + node-build-version=$(curl -s 'https://formulae.brew.sh/api/formula/node-build.json' | jq -r '.versions.stable') + + echo "node-version=${node-version}" >> $GITHUB_OUTPUT + echo "node-build-version=${node-build-version}" >> $GITHUB_OUTPUT + + curl -fsIo /dev/null "https://raw.githubusercontent.com/nodenv/node-build/v${node-build-version}/share/node-build/${node-version}" + +outputs: + node-version: + description: The version in .node-version + value: ${{ steps.check.outputs.node-version }} + node-build-version: + description: The latest node-build version + value: ${{ steps.check.outputs.node-build-version }} diff --git a/release.config.cjs b/release.config.cjs new file mode 100644 index 0000000..3778f45 --- /dev/null +++ b/release.config.cjs @@ -0,0 +1,9 @@ +/** @type {import('semantic-release').GlobalConfig} */ +module.exports = { + branches: ['main'], + plugins: [ + '@semantic-release/commit-analyzer', + '@semantic-release/release-notes-generator', + '@semantic-release/github', + ], +}