|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + |
| 8 | +env: |
| 9 | + GORELEASER_VERSION: "v1.18.2" |
| 10 | + |
| 11 | +jobs: |
| 12 | + release: |
| 13 | + name: Release |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - name: Checkout |
| 17 | + uses: actions/checkout@v2 |
| 18 | + with: |
| 19 | + fetch-depth: 0 |
| 20 | + |
| 21 | + - name: Fetch tags |
| 22 | + run: git fetch --force --tags |
| 23 | + |
| 24 | + - name: Setup QEMU |
| 25 | + uses: docker/setup-qemu-action@v2 |
| 26 | + |
| 27 | + - name: Setup Docker Buildx |
| 28 | + uses: docker/setup-buildx-action@v2 |
| 29 | + id: buildx |
| 30 | + |
| 31 | + - name: Login to container Registry |
| 32 | + uses: docker/login-action@v2 |
| 33 | + with: |
| 34 | + username: ${{ github.repository_owner }} |
| 35 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 36 | + registry: ghcr.io |
| 37 | + |
| 38 | + - name: Prepare |
| 39 | + id: prep |
| 40 | + run: | |
| 41 | + VERSION=sha-${GITHUB_SHA::8} |
| 42 | + if [[ $GITHUB_REF == refs/tags/* ]]; then |
| 43 | + VERSION=${GITHUB_REF/refs\/tags\//} |
| 44 | + fi |
| 45 | + echo ::set-output name=BUILD_DATE::$(date -u +'%Y-%m-%dT%H:%M:%SZ') |
| 46 | + echo ::set-output name=VERSION::${VERSION} |
| 47 | +
|
| 48 | + - name: Publish multi-arch Docker image |
| 49 | + uses: docker/build-push-action@v2 |
| 50 | + with: |
| 51 | + push: true |
| 52 | + builder: ${{ steps.buildx.outputs.name }} |
| 53 | + context: . |
| 54 | + file: ./Dockerfile |
| 55 | + platforms: linux/arm64,linux/amd64 |
| 56 | + tags: | |
| 57 | + ghcr.io/${{ github.repository_owner }}/init:${{ steps.prep.outputs.VERSION }} |
| 58 | + ghcr.io/${{ github.repository_owner }}/init:latest |
| 59 | + labels: | |
| 60 | + org.opencontainers.image.title=${{ github.event.repository.name }} |
| 61 | + org.opencontainers.image.description=${{ github.event.repository.description }} |
| 62 | + org.opencontainers.image.source=${{ github.event.repository.html_url }} |
| 63 | + org.opencontainers.image.url=${{ github.event.repository.html_url }} |
| 64 | + org.opencontainers.image.revision=${{ github.sha }} |
| 65 | + org.opencontainers.image.version=${{ steps.prep.outputs.VERSION }} |
| 66 | + org.opencontainers.image.created=${{ steps.prep.outputs.BUILD_DATE }} |
| 67 | +
|
| 68 | + - name: Set GORELEASER_PREVIOUS_TAG |
| 69 | + run: echo "GORELEASER_PREVIOUS_TAG=$(git tag -l "v*" --sort=-version:refname | head -n 2 | tail -n 1)" >> $GITHUB_ENV |
| 70 | + |
| 71 | + - name: GoReleaser |
| 72 | + uses: goreleaser/goreleaser-action@v4 |
| 73 | + with: |
| 74 | + version: ${{ env.GORELEASER_VERSION }} |
| 75 | + args: release |
| 76 | + env: |
| 77 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments