release.yml 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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: Copy README for `uppy` package
  30. run: cp README.md packages/uppy/.
  31. - name: Build before publishing
  32. run: corepack yarn run build
  33. - name: Hack to allow the publish of the Angular package
  34. run: corepack yarn workspace @uppy/angular prepublishOnly
  35. - name: Login to NPM
  36. run: corepack yarn config set npmAuthToken ${{ toJSON(secrets.NPM_TOKEN) }}
  37. - name: Publish to NPM
  38. run: corepack yarn workspaces foreach --no-private npm publish --access public --tolerate-republish
  39. - name: Merge PR
  40. id: merge
  41. run: |
  42. gh api -X PUT repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/merge \
  43. -F merge_method="squash" \
  44. -F commit_message="$(cat CHANGELOG.diff.md)" \
  45. --jq 'if .merged then "##[set-output name=sha;]"+.sha else error("not merged") end'
  46. env:
  47. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  48. - name: Create tags
  49. run: |
  50. 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
  51. cat createTags.sh
  52. sh createTags.sh | sh
  53. env:
  54. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  55. - name: Get Uppy version number
  56. id: uppyVersion
  57. run: jq -r '"##[set-output name=version;]"+.version' < packages/uppy/package.json
  58. - name: Create GitHub release
  59. run: gh release create uppy@${{ steps.uppyVersion.outputs.version }} -t "Uppy ${{ steps.uppyVersion.outputs.version }}" -F CHANGELOG.diff.md
  60. env:
  61. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  62. - name: Upload `uppy` to CDN
  63. run: corepack yarn run uploadcdn uppy
  64. env:
  65. EDGLY_KEY: ${{secrets.EDGLY_KEY}}
  66. EDGLY_SECRET: ${{secrets.EDGLY_SECRET}}
  67. - name: Upload `@uppy/robodog` to CDN if it was released
  68. run: git diff --exit-code --quiet HEAD^ -- packages/@uppy/robodog/package.json || corepack yarn run uploadcdn @uppy/robodog
  69. env:
  70. EDGLY_KEY: ${{secrets.EDGLY_KEY}}
  71. EDGLY_SECRET: ${{secrets.EDGLY_SECRET}}
  72. - name: Upload `@uppy/locales` to CDN if it was released
  73. run: git diff --exit-code --quiet HEAD^ -- packages/@uppy/locales/package.json ||corepack yarn run uploadcdn @uppy/locales
  74. env:
  75. EDGLY_KEY: ${{secrets.EDGLY_KEY}}
  76. EDGLY_SECRET: ${{secrets.EDGLY_SECRET}}
  77. - name: Remove release-candidate branch
  78. run: gh api -X DELETE repos/${{ github.repository }}/git/refs/heads/release-candidate || echo "Already deleted"
  79. env:
  80. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  81. - name: Remove release branch
  82. run: gh api -X DELETE repos/${{ github.repository }}/git/refs/heads/release
  83. env:
  84. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  85. - name: Disable Release workflow
  86. run: gh workflow disable Release --repo ${{ github.repository }}
  87. env:
  88. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  89. - name: In case of failure
  90. if: ${{ failure() }}
  91. run: gh pr comment ${{ github.event.pull_request.number }} --body "Release job failed, please take action."
  92. env:
  93. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}