release.yml 4.5 KB

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