test-and-release.yml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. # This workflow will do a clean install of node dependencies, build the source
  2. # code and run tests across different versions of node.
  3. #
  4. # In case there is a new version in package.json and it's the main branch, it
  5. # will also tag and release this version.
  6. name: Test and Release
  7. on:
  8. push:
  9. branches: [ main ]
  10. pull_request:
  11. branches: [ main ]
  12. jobs:
  13. test:
  14. name: Test
  15. runs-on: ubuntu-latest
  16. steps:
  17. - name: Setup Node.js environment
  18. uses: actions/setup-node@v2.1.1
  19. - name: Checkout Dropzone
  20. uses: actions/checkout@v2
  21. - run: yarn install
  22. - run: yarn test
  23. # Auto tag when the package.json version has changed. A different job will see
  24. # this tag, publish it, and create a release for it.
  25. tag:
  26. name: Tag if package.json version increased
  27. runs-on: ubuntu-latest
  28. if: github.ref == 'refs/heads/main'
  29. needs: [test]
  30. outputs:
  31. tagname: ${{ steps.auto_tag.outputs.tagname }}
  32. steps:
  33. - name: Checkout Dropzone
  34. uses: actions/checkout@v2
  35. - name: Auto tag
  36. id: auto_tag
  37. uses: Klemensas/action-autotag@1.2.3
  38. env:
  39. GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
  40. with:
  41. tag_prefix: v
  42. tag_message: "Please check the changelog for a list of changes"
  43. build:
  44. name: Build dist files
  45. runs-on: ubuntu-latest
  46. if: github.ref == 'refs/heads/main'
  47. needs: [test]
  48. steps:
  49. - name: Setup Node.js environment
  50. uses: actions/setup-node@v2.1.1
  51. - name: Checkout Dropzone
  52. uses: actions/checkout@v2
  53. - run: yarn install
  54. - name: Read package.json version
  55. uses: pchynoweth/action-get-npm-version@1.0.1
  56. id: package_version
  57. - name: Inject package version into javascript file
  58. uses: jacobtomlinson/gha-find-replace@master
  59. id: version_replace
  60. with:
  61. include: "src/dropzone.js"
  62. find: "version = \"dev\""
  63. replace: "version = \"${{ steps.package_version.outputs.version }}\""
  64. - name: Abort if version wasn't replaced
  65. if: steps.version_replace.outputs.modifiedFiles != 1
  66. run: exit 1
  67. - run: yarn build
  68. - name: Upload dist folder in case of release
  69. uses: actions/upload-artifact@v2
  70. with:
  71. name: dist
  72. path: dist
  73. release:
  74. name: Create GitHub release
  75. runs-on: ubuntu-latest
  76. needs: [build, tag]
  77. if: github.ref == 'refs/heads/main' && needs.tag.outputs.tagname != null
  78. steps:
  79. - name: Checkout Dropzone
  80. uses: actions/checkout@v2
  81. - name: Download dist folder
  82. uses: actions/download-artifact@v2
  83. with:
  84. name: dist
  85. path: dist
  86. - name: Compress dist folder
  87. run: zip dist -r dist
  88. - name: Release
  89. id: create_release
  90. uses: actions/create-release@v1
  91. env:
  92. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  93. with:
  94. tag_name: "${{ needs.tag.outputs.tagname }}"
  95. release_name: "Release ${{ needs.tag.outputs.tagname }}"
  96. body: "Please check the [changelog](https://github.com/dropzone/dropzone/blob/${{ github.sha }}/CHANGELOG.md) for a list of changes"
  97. draft: false
  98. prerelease: false
  99. - name: Upload Release Asset
  100. id: upload-release-asset
  101. uses: actions/upload-release-asset@v1
  102. env:
  103. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  104. with:
  105. upload_url: ${{ steps.create_release.outputs.upload_url }}
  106. asset_path: ./dist.zip
  107. asset_name: dist.zip
  108. asset_content_type: application/zip
  109. npm-publish:
  110. name: Publish new version to npm
  111. runs-on: ubuntu-latest
  112. needs: [build,release]
  113. steps:
  114. - name: Checkout Dropzone
  115. uses: actions/checkout@v2
  116. - name: Download dist folder
  117. uses: actions/download-artifact@v2
  118. with:
  119. name: dist
  120. path: dist
  121. - name: Publish
  122. uses: JS-DevTools/npm-publish@v1
  123. with:
  124. token: ${{ secrets.NPM_TOKEN }}
  125. trigger-remote-releases:
  126. name: Dispatch the "new-release" event to packagist and bower repo
  127. runs-on: ubuntu-latest
  128. needs: [tag,release]
  129. steps:
  130. - name: Dispatch "new-release" event to the dropzone-packagist repo.
  131. uses: peter-evans/repository-dispatch@v1
  132. with:
  133. token: ${{ secrets.DRONE_PAT }}
  134. repository: dropzone/dropzone-packagist
  135. event-type: new-release
  136. client-payload: '{"releaseTag": "${{ needs.tag.outputs.tagname }}"}'
  137. - name: Dispatch "new-release" event to the dropzone-bower repo.
  138. uses: peter-evans/repository-dispatch@v1
  139. with:
  140. token: ${{ secrets.DRONE_PAT }}
  141. repository: dropzone/dropzone-bower
  142. event-type: new-release
  143. client-payload: '{"releaseTag": "${{ needs.tag.outputs.tagname }}"}'