release.yml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. name: Release
  2. on:
  3. pull_request_review:
  4. types: [submitted]
  5. env:
  6. YARN_ENABLE_GLOBAL_CACHE: false
  7. jobs:
  8. release:
  9. name: Publish releases
  10. if:
  11. ${{ github.event.review.state == 'approved' && github.event.sender.login
  12. == github.event.pull_request.assignee.login &&
  13. github.event.pull_request.head.ref == 'release-candidate' }}
  14. outputs:
  15. companionWasReleased:
  16. ${{ steps.checkIfCompanionWasReleased.outputs.version }}
  17. runs-on: ubuntu-latest
  18. steps:
  19. - name: Checkout sources
  20. uses: actions/checkout@v4
  21. with:
  22. fetch-depth: 2
  23. - name: Get yarn cache directory path
  24. id: yarn-cache-dir-path
  25. run:
  26. echo "dir=$(corepack yarn config get cacheFolder)" >> $GITHUB_OUTPUT
  27. - uses: actions/cache@v4
  28. id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
  29. with:
  30. path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
  31. key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
  32. restore-keys: |
  33. ${{ runner.os }}-yarn-
  34. - name: Install Node.js
  35. uses: actions/setup-node@v4
  36. with:
  37. node-version: lts/*
  38. - name: Install dependencies
  39. run: corepack yarn install --immutable
  40. env:
  41. # https://docs.cypress.io/guides/references/advanced-installation#Skipping-installation
  42. CYPRESS_INSTALL_BINARY: 0
  43. - name: Get CHANGELOG diff
  44. run:
  45. git --no-pager diff HEAD^ -- CHANGELOG.md | awk '{ if( substr($0,0,1)
  46. == "+" && $1 != "+##" && $1 != "+Released:" && $1 != "+++" ) { print
  47. substr($0,2) } }' > CHANGELOG.diff.md
  48. - name: Copy README for `uppy` package
  49. run: cp README.md packages/uppy/.
  50. - name: Build before publishing
  51. run: corepack yarn run build
  52. - name: Hack to allow the publish of the Angular package
  53. run: corepack yarn workspace @uppy/angular prepublishOnly
  54. - name: Publish to the npm registry
  55. run:
  56. corepack yarn workspaces foreach --all --no-private npm publish
  57. --access public --tolerate-republish
  58. env:
  59. YARN_NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
  60. - name: Merge PR
  61. id: merge
  62. run: |
  63. gh api -X PUT repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/merge \
  64. -F merge_method="squash" \
  65. -F commit_message="$(cat CHANGELOG.diff.md)" \
  66. --jq 'if .merged then "sha="+.sha else error("not merged") end' >> $GITHUB_OUTPUT
  67. env:
  68. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  69. - name: Create tags
  70. run: |
  71. 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
  72. cat createTags.sh
  73. sh createTags.sh | sh
  74. env:
  75. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  76. - name: Get Uppy version number
  77. id: uppyVersion
  78. run:
  79. jq -r '"version="+.version' < packages/uppy/package.json >>
  80. $GITHUB_OUTPUT
  81. - name: Create GitHub release
  82. run:
  83. gh release create uppy@${{ steps.uppyVersion.outputs.version }} -t
  84. "Uppy ${{ steps.uppyVersion.outputs.version }}" -F CHANGELOG.diff.md
  85. env:
  86. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  87. - name: Upload `uppy` to CDN
  88. run: corepack yarn run uploadcdn uppy
  89. env:
  90. EDGLY_KEY: ${{secrets.EDGLY_KEY}}
  91. EDGLY_SECRET: ${{secrets.EDGLY_SECRET}}
  92. - name: Upload `@uppy/locales` to CDN if it was released
  93. run:
  94. git diff --exit-code --quiet HEAD^ --
  95. packages/@uppy/locales/package.json ||corepack yarn run uploadcdn
  96. @uppy/locales
  97. env:
  98. EDGLY_KEY: ${{secrets.EDGLY_KEY}}
  99. EDGLY_SECRET: ${{secrets.EDGLY_SECRET}}
  100. - name: Check if Companion was released
  101. id: checkIfCompanionWasReleased
  102. run:
  103. git diff --exit-code --quiet HEAD^ --
  104. packages/@uppy/companion/package.json || echo "version=$(jq -r
  105. .version < packages/@uppy/companion/package.json)" >> $GITHUB_OUTPUT
  106. - name: Remove release-candidate branch
  107. run:
  108. gh api -X DELETE repos/${{ github.repository
  109. }}/git/refs/heads/release-candidate || echo "Already deleted"
  110. env:
  111. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  112. - name: Remove release branch
  113. run:
  114. gh api -X DELETE repos/${{ github.repository }}/git/refs/heads/release
  115. env:
  116. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  117. - name: Disable Release workflow
  118. run: gh workflow disable Release --repo ${{ github.repository }}
  119. env:
  120. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  121. - name: In case of failure
  122. if: ${{ failure() }}
  123. run:
  124. gh pr comment ${{ github.event.pull_request.number }} --body "Release
  125. job failed, please take action."
  126. env:
  127. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  128. # See also companion-deploy.yml
  129. docker:
  130. name: DockerHub
  131. needs: release
  132. if: ${{ needs.release.outputs.companionWasReleased }}
  133. runs-on: ubuntu-latest
  134. env:
  135. DOCKER_BUILDKIT: 0
  136. COMPOSE_DOCKER_CLI_BUILD: 0
  137. steps:
  138. - name: Checkout sources
  139. uses: actions/checkout@v4
  140. - name: Docker meta
  141. id: docker_meta
  142. uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
  143. with:
  144. images: transloadit/companion
  145. tags: |
  146. type=edge
  147. type=semver,pattern={{version}},value=${{ needs.release.outputs.companionWasReleased }}
  148. # set latest tag for default branch
  149. type=raw,value=latest,enable=true
  150. - uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0
  151. - uses: docker/setup-buildx-action@v3
  152. - name: Log in to DockerHub
  153. uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
  154. with:
  155. username: ${{secrets.DOCKER_USERNAME}}
  156. password: ${{secrets.DOCKER_PASSWORD}}
  157. - name: Build and push
  158. uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6.9.0
  159. with:
  160. push: true
  161. context: .
  162. platforms: linux/amd64,linux/arm64
  163. file: Dockerfile
  164. tags: ${{ steps.docker_meta.outputs.tags }}
  165. labels: ${{ steps.docker_meta.outputs.labels }}