name: ci on: push: pull_request: permissions: contents: write packages: write jobs: setup: runs-on: ubuntu-latest outputs: go-version: ${{ steps.go-version.outputs.version }} steps: - name: Checkout uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5 - name: Extract Go version from go.mod id: go-version run: | GO_VERSION=$(grep -E '^go [0-9]+\.[0-9]+' go.mod | awk '{print $2}' | cut -d. -f1,2) echo "version=v${GO_VERSION}" >> $GITHUB_OUTPUT builds: timeout-minutes: 10 runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5 with: fetch-depth: 0 - name: Set up Go uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5 with: go-version-file: 'go.mod' cache: true - name: Build run: make build tests: needs: [ builds ] strategy: matrix: os: [ubuntu-latest] name: [unit] runs-on: ${{ matrix.os }} name: test (${{ matrix.name }}, ${{ matrix.os }}) steps: - name: Checkout code uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5 - name: Set up Go uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5 with: go-version-file: 'go.mod' cache: true - name: Run [${{ matrix.name }} - ${{ matrix.os }}] tests run: make test release-binaries: if: github.ref_type == 'tag' needs: [ setup, tests, builds] strategy: matrix: os: [ ubuntu-latest] runs-on: ${{ matrix.os }} steps: - name: Checkout id: checkout uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5 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: ${{ needs.setup.outputs.go-version }} 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: ${{ needs.setup.outputs.go-version }} 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@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5 with: fetch-depth: 0 - name: Set up QEMU uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3 - name: Set up Docker Buildx uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3 - name: Cache Docker layers uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 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@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GH_ACCESS_TOKEN }} - name: Docker meta id: meta uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # 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@263435318d21b8e681c14492fe198d362a7d2c83 # v6 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 }}