release.yml 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. name: release
  2. on:
  3. workflow_dispatch:
  4. push:
  5. branches:
  6. - master
  7. jobs:
  8. release:
  9. runs-on: ubuntu-latest
  10. permissions: write-all
  11. name: Release
  12. steps:
  13. - name: Checkout
  14. uses: actions/checkout@v4
  15. with:
  16. fetch-depth: 0
  17. - name: Check version
  18. id: version-check
  19. run: |
  20. chmod +x ./scripts/is-newer-version.bash
  21. chmod +x ./scripts/get-version.bash
  22. VERSION=$(./scripts/is-newer-version.bash)
  23. echo "version=${VERSION}" >> $GITHUB_OUTPUT
  24. if [ "$VERSION" != "0" ]; then
  25. echo "New version detected: $VERSION"
  26. else
  27. echo "No new version to release"
  28. fi
  29. - name: Push tag
  30. if: steps.version-check.outputs.version != '0'
  31. id: push-tag
  32. run: |
  33. tag="v${{ steps.version-check.outputs.version }}"
  34. git config user.name "${GITHUB_ACTOR}"
  35. git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
  36. git tag -a "${tag}" -m "Release ${tag}"
  37. git push origin "${tag}"
  38. echo "tag_name=${tag}" >> $GITHUB_OUTPUT
  39. - name: Checkout
  40. if: steps.version-check.outputs.version != '0'
  41. uses: actions/checkout@v4
  42. - name: Setup Rust
  43. if: steps.version-check.outputs.version != '0'
  44. uses: MatteoH2O1999/setup-rust@v1
  45. - name: Cache Rust dependencies
  46. if: steps.version-check.outputs.version != '0'
  47. uses: Swatinem/rust-cache@v2
  48. with:
  49. cache-on-failure: "true"
  50. - name: Build project
  51. if: steps.version-check.outputs.version != '0'
  52. run: cargo build --release
  53. shell: bash
  54. working-directory: ${{ github.action_path }}
  55. - name: Generate minimized HTML
  56. if: steps.version-check.outputs.version != '0'
  57. run: cargo run --release -- index.html
  58. shell: bash
  59. working-directory: ${{ github.action_path }}
  60. - name: Copy files
  61. if: steps.version-check.outputs.version != '0'
  62. run: |
  63. mkdir -p ../release
  64. cp -v index.html ../release/
  65. cp -v index.min.html ../release/
  66. cp -v index.allinone.html ../release/
  67. cp -v index.allinone.min.html ../release/
  68. shell: bash
  69. working-directory: ${{ github.action_path }}
  70. - name: Create release
  71. if: steps.version-check.outputs.version != '0'
  72. uses: ncipollo/release-action@v1
  73. with:
  74. generateReleaseNotes: true
  75. tag: "v${{ steps.version-check.outputs.version }}"
  76. artifacts: "../release/index.html,../release/index.min.html,../release/index.allinone.html,../release/index.allinone.min.html"
  77. - name: Delete tag
  78. if: (cancelled() || failure()) && steps.push-tag.outputs.tag_name != ''
  79. run: |
  80. git config user.name "${GITHUB_ACTOR}"
  81. git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
  82. git push --delete origin "${{ steps.push-tag.outputs.tag_name }}"
  83. git tag -d "${{ steps.push-tag.outputs.tag_name }}"