|
| 1 | +name: Create GitHub Release & Docker Build and Push |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + |
| 6 | +jobs: |
| 7 | + release-and-build: |
| 8 | + runs-on: ubuntu-latest |
| 9 | + permissions: |
| 10 | + contents: write # Needed to create tags and releases |
| 11 | + packages: write # Needed to push to GHCR |
| 12 | + id-token: write # For trusted publishing |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Checkout repository |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 0 # Important for tagging |
| 19 | + |
| 20 | + - name: Generate tag name from current date |
| 21 | + id: date |
| 22 | + run: echo "tag=$(date +'%Y.%m.%d')" >> $GITHUB_OUTPUT |
| 23 | + |
| 24 | + - name: Check if tag already exists |
| 25 | + id: check_tag |
| 26 | + run: | |
| 27 | + if git rev-parse "${{ steps.date.outputs.tag }}" >/dev/null 2>&1; then |
| 28 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 29 | + else |
| 30 | + echo "exists=false" >> $GITHUB_OUTPUT |
| 31 | + fi |
| 32 | +
|
| 33 | + - name: Create git tag |
| 34 | + if: steps.check_tag.outputs.exists == 'false' |
| 35 | + run: | |
| 36 | + git config user.name "github-actions[bot]" |
| 37 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 38 | + git tag ${{ steps.date.outputs.tag }} |
| 39 | + git push origin ${{ steps.date.outputs.tag }} |
| 40 | +
|
| 41 | + - name: Create GitHub Release |
| 42 | + if: steps.check_tag.outputs.exists == 'false' |
| 43 | + uses: ncipollo/release-action@v1 |
| 44 | + with: |
| 45 | + tag: ${{ steps.date.outputs.tag }} |
| 46 | + name: Release ${{ steps.date.outputs.tag }} |
| 47 | + generateReleaseNotes: true |
| 48 | + draft: false |
| 49 | + prerelease: false |
| 50 | + |
| 51 | + - name: Set up Docker Buildx |
| 52 | + uses: docker/setup-buildx-action@v3 |
| 53 | + |
| 54 | + - name: Log in to GitHub Container Registry |
| 55 | + uses: docker/login-action@v3 |
| 56 | + with: |
| 57 | + registry: ghcr.io |
| 58 | + username: ${{ github.actor }} |
| 59 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 60 | + |
| 61 | + - name: Extract metadata (tags, labels) for Docker |
| 62 | + id: meta |
| 63 | + uses: docker/metadata-action@v5 |
| 64 | + with: |
| 65 | + images: ghcr.io/${{ github.repository }} |
| 66 | + tags: | |
| 67 | + type=raw,value=${{ steps.date.outputs.tag }},priority=1000 |
| 68 | + type=raw,value=latest |
| 69 | +
|
| 70 | + - name: Build and push Docker image |
| 71 | + uses: docker/build-push-action@v6 |
| 72 | + with: |
| 73 | + context: . |
| 74 | + push: true |
| 75 | + tags: ${{ steps.meta.outputs.tags }} |
| 76 | + labels: ${{ steps.meta.outputs.labels }} |
| 77 | + cache-from: type=gha |
| 78 | + cache-to: type=gha,mode=max |
0 commit comments