build.yml

  1name: build
  2
  3on: [push, pull_request]
  4
  5permissions:
  6  packages: write
  7
  8jobs:
  9  build:
 10    strategy:
 11      matrix:
 12        go-version: [~1.17, ^1]
 13        os: [ubuntu-latest, macos-latest, windows-latest]
 14    runs-on: ${{ matrix.os }}
 15    env:
 16      GO111MODULE: "on"
 17    steps:
 18      - name: Install Go
 19        uses: actions/setup-go@v2
 20        with:
 21          go-version: ${{ matrix.go-version }}
 22
 23      - name: Checkout code
 24        uses: actions/checkout@v2
 25
 26      - name: Download Go modules
 27        run: go mod download
 28
 29      - name: Build
 30        run: go build -v ./...
 31
 32      - name: Test
 33        run: go test ./...
 34
 35  nightly:
 36    env:
 37      GO111MODULE: "on"
 38      DOCKER_CLI_EXPERIMENTAL: enabled
 39    runs-on: ubuntu-latest
 40    steps:
 41      - name: Install Go
 42        uses: actions/setup-go@v2
 43        with:
 44          go-version: "~1.17"
 45
 46      - name: Checkout code
 47        uses: actions/checkout@v2
 48
 49      - name: Login to GitHub Container Registry
 50        uses: docker/login-action@v1
 51        with:
 52          registry: ghcr.io
 53          username: ${{ github.repository_owner }}
 54          password: ${{ secrets.GITHUB_TOKEN }}
 55
 56      - name: Set up QEMU
 57        uses: docker/setup-qemu-action@v1
 58
 59      - name: Set up Docker Buildx
 60        id: buildx
 61        uses: docker/setup-buildx-action@v1
 62
 63      - name: Run GoReleaser
 64        uses: goreleaser/goreleaser-action@v2
 65        with:
 66          distribution: goreleaser
 67          version: latest
 68          args: release --snapshot --rm-dist --skip-sign --skip-sbom
 69        env:
 70          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
 71          HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
 72
 73      - name: Push docker images
 74        run: |
 75          GIT_HASH=$(git rev-parse --short "$GITHUB_SHA")
 76
 77          docker tag ghcr.io/$GITHUB_REPOSITORY:latest-amd64 ghcr.io/$GITHUB_REPOSITORY:devel-$GIT_HASH-amd64
 78          docker tag ghcr.io/$GITHUB_REPOSITORY:latest-arm64 ghcr.io/$GITHUB_REPOSITORY:devel-$GIT_HASH-arm64
 79          docker tag ghcr.io/$GITHUB_REPOSITORY:latest-armv7 ghcr.io/$GITHUB_REPOSITORY:devel-$GIT_HASH-armv7
 80          docker tag ghcr.io/$GITHUB_REPOSITORY:latest-i386 ghcr.io/$GITHUB_REPOSITORY:devel-$GIT_HASH-i386
 81
 82          docker push ghcr.io/$GITHUB_REPOSITORY:devel-$GIT_HASH-amd64
 83          docker push ghcr.io/$GITHUB_REPOSITORY:devel-$GIT_HASH-arm64
 84          docker push ghcr.io/$GITHUB_REPOSITORY:devel-$GIT_HASH-armv7
 85          docker push ghcr.io/$GITHUB_REPOSITORY:devel-$GIT_HASH-i386
 86
 87          docker manifest create ghcr.io/$GITHUB_REPOSITORY:devel-$GIT_HASH \
 88            ghcr.io/$GITHUB_REPOSITORY:devel-$GIT_HASH-amd64 \
 89            ghcr.io/$GITHUB_REPOSITORY:devel-$GIT_HASH-arm64 \
 90            ghcr.io/$GITHUB_REPOSITORY:devel-$GIT_HASH-armv7 \
 91            ghcr.io/$GITHUB_REPOSITORY:devel-$GIT_HASH-i386
 92          docker manifest push ghcr.io/$GITHUB_REPOSITORY:devel-$GIT_HASH
 93
 94          if [[ $GITHUB_REF = 'refs/heads/main' && $GITHUB_EVENT_NAME = 'push' ]]; then
 95            docker tag ghcr.io/$GITHUB_REPOSITORY:latest-amd64 ghcr.io/$GITHUB_REPOSITORY:devel-amd64
 96            docker tag ghcr.io/$GITHUB_REPOSITORY:latest-arm64 ghcr.io/$GITHUB_REPOSITORY:devel-arm64
 97            docker tag ghcr.io/$GITHUB_REPOSITORY:latest-armv7 ghcr.io/$GITHUB_REPOSITORY:devel-armv7
 98            docker tag ghcr.io/$GITHUB_REPOSITORY:latest-i386 ghcr.io/$GITHUB_REPOSITORY:devel-i386
 99
100            docker push ghcr.io/$GITHUB_REPOSITORY:devel-amd64
101            docker push ghcr.io/$GITHUB_REPOSITORY:devel-arm64
102            docker push ghcr.io/$GITHUB_REPOSITORY:devel-armv7
103            docker push ghcr.io/$GITHUB_REPOSITORY:devel-i386
104
105            docker manifest create ghcr.io/$GITHUB_REPOSITORY:devel \
106              ghcr.io/$GITHUB_REPOSITORY:devel-amd64 \
107              ghcr.io/$GITHUB_REPOSITORY:devel-arm64 \
108              ghcr.io/$GITHUB_REPOSITORY:devel-armv7 \
109              ghcr.io/$GITHUB_REPOSITORY:devel-i386
110            docker manifest push ghcr.io/$GITHUB_REPOSITORY:devel
111          fi
112
113      - uses: actions/upload-artifact@v2
114        with:
115          name: Linux (x86_64)
116          path: |
117            dist/soft-serve_linux_amd64/*
118            LICENSE
119            README.md
120
121      - uses: actions/upload-artifact@v2
122        with:
123          name: Linux (arm64)
124          path: |
125            dist/soft-serve_linux_arm64/*
126            LICENSE
127            README.md
128
129      - uses: actions/upload-artifact@v2
130        with:
131          name: MacOS (x86_64)
132          path: |
133            dist/soft-serve_darwin_amd64/*
134            LICENSE
135            README.md
136
137      - uses: actions/upload-artifact@v2
138        with:
139          name: MacOS (arm64)
140          path: |
141            dist/soft-serve_darwin_arm64/*
142            LICENSE
143            README.md
144
145      - uses: actions/upload-artifact@v2
146        with:
147          name: Windows (x86_64)
148          path: |
149            dist/soft-serve_windows_amd64/*
150            LICENSE
151            README.md