From 70080a48d91e88a81a85266ca810b190e54e03b9 Mon Sep 17 00:00:00 2001 From: yi_Xu Date: Tue, 23 Mar 2021 12:10:42 +0800 Subject: [PATCH] =?UTF-8?q?ci(actions):=20=E2=9C=A8=20add=20prepare-releas?= =?UTF-8?q?e=20workflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/prepare-release.yml | 107 ++++++++++++++++++++++++++ .husky/pre-commit | 2 +- .prettierrc.js | 22 +++++- package.json | 4 +- 4 files changed, 130 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/prepare-release.yml diff --git a/.github/workflows/prepare-release.yml b/.github/workflows/prepare-release.yml new file mode 100644 index 0000000..0b4b730 --- /dev/null +++ b/.github/workflows/prepare-release.yml @@ -0,0 +1,107 @@ +name: 'prepare release' +on: + workflow_run: + workflows: ['release'] + branches: [main] + types: + - completed + push: + branches: + - main + +env: + BASE_BRANCH: 'main' + HEAD_BRANCH: 'prepare-release' + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +jobs: + build: + name: Prepare release + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2.3.4 + with: + fetch-depth: 0 + + - name: Setup nodejs + uses: actions/setup-node@v2.1.5 + with: + node-version: 12 + + - uses: actions/cache@v2.1.4 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + + - name: Bump version + run: | + npx standard-version --skip.commit --skip.tag + sed 's/^### \[/## [/' -i CHANGELOG.md + npx prettier --write 'CHANGELOG.md' --prose-wrap never --ignore-path './gitignore' + + - name: Get version from package.json + uses: actions/github-script@v3.1.0 + id: version + with: + result-encoding: string + script: | + const version = require(`${process.env.GITHUB_WORKSPACE}/package.json`).version; + core.setOutput('repo', context.repo.repo); + core.setOutput('version', version); + core.setOutput('title', 'chore(release): :bookmark: release v' + version); + + - name: Create commit + run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + git add . + git commit -m 'chore(release): :bookmark: release v${{steps.version.outputs.version}}' + git branch -D '${{ env.HEAD_BRANCH }}' 2>&1 | sed 's/error/warning/' + git checkout -b '${{ env.HEAD_BRANCH }}' + git remote set-url origin 'https://x-access-token:${{secrets.GITHUB_TOKEN}}@github.com/${{github.repository}}.git' + git push -f -u origin '${{ env.HEAD_BRANCH }}' + + - name: Get Changelog Entry + id: changelog_reader + uses: mindsers/changelog-reader-action@v2.0.0 + with: + version: ${{steps.version.outputs.version}} + path: ./CHANGELOG.md + + - name: Get Changelog + uses: actions/github-script@v3.1.0 + id: changelog + env: + CHANGELOG: ${{ steps.changelog_reader.outputs.changes }} + with: + script: return process.env.CHANGELOG; + + - name: Create pull request + run: | + curl \ + -X POST \ + -H 'authorization: token ${{secrets.GITHUB_TOKEN}}' \ + -H 'Accept: application/vnd.github.v3+json' \ + 'https://api.github.com/repos/${{github.repository}}/pulls' \ + -d '{"head":"${{ env.HEAD_BRANCH }}","base":"${{ env.BASE_BRANCH }}","title":"${{steps.version.outputs.title}}","body":${{steps.CHANGELOG.outputs.result}},"maintainer_can_modify":true}' + + - name: Find pull request + uses: juliangruber/find-pull-request-action@v1.4.0 + id: find-pull-request + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + branch: ${{ env.HEAD_BRANCH }} + + - name: Update pull request + env: + NUMBER: ${{ steps.find-pull-request.outputs.number }} + run: | + curl \ + -X PATCH \ + -H 'authorization: token ${{secrets.GITHUB_TOKEN}}' \ + -H 'Accept: application/vnd.github.v3+json' \ + 'https://api.github.com/repos/${{github.repository}}/pulls/${{ env.NUMBER }}' \ + -d '{"base":"${{ env.BASE_BRANCH }}","title":"${{steps.version.outputs.title}}","body":${{steps.CHANGELOG.outputs.result}}}' diff --git a/.husky/pre-commit b/.husky/pre-commit index c0a3b1e..c70c608 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,4 @@ #!/bin/sh . "$(dirname "$0")/_/husky.sh" -npx --no-install lint-staged && npm run lint-check \ No newline at end of file +npx --no-install lint-staged \ No newline at end of file diff --git a/.prettierrc.js b/.prettierrc.js index 8671bd9..78d7b0c 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -1,22 +1,42 @@ +// .prettierrc.js module.exports = { + // max 120 characters per line printWidth: 120, + // use 2 spaces for indentation tabWidth: 2, + // use spaces instead of indentations useTabs: false, + // semicolon at the end of the line semi: true, + // use single quotes singleQuote: true, + // object's key is quoted only when necessary quoteProps: 'as-needed', + // use double quotes instead of single quotes in jsx jsxSingleQuote: false, + // no comma at the end trailingComma: 'all', + // spaces are required at the beginning and end of the braces bracketSpacing: true, + // end tag of jsx need to wrap jsxBracketSameLine: false, + // brackets are required for arrow function parameter, even when there is only one parameter arrowParens: 'always', + // format the entire contents of the file rangeStart: 0, rangeEnd: Infinity, + // no need to write the beginning @prettier of the file requirePragma: false, + // No need to automatically insert @prettier at the beginning of the file insertPragma: false, + // use default break criteria proseWrap: 'preserve', + // decide whether to break the html according to the display style htmlWhitespaceSensitivity: 'css', + // vue files script and style tags indentation vueIndentScriptAndStyle: false, + // lf for newline endOfLine: 'lf', + // formats quoted code embedded embeddedLanguageFormatting: 'auto', -}; \ No newline at end of file +}; diff --git a/package.json b/package.json index 531d602..970c05a 100644 --- a/package.json +++ b/package.json @@ -6,9 +6,7 @@ "types": "lib/src/index.d.ts", "private": false, "scripts": { - "postinstall": "husky install", - "prepublishOnly": "pinst --disable", - "postpublish": "pinst --enable", + "prepare": "husky install", "build": "npm run compile", "compile": "rimraf lib/ && tsc", "precompile": "npm run lint && npm run lint-check",