From 7683d3453d886ee6e6f751a693077a62c27ec88d Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Thu, 1 Aug 2024 22:12:46 +0200 Subject: [PATCH] ci: add automate release --- .github/workflows/main.yml | 69 ++++++++++++++++++++++++++++++ .github/workflows/pull_request.yml | 36 ++++++++++++++++ package.json | 4 +- 3 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/main.yml create mode 100644 .github/workflows/pull_request.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..070eac7 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,69 @@ +name: main + +on: + push: + branches: + - master + +jobs: + contributors: + if: "${{ github.event.head_commit.message != 'build: contributors' }}" + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: lts/* + - name: Contributors + run: | + git config --global user.email ${{ secrets.GIT_EMAIL }} + git config --global user.name ${{ secrets.GIT_USERNAME }} + npm run contributors + - name: Push changes + run: | + git push origin ${{ github.head_ref }} + + release: + if: | + !startsWith(github.event.head_commit.message, 'chore(release):') && + !startsWith(github.event.head_commit.message, 'docs:') && + !startsWith(github.event.head_commit.message, 'ci:') + needs: [contributors] + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 2 + token: ${{ secrets.GITHUB_TOKEN }} + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: lts/* + - name: Setup PNPM + uses: pnpm/action-setup@v4 + with: + version: latest + run_install: true + - name: Test + run: pnpm test + - name: Report + run: npx c8 report --reporter=text-lcov > coverage/lcov.info + - name: Coverage + uses: coverallsapp/github-action@main + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + - name: Release + env: + GH_TOKEN: ${{ secrets.GH_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + run: | + git config --global user.email ${{ secrets.GIT_EMAIL }} + git config --global user.name ${{ secrets.GIT_USERNAME }} + git pull origin master + pnpm run release diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml new file mode 100644 index 0000000..268a2b1 --- /dev/null +++ b/.github/workflows/pull_request.yml @@ -0,0 +1,36 @@ +name: pull_request + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + test: + if: github.ref != 'refs/heads/master' + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: lts/* + - name: Setup PNPM + uses: pnpm/action-setup@v4 + with: + version: latest + run_install: true + - name: Test + run: pnpm test + - name: Report + run: npx c8 report --reporter=text-lcov > coverage/lcov.info + - name: Coverage + uses: coverallsapp/github-action@main + with: + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/package.json b/package.json index e4b400f..70d3c4a 100644 --- a/package.json +++ b/package.json @@ -40,12 +40,12 @@ "@ksmithut/prettier-standard": "latest", "ava": "latest", "c8": "latest", + "ci-publish": "latest", "finepack": "latest", "git-authors-cli": "latest", "github-generate-release": "latest", "nano-staged": "latest", "npm-check-updates": "latest", - "pretty-ms": "7", "simple-git-hooks": "latest", "standard": "latest", "standard-markdown": "latest", @@ -63,7 +63,7 @@ "contributors": "(npx git-authors-cli && npx finepack && git add package.json && git commit -m 'build: contributors' --no-verify) || true", "coverage": "c8 report --reporter=text-lcov > coverage/lcov.info", "lint": "standard-markdown README.md && standard", - "postrelease": "npm run release:tags && npm run release:github && npm publish", + "postrelease": "npm run release:tags && npm run release:github && (ci-publish || npm publish --access=public)", "prerelease": "npm run update:check", "pretest": "npm run lint", "release": "standard-version -a",