release.yml 6.7 KB

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