4
0

release.yml 3.8 KB

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