Skip to content

Commit

Permalink
ci(actions): ✨ add prepare-release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
yi-Xu-0100 committed Mar 23, 2021
1 parent 220d6c3 commit 70080a4
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 5 deletions.
107 changes: 107 additions & 0 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
with:
fetch-depth: 0

- name: Setup nodejs
uses: actions/[email protected]
with:
node-version: 12

- uses: actions/[email protected]
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/[email protected]
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/[email protected]
with:
version: ${{steps.version.outputs.version}}
path: ./CHANGELOG.md

- name: Get Changelog
uses: actions/[email protected]
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/[email protected]
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}}}'
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no-install lint-staged && npm run lint-check
npx --no-install lint-staged
22 changes: 21 additions & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
@@ -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',
};
};
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 70080a4

Please sign in to comment.