From 51bbd628b7155bc5d58b9149babe33a61869ff33 Mon Sep 17 00:00:00 2001 From: sonologico <1592315+sonologico@users.noreply.github.com> Date: Mon, 8 Aug 2022 09:45:51 +0200 Subject: [PATCH] Automated release setup (#170) --- .github/PULL_REQUEST_TEMPLATE.md | 14 ++++++ .github/workflows/release.yml | 82 ++++++++++++++++++++++++++++++++ .github/workflows/release_pr.yml | 42 ++++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/release_pr.yml diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..b224e37 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,14 @@ +## What does this PR do? + +[Description here] + +## Checklist + +- [ ] All new functionality has tests. +- [ ] All tests are passing. +- [ ] New or changed API methods have been documented. +- [ ] `npm run format` has been run + +## CHANGELOG + +- [CHANGED] Describe your change here. Look at CHANGELOG.md to see the format. diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..d8dd279 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,82 @@ +on: + push: + branches: [master] + +jobs: + check-release-tag: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Prepare tag + id: prepare_tag + continue-on-error: true + run: | + export TAG=v$(jq -r '.version' package.json) + echo "TAG=$TAG" >> $GITHUB_ENV + + export CHECK_TAG=$(git tag | grep $TAG) + if [[ $CHECK_TAG ]]; then + echo "Skipping because release tag already exists" + exit 1 + fi + - name: Output + id: release_output + if: ${{ steps.prepare_tag.outcome == 'success' }} + run: | + echo "::set-output name=tag::${{ env.TAG }}" + outputs: + tag: ${{ steps.release_output.outputs.tag }} + + create-github-release: + runs-on: ubuntu-latest + needs: check-release-tag + if: ${{ needs.check-release-tag.outputs.tag }} + steps: + - uses: actions/checkout@v2 + - name: Prepare tag + run: | + export TAG=v$(jq -r '.version' package.json) + echo "TAG=$TAG" >> $GITHUB_ENV + - name: Setup git + run: | + git config user.email "pusher-ci@pusher.com" + git config user.name "Pusher CI" + - name: Prepare description + run: | + csplit -s CHANGELOG.md "/##/" {1} + cat xx01 > CHANGELOG.tmp + - name: Create Release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ env.TAG }} + release_name: ${{ env.TAG }} + body_path: CHANGELOG.tmp + draft: false + prerelease: false + + publish-to-npm: + runs-on: ubuntu-latest + needs: create-github-release + steps: + - uses: actions/checkout@v2 + - uses: flood-io/is-published-on-npm@8478347e2650eb228d303975415458183d0a37e4 + id: is-published + - run: echo "This version is already published on NPM" + if: ${{ steps.is-published.outputs.published == 'true' }} + - uses: actions/setup-node@v2 + if: ${{ steps.is-published.outputs.published == 'false' }} + with: + node-version: "14" + registry-url: https://registry.npmjs.org/ + - run: npm install + if: ${{ steps.is-published.outputs.published == 'false' }} + - run: npm publish --access public + if: ${{ steps.is-published.outputs.published == 'false' }} + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/release_pr.yml b/.github/workflows/release_pr.yml new file mode 100644 index 0000000..bb64927 --- /dev/null +++ b/.github/workflows/release_pr.yml @@ -0,0 +1,42 @@ +name: release + +on: + pull_request: + types: [labeled] + branches: + - master + +jobs: + prepare-release: + name: Prepare release + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Get current version + shell: bash + run: | + CURRENT_VERSION=$(jq -r '.version' package.json) + echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV + - uses: actions/checkout@v2 + with: + repository: pusher/actions + token: ${{ secrets.PUSHER_CI_GITHUB_PRIVATE_TOKEN }} + path: .github/actions + - uses: ./.github/actions/prepare-version-bump + id: bump + with: + current_version: ${{ env.CURRENT_VERSION }} + - uses: actions/setup-node@v2 + with: + node-version: "14" + - run: npm install + - name: Push + shell: bash + run: | + echo "$(jq '.version = "${{ steps.bump.outputs.new_version }}"' package.json)" > package.json + + make build_all + + git add package.json CHANGELOG.md dist/ + git commit -m "Bump to version ${{ steps.bump.outputs.new_version }}" + git push