|
| 1 | +name: "CD" |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + release-type: |
| 7 | + description: "Type of release?" |
| 8 | + required: true |
| 9 | + type: choice |
| 10 | + options: |
| 11 | + - patch |
| 12 | + - minor |
| 13 | + - major |
| 14 | + |
| 15 | +jobs: |
| 16 | + release: |
| 17 | + name: "Release" |
| 18 | + if: ${{ github.ref == 'refs/heads/master' }} |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - name: "Checkout code" |
| 22 | + uses: actions/checkout@v2 |
| 23 | + with: |
| 24 | + token: ${{ secrets.GH_PAT }} |
| 25 | + |
| 26 | + - name: "Set up Node" |
| 27 | + uses: actions/setup-node@v2 |
| 28 | + with: |
| 29 | + node-version: '12' |
| 30 | + cache: 'yarn' |
| 31 | + |
| 32 | + - name: "Install dependencies" |
| 33 | + run: yarn install --frozen-lockfile |
| 34 | + |
| 35 | + - name: "Build the sources" |
| 36 | + run: yarn build |
| 37 | + |
| 38 | + - name: "Publish to npm" |
| 39 | + id: publish |
| 40 | + run: | |
| 41 | + yarn publish:all ${{ github.event.inputs.release-type }} |
| 42 | + echo "::set-output name=version::$(node --print 'require("./lerna.json").version')" |
| 43 | + env: |
| 44 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 45 | + |
| 46 | + - name: "Update the changelog" |
| 47 | + # Find the first line that starts with `###` or `## [<number>` from the CHANGELOG and insert the new version header before it. |
| 48 | + run: | |
| 49 | + current_date="$(date -u '+%Y-%m-%d')" |
| 50 | + sed -i "0,/^\(###\|## *\[[0-9]\).*/{s//## [${{ steps.publish.outputs.version }}] - ${current_date}\n\n&/}" CHANGELOG.md |
| 51 | +
|
| 52 | + - name: "Extract version's changelog for release notes" |
| 53 | + # 1. Find the lines between the first `## [<number>` and the second `## [<number>`. |
| 54 | + # 2. Remove all leading and trailing newlines from the output. |
| 55 | + run: sed '1,/^## *\[[0-9]/d;/^## *\[[0-9]/Q' CHANGELOG.md | sed -e :a -e '/./,$!d;/^\n*$/{$d;N;};/\n$/ba' > release_notes.txt |
| 56 | + |
| 57 | + - name: "Commit and tag the changes" |
| 58 | + uses: EndBug/add-and-commit@8c12ff729a98cfbcd3fe38b49f55eceb98a5ec02 # v7.5.0 |
| 59 | + with: |
| 60 | + add: '["lerna.json", "*package.json", "CHANGELOG.md"]' |
| 61 | + message: 'Release ${{ steps.publish.outputs.version }}' |
| 62 | + tag: 'v${{ steps.publish.outputs.version }} --annotate --file /dev/null' |
| 63 | + default_author: github_actions |
| 64 | + pathspec_error_handling: exitImmediately |
| 65 | + |
| 66 | + - name: "Create a GitHub release" |
| 67 | + uses: softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5 # v1 |
| 68 | + with: |
| 69 | + tag_name: v${{ steps.publish.outputs.version }} |
| 70 | + name: v${{ steps.publish.outputs.version }} |
| 71 | + body_path: release_notes.txt |
0 commit comments