release.yml 6.7 KB

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