From b02c0513ce35b8388e8d50f0f2d6208717a1dc4f Mon Sep 17 00:00:00 2001 From: Patrick Mowrer Date: Thu, 11 Jan 2024 23:37:54 -0500 Subject: [PATCH] ci: migrate from travis to github actions --- .github/workflows/release-preview.yml | 13 +++++++++++++ .github/workflows/release.yml | 22 ++++++++++++++++++++++ .github/workflows/tests.yml | 11 +++++++++++ bin/semantic-release-github-pr.js | 6 +----- 4 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/release-preview.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/release-preview.yml b/.github/workflows/release-preview.yml new file mode 100644 index 0000000..c7a011c --- /dev/null +++ b/.github/workflows/release-preview.yml @@ -0,0 +1,13 @@ +name: Release preview +on: [pull_request] +jobs: + release-preview: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + # semantic-release dry-run workaround https://github.com/semantic-release/semantic-release/issues/1890#issuecomment-974512960 + - run: git checkout -b ${{ github.head_ref }} + - run: unset GITHUB_ACTIONS && yarn && node ./bin/semantic-release-github-pr --debug --branches ${{ github.head_ref }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..241a16f --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,22 @@ +name: Release + +on: + pull_request: + branches: + - master + types: + - closed + +jobs: + release: + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + - run: npx semantic-release --debug \ No newline at end of file diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..bc23f0c --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,11 @@ +name: Tests +on: [pull_request] +jobs: + run-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + - run: yarn && yarn test diff --git a/bin/semantic-release-github-pr.js b/bin/semantic-release-github-pr.js index 83a3f11..4c4c4d7 100755 --- a/bin/semantic-release-github-pr.js +++ b/bin/semantic-release-github-pr.js @@ -1,16 +1,12 @@ #!/usr/bin/env node const execa = require('execa'); -const envCi = require('env-ci'); const { argv } = process; const { resolve } = require('path'); const { getCurrentBranchName } = require('../src/git-utils'); (async function() { const plugins = `${resolve(__dirname, '../src/index.js')}`; - const currentBranchName = await getCurrentBranchName(); - // If we're in a "detached HEAD" state, assume we're running on CI. - const branch = - currentBranchName !== 'HEAD' ? currentBranchName : envCi().prBranch; + const branch = await getCurrentBranchName(); const args = argv.slice(2).concat([ // We want to run on pull request builds, but `semantic-release` won't