|
| 1 | +name: Publish |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + # Publish `v*` tags as releases. |
| 6 | + tags: |
| 7 | + - v* |
| 8 | + pull_request: |
| 9 | + |
| 10 | +jobs: |
| 11 | + test: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - name: Set up Go 1.x |
| 15 | + uses: actions/setup-go@v2 |
| 16 | + with: |
| 17 | + go-version: ^1.15 |
| 18 | + id: go |
| 19 | + |
| 20 | + - name: Check out code into the Go module directory |
| 21 | + uses: actions/checkout@v2 |
| 22 | + |
| 23 | + - name: Build |
| 24 | + run: go build -v . |
| 25 | + |
| 26 | + - name: Test |
| 27 | + run: go test -v . |
| 28 | + publish: |
| 29 | + runs-on: ubuntu-latest |
| 30 | + if: github.event_name == 'push' |
| 31 | + # Ensure test job passes before pushing image. |
| 32 | + needs: test |
| 33 | + steps: |
| 34 | + - |
| 35 | + name: Checkout |
| 36 | + uses: actions/checkout@v2 |
| 37 | + - |
| 38 | + name: Docker meta |
| 39 | + id: docker_meta |
| 40 | + uses: crazy-max/ghaction-docker-meta@v1 |
| 41 | + with: |
| 42 | + images: ${{ secrets.DOCKER_HUB_USERNAME }}/k8s-aws-ebs-tagger,ghcr.io/${{ github.repository_owner }}/k8s-aws-ebs-tagger |
| 43 | + - |
| 44 | + name: Set up QEMU |
| 45 | + uses: docker/setup-qemu-action@v1 |
| 46 | + - |
| 47 | + name: Set up Docker Buildx |
| 48 | + uses: docker/setup-buildx-action@v1 |
| 49 | + - |
| 50 | + name: Login to DockerHub |
| 51 | + uses: docker/login-action@v1 |
| 52 | + if: github.event_name != 'pull_request' |
| 53 | + with: |
| 54 | + username: ${{ secrets.DOCKER_HUB_USERNAME }} |
| 55 | + password: ${{ secrets.DOCKER_HUB_TOKEN }} |
| 56 | + - |
| 57 | + name: Login to GitHub Container Registry |
| 58 | + uses: docker/login-action@v1 |
| 59 | + if: github.event_name != 'pull_request' |
| 60 | + with: |
| 61 | + registry: ghcr.io |
| 62 | + username: ${{ github.repository_owner }} |
| 63 | + password: ${{ secrets.GHCR_PAT }} |
| 64 | + - |
| 65 | + name: Build and push |
| 66 | + id: docker_build |
| 67 | + uses: docker/build-push-action@v2 |
| 68 | + with: |
| 69 | + context: . |
| 70 | + file: ./Dockerfile |
| 71 | + build-args: VERSION=${{ steps.docker_meta.outputs.version }} |
| 72 | + platforms: linux/amd64,linux/arm64 |
| 73 | + push: ${{ github.event_name != 'pull_request' }} |
| 74 | + tags: ${{ steps.docker_meta.outputs.tags }} |
| 75 | + labels: ${{ steps.docker_meta.outputs.labels }} |
0 commit comments