release.yml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. name: Release
  2. on:
  3. push:
  4. tags:
  5. - 'v*'
  6. workflow_dispatch:
  7. permissions:
  8. contents: write
  9. pull-requests: read
  10. jobs:
  11. release:
  12. name: Create Release
  13. runs-on: ubuntu-latest
  14. timeout-minutes: 10
  15. steps:
  16. - name: Checkout repository
  17. uses: actions/checkout@v4
  18. with:
  19. fetch-depth: 0
  20. - name: Set up Python
  21. uses: actions/setup-python@v5
  22. with:
  23. python-version: "3.11"
  24. cache: 'pip'
  25. - name: Install dependencies
  26. run: |
  27. python -m pip install --upgrade pip
  28. if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
  29. - name: Create distribution
  30. run: |
  31. # Create a simple distribution with the necessary files
  32. mkdir -p dist/squidstats
  33. cp -r app.py requirements.txt database/ parsers/ services/ static/ templates/ utils/ dist/squidstats/
  34. cd dist && tar -czf squidstats-${GITHUB_REF_NAME}.tar.gz squidstats/
  35. - name: Generate changelog
  36. id: changelog
  37. run: |
  38. # Get the previous tag
  39. PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
  40. # Generate changelog
  41. if [ -n "$PREV_TAG" ]; then
  42. echo "## Changes since $PREV_TAG" > CHANGELOG.md
  43. git log --pretty=format:"- %s (%h)" $PREV_TAG..HEAD >> CHANGELOG.md
  44. else
  45. echo "## Initial Release" > CHANGELOG.md
  46. echo "First release of SquidStats" >> CHANGELOG.md
  47. fi
  48. echo "changelog<<EOF" >> $GITHUB_OUTPUT
  49. cat CHANGELOG.md >> $GITHUB_OUTPUT
  50. echo "EOF" >> $GITHUB_OUTPUT
  51. - name: Create Release
  52. uses: actions/create-release@v1
  53. env:
  54. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  55. with:
  56. tag_name: ${{ github.ref_name }}
  57. release_name: SquidStats ${{ github.ref_name }}
  58. body: ${{ steps.changelog.outputs.changelog }}
  59. draft: false
  60. prerelease: false
  61. - name: Upload Release Asset
  62. uses: actions/upload-release-asset@v1
  63. env:
  64. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  65. with:
  66. upload_url: ${{ steps.create_release.outputs.upload_url }}
  67. asset_path: ./dist/squidstats-${{ github.ref_name }}.tar.gz
  68. asset_name: squidstats-${{ github.ref_name }}.tar.gz
  69. asset_content_type: application/gzip
  70. docker:
  71. name: Build Docker Image
  72. runs-on: ubuntu-latest
  73. timeout-minutes: 20
  74. needs: release
  75. if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
  76. steps:
  77. - name: Checkout repository
  78. uses: actions/checkout@v4
  79. - name: Set up Docker Buildx
  80. uses: docker/setup-buildx-action@v3
  81. - name: Login to GitHub Container Registry
  82. uses: docker/login-action@v3
  83. with:
  84. registry: ghcr.io
  85. username: ${{ github.actor }}
  86. password: ${{ secrets.GITHUB_TOKEN }}
  87. - name: Extract metadata
  88. id: meta
  89. uses: docker/metadata-action@v5
  90. with:
  91. images: ghcr.io/${{ github.repository_owner }}/squidstats
  92. tags: |
  93. type=ref,event=tag
  94. type=semver,pattern={{version}}
  95. type=semver,pattern={{major}}.{{minor}}
  96. type=semver,pattern={{major}}
  97. - name: Build and push Docker image
  98. uses: docker/build-push-action@v5
  99. with:
  100. context: .
  101. push: true
  102. tags: ${{ steps.meta.outputs.tags }}
  103. labels: ${{ steps.meta.outputs.labels }}
  104. cache-from: type=gha
  105. cache-to: type=gha,mode=max