name: ci on: push: pull_request: jobs: builds: timeout-minutes: 10 runs-on: ubuntu-latest strategy: matrix: go-version: [1.21] steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 - name: Set up Go uses: actions/setup-go@v5 with: go-version: ${{ matrix.go-version }} - name: Build run: make build tests: needs: [builds] strategy: matrix: os: [ubuntu-latest] name: [unit] go-version: [1.21] runs-on: ${{ matrix.os }} name: test (${{ matrix.name }}, ${{ matrix.os }}) steps: - name: Checkout code uses: actions/checkout@v4 - name: Set up Go uses: actions/setup-go@v5 with: go-version: ${{ matrix.go-version }} cache: true - name: Run [${{ matrix.name }} - ${{ matrix.os }}] tests run: make test release-binaries: if: github.ref_type == 'tag' strategy: matrix: go-version: [ 1.21 ] os: [ ubuntu-22.04] needs: [tests, builds] runs-on: ${{ matrix.os }} steps: - name: Checkout id: checkout uses: actions/checkout@v4 with: fetch-depth: 0 - name: Run GoReleaser Linux run: | docker run \ --rm \ --privileged \ -e CGO_ENABLED=1 \ -e GITHUB_TOKEN \ -v /var/run/docker.sock:/var/run/docker.sock \ -v `pwd`:/go/src/$(PACKAGE_NAME) \ -w /go/src/$(PACKAGE_NAME) \ ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \ --clean --config .goreleaser-Linux.yml env: PACKAGE_NAME: github.com/AndriyKalashnykov/go-httpbin GOLANG_CROSS_VERSION: v1.21 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Run GoReleaser MacOS run: | docker run \ --rm \ --privileged \ -e CGO_ENABLED=1 \ -e GITHUB_TOKEN \ -v /var/run/docker.sock:/var/run/docker.sock \ -v `pwd`:/go/src/$(PACKAGE_NAME) \ -w /go/src/$(PACKAGE_NAME) \ ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \ --clean --config .goreleaser-Darwin-cross.yml env: PACKAGE_NAME: github.com/AndriyKalashnykov/go-httpbin GOLANG_CROSS_VERSION: v1.21 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} release-docker-images: if: github.ref_type == 'tag' needs: [tests, builds] timeout-minutes: 10 runs-on: ubuntu-latest env: GH_ACCESS_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }} permissions: packages: write contents: read steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 - name: Set up QEMU uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Cache Docker layers uses: actions/cache@v4.0.2 with: path: /tmp/.buildx-cache key: ${{ runner.os }}-buildx-${{ github.sha }} restore-keys: | ${{ runner.os }}-buildx- - name: Convert owner to lower case run: | echo "OWNER_LC=${OWNER,,}" >>${GITHUB_ENV} env: OWNER: '${{ github.repository_owner }}' - name: Login to image repository uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GH_ACCESS_TOKEN }} - name: Docker meta id: meta uses: docker/metadata-action@v5 with: images: ghcr.io/${{ env.OWNER_LC }}/go-httpbin flavor: latest=true tags: | type=ref,event=branch type=ref,event=pr type=semver,pattern=v{{version}} - name: Build and push uses: docker/build-push-action@v5 with: context: . file: ./Dockerfile platforms: linux/amd64 push: ${{ github.ref_type == 'tag' }} cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }}