diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..fa65831 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,19 @@ +version: 2 +updates: + - package-ecosystem: npm + versioning-strategy: increase + directory: '/' + schedule: + interval: daily + commit-message: + prefix: fix + prefix-development: chore + include: scope + - package-ecosystem: github-actions + directory: '/' + schedule: + interval: weekly + commit-message: + prefix: fix + prefix-development: chore + include: scope diff --git a/.github/workflows/automerger.yml b/.github/workflows/automerger.yml new file mode 100644 index 0000000..aabbbcd --- /dev/null +++ b/.github/workflows/automerger.yml @@ -0,0 +1,16 @@ +name: 'Auto Merge PRs' + +on: + workflow_call: + +permissions: + pull-requests: write + contents: write + +jobs: + automerge: + runs-on: ubuntu-latest + steps: + - uses: fastify/github-action-merge-dependabot@v3 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml new file mode 100644 index 0000000..7ddd243 --- /dev/null +++ b/.github/workflows/pipeline.yml @@ -0,0 +1,37 @@ +name: 'The Pipeline' + +on: + push: + branches: + - master + pull_request: + branches: + - master + +concurrency: + group: ci-${{ github.ref }}-1 + cancel-in-progress: true + +jobs: + extract-branch: + name: 'Fetch branch' + runs-on: ubuntu-latest + outputs: + current_branch: ${{ steps.get-branch.outputs.current_branch }} + steps: + - name: Extract branch name ๐Ÿ•Š + id: get-branch + run: echo "current_branch=${GITHUB_REF##*/}" >> $GITHUB_OUTPUT + ct: + name: 'CT' + needs: + - extract-branch + uses: ./.github/workflows/test.yml + automerger: + name: 'Automerge Dependabot PRs' + needs: + - ct + - extract-branch + if: > + github.event_name == 'pull_request' && github.event.pull_request.user.login == 'dependabot[bot]' + uses: ./.github/workflows/automerger.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..fb071d4 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,82 @@ +name: 'Build, Test, Release' + +on: + workflow_dispatch: + inputs: + npm_token: + description: 'NPM Token' + required: true + +jobs: + release-check: + name: Check if version is published + runs-on: ubuntu-latest + defaults: + run: + shell: bash + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version-file: 'package.json' + check-latest: true + cache: 'npm' + + - name: Check if version is published + id: check + run: | + currentVersion="$( node -e "console.log(require('./package.json').version)" )" + isPublished="$( npm view @acalcutt/node-pre-gyp-github versions --json | jq -c --arg cv "$currentVersion" 'any(. == $cv)' )" + echo "version=$currentVersion" >> "$GITHUB_OUTPUT" + echo "published=$isPublished" >> "$GITHUB_OUTPUT" + echo "currentVersion: $currentVersion" + echo "isPublished: $isPublished" + outputs: + published: ${{ steps.check.outputs.published }} + version: ${{ steps.check.outputs.version }} + + release: + needs: release-check + if: ${{ needs.release-check.outputs.published == 'false' }} + name: 'Build, Test, Publish' + runs-on: ubuntu-latest + env: + PACKAGE_VERSION: ${{ needs.release-check.outputs.version }} + steps: + - name: Check out repository โœจ + uses: actions/checkout@v4 + + - name: Update apt-get ๐Ÿš€ + run: sudo apt-get update -qq + + - name: Setup node env ๐Ÿ“ฆ + uses: actions/setup-node@v4 + with: + node-version-file: 'package.json' + check-latest: true + cache: 'npm' + + - name: Install npm dependencies ๐Ÿš€ + run: npm ci + + - name: Run tests ๐Ÿงช + run: npm test + + - name: Get release type + id: prepare_release + run: | + RELEASE_TYPE="$(node -e "console.log(require('semver').prerelease('${{ needs.release-check.outputs.version }}') ? 'prerelease' : 'regular')")" + if [[ $RELEASE_TYPE == 'regular' ]]; then + echo "prerelease=false" >> "$GITHUB_OUTPUT" + else + echo "prerelease=true" >> "$GITHUB_OUTPUT" + fi + + - name: Publish to NPM + run: | + npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN} + npm publish --access public --tag ${{ steps.prepare_release.outputs.prerelease == 'true' && 'next' || 'latest' }} + env: + NPM_TOKEN: ${{ github.event.inputs.npm_token }} + diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9b5e62b..5c0da32 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,35 +1,25 @@ name: Test on: - pull_request: - push: - branches: - - master + workflow_call: + jobs: build: runs-on: ubuntu-latest strategy: matrix: - node: [ 18, 20 ] + node: [ 18, 20, 22 ] env: FORCE_COLOR: 1 name: Node ${{ matrix.node }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 0 - - uses: actions/setup-node@v2 - env: - FORCE_COLOR: 0 + - name: Setup node env ๐Ÿ“ฆ + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node }} - cache: npm - + check-latest: true + cache: 'npm' - run: npm install - run: npm test - - - name: Coveralls - uses: coverallsapp/github-action@v2 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - file: './coverage/lcov.info' - flag-name: run-${{ matrix.node }} \ No newline at end of file