release.yml 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. name: Release
  2. on:
  3. pull_request_review:
  4. types: [submitted]
  5. jobs:
  6. release:
  7. name: Publish releases
  8. if: ${{ github.event.review.state == 'approved' && github.event.sender.login == github.event.pull_request.assignee.login && github.event.pull_request.head.ref == 'release-candidate' }}
  9. runs-on: ubuntu-latest
  10. steps:
  11. - name: Checkout sources
  12. uses: actions/checkout@v2
  13. with:
  14. fetch-depth: 2
  15. - name: Cache npm dependencies
  16. id: cache-npm-libraries
  17. uses: actions/cache@v2
  18. with:
  19. path: .yarn/cache/*
  20. key: ${{ runner.os }}
  21. - name: Install Node.js
  22. uses: actions/setup-node@v2
  23. with:
  24. node-version: 16.x
  25. - name: Install dependencies
  26. run: corepack yarn install
  27. - name: Get CHANGELOG diff
  28. run: git --no-pager diff HEAD^ -- CHANGELOG.md | awk '{ if( substr($0,0,1) == "+" && $1 != "+##" && $1 != "+Released:" && $1 != "+++" ) { print substr($0,2) } }' > CHANGELOG.diff.md
  29. - name: Build before publishing
  30. run: corepack yarn run build
  31. - name: Publish to NPM
  32. run: corepack yarn workspaces foreach --no-private npm publish --access public --tolerate-republish
  33. env:
  34. NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
  35. - name: Merge PR
  36. id: merge
  37. run: |
  38. gh api -X PUT repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/merge \
  39. -F merge_method="squash" \
  40. -F commit_message="$(cat CHANGELOG.diff.md)" \
  41. --jq 'if .merged then "##[set-output name=sha;]"+.sha else error("not merged") end'
  42. env:
  43. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  44. - name: Create tags
  45. run: |
  46. git --no-pager diff --name-only HEAD^ | awk '$0 ~ /^packages\/.+\/package\.json$/ { print "jq -r '"'"'\"gh api /repos/{owner}/{repo}/git/refs -f ref=\\\"refs/tags/\"+.name+\"@\"+.version+\"\\\" -f sha=${{ steps.merge.outputs.sha }}\"'"'"' < " $0 }' > createTags.sh
  47. cat createTags.sh
  48. sh createTags.sh | sh
  49. env:
  50. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  51. - name: Get Uppy version number
  52. id: uppyVersion
  53. run: jq -r '"##[set-output name=version;]"+.version' < packages/uppy/package.json
  54. - name: Create GitHub release
  55. run: gh release create uppy@${{ steps.uppyVersion.outputs.version }} -t "Uppy ${{ steps.uppyVersion.outputs.version }}" -F CHANGELOG.diff.md
  56. env:
  57. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  58. - name: Upload `uppy` to CDN
  59. run: corepack yarn run uploadcdn uppy
  60. env:
  61. EDGLY_KEY: ${{secrets.EDGLY_KEY}}
  62. EDGLY_SECRET: ${{secrets.EDGLY_SECRET}}
  63. - name: Upload `@uppy/robodog` to CDN if it was released
  64. run: git diff --exit-code --quiet HEAD^ -- packages/@uppy/robodog/package.json || corepack yarn run uploadcdn @uppy/robodog
  65. env:
  66. EDGLY_KEY: ${{secrets.EDGLY_KEY}}
  67. EDGLY_SECRET: ${{secrets.EDGLY_SECRET}}
  68. - name: Upload `@uppy/locales` to CDN if it was released
  69. if: false
  70. run: git diff --exit-code --quiet HEAD^ -- packages/@uppy/locales/package.json ||corepack yarn run uploadcdn @uppy/locales
  71. env:
  72. EDGLY_KEY: ${{secrets.EDGLY_KEY}}
  73. EDGLY_SECRET: ${{secrets.EDGLY_SECRET}}
  74. - name: Remove release-candidate branch
  75. run: gh api -X DELETE repos/${{ github.repository }}/git/refs/heads/release-candidate
  76. env:
  77. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  78. - name: Remove release branch
  79. run: gh api -X DELETE repos/${{ github.repository }}/git/refs/heads/release
  80. env:
  81. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  82. - name: Disable Release workflow
  83. run: gh workflow disable Release --repo ${{ github.repository }}
  84. env:
  85. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  86. - name: In case of failure
  87. if: ${{ failure() }}
  88. run: gh pr comment ${{ github.event.pull_request.number }} --body "Release job failed, please take action."
  89. env:
  90. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}