release.yml 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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@v3
  13. with:
  14. fetch-depth: 2
  15. - name: Get yarn cache directory path
  16. id: yarn-cache-dir-path
  17. run: echo "::set-output name=dir::$(corepack yarn config get cacheFolder)"
  18. - uses: actions/cache@v3
  19. id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
  20. with:
  21. path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
  22. key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
  23. restore-keys: |
  24. ${{ runner.os }}-yarn-
  25. - name: Install Node.js
  26. uses: actions/setup-node@v3
  27. with:
  28. node-version: lts/*
  29. - name: Install dependencies
  30. run: corepack yarn install --immutable
  31. - name: Get CHANGELOG diff
  32. 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
  33. - name: Copy README for `uppy` package
  34. run: cp README.md packages/uppy/.
  35. - name: Build before publishing
  36. run: corepack yarn run build
  37. - name: Hack to allow the publish of the Angular package
  38. run: corepack yarn workspace @uppy/angular prepublishOnly
  39. - name: Login to NPM
  40. run: corepack yarn config set npmAuthToken ${{ toJSON(secrets.NPM_TOKEN) }}
  41. - name: Publish to NPM
  42. run: corepack yarn workspaces foreach --no-private npm publish --access public --tag next --tolerate-republish
  43. - name: Merge PR
  44. id: merge
  45. run: |
  46. gh api -X PUT repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/merge \
  47. -F merge_method="squash" \
  48. -F commit_message="$(cat CHANGELOG.diff.md)" \
  49. --jq 'if .merged then "##[set-output name=sha;]"+.sha else error("not merged") end'
  50. env:
  51. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  52. - name: Create tags
  53. run: |
  54. 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
  55. cat createTags.sh
  56. sh createTags.sh | sh
  57. env:
  58. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  59. - name: Get Uppy version number
  60. id: uppyVersion
  61. run: jq -r '"##[set-output name=version;]"+.version' < packages/uppy/package.json
  62. - name: Create GitHub release
  63. run: gh release create uppy@${{ steps.uppyVersion.outputs.version }} -t "Uppy ${{ steps.uppyVersion.outputs.version }}" -F CHANGELOG.diff.md --prerelease
  64. env:
  65. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  66. - name: Upload `uppy` to CDN
  67. run: corepack yarn run uploadcdn uppy
  68. env:
  69. EDGLY_KEY: ${{secrets.EDGLY_KEY}}
  70. EDGLY_SECRET: ${{secrets.EDGLY_SECRET}}
  71. - name: Upload `@uppy/robodog` to CDN if it was released
  72. run: git diff --exit-code --quiet HEAD^ -- packages/@uppy/robodog/package.json || corepack yarn run uploadcdn @uppy/robodog
  73. env:
  74. EDGLY_KEY: ${{secrets.EDGLY_KEY}}
  75. EDGLY_SECRET: ${{secrets.EDGLY_SECRET}}
  76. - name: Upload `@uppy/locales` to CDN if it was released
  77. run: git diff --exit-code --quiet HEAD^ -- packages/@uppy/locales/package.json ||corepack yarn run uploadcdn @uppy/locales
  78. env:
  79. EDGLY_KEY: ${{secrets.EDGLY_KEY}}
  80. EDGLY_SECRET: ${{secrets.EDGLY_SECRET}}
  81. - name: Remove release-candidate branch
  82. run: gh api -X DELETE repos/${{ github.repository }}/git/refs/heads/release-candidate || echo "Already deleted"
  83. env:
  84. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  85. - name: Remove release-beta branch
  86. run: gh api -X DELETE repos/${{ github.repository }}/git/refs/heads/release-beta
  87. env:
  88. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  89. - name: Disable Release workflow
  90. run: gh workflow disable Release --repo ${{ github.repository }}
  91. env:
  92. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  93. - name: In case of failure
  94. if: ${{ failure() }}
  95. run: gh pr comment ${{ github.event.pull_request.number }} --body "Release job failed, please take action."
  96. env:
  97. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}