|
| 1 | +name: Docker Build and Publish |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: [ 'v*' ] |
| 6 | + |
| 7 | +env: |
| 8 | + REGISTRY: ghcr.io |
| 9 | + IMAGE_NAME: ftp27/universal-redirect |
| 10 | + |
| 11 | +jobs: |
| 12 | + build-and-push: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + permissions: |
| 15 | + contents: read |
| 16 | + packages: write |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Checkout repository |
| 20 | + uses: actions/checkout@v3 |
| 21 | + |
| 22 | + - name: Set up Go |
| 23 | + uses: actions/setup-go@v4 |
| 24 | + with: |
| 25 | + go-version: '1.20' |
| 26 | + cache: true |
| 27 | + |
| 28 | + - name: Run tests |
| 29 | + run: make test |
| 30 | + |
| 31 | + - name: Set up Docker Buildx |
| 32 | + uses: docker/setup-buildx-action@v2 |
| 33 | + |
| 34 | + - name: Log in to the Container registry |
| 35 | + uses: docker/login-action@v2 |
| 36 | + with: |
| 37 | + registry: ${{ env.REGISTRY }} |
| 38 | + username: ${{ github.actor }} |
| 39 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 40 | + |
| 41 | + - name: Extract Git tag |
| 42 | + id: get_tag |
| 43 | + run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT |
| 44 | + |
| 45 | + - name: Extract metadata (tags, labels) for Docker |
| 46 | + id: meta |
| 47 | + uses: docker/metadata-action@v4 |
| 48 | + with: |
| 49 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 50 | + tags: | |
| 51 | + type=raw,value=${{ steps.get_tag.outputs.TAG }} |
| 52 | + type=semver,pattern={{version}} |
| 53 | + type=semver,pattern={{major}}.{{minor}} |
| 54 | +
|
| 55 | + - name: Build and push Docker image |
| 56 | + uses: docker/build-push-action@v4 |
| 57 | + with: |
| 58 | + context: . |
| 59 | + push: true |
| 60 | + tags: ${{ steps.meta.outputs.tags }} |
| 61 | + labels: ${{ steps.meta.outputs.labels }} |
| 62 | + cache-from: type=gha |
| 63 | + cache-to: type=gha,mode=max |
0 commit comments