|
| 1 | +name: main |
| 2 | +on: |
| 3 | + push: |
| 4 | + tags: |
| 5 | + - v* |
| 6 | + branches: |
| 7 | + - main |
| 8 | + pull_request: |
| 9 | + |
| 10 | +jobs: |
| 11 | + lint: |
| 12 | + name: Lint |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v2 |
| 16 | + - name: golangci-lint |
| 17 | + uses: golangci/golangci-lint-action@v2 |
| 18 | + with: |
| 19 | + version: v1.33 |
| 20 | + args: --timeout=5m |
| 21 | + |
| 22 | + test: |
| 23 | + name: Test |
| 24 | + runs-on: ubuntu-latest |
| 25 | + |
| 26 | + # TODO Set up Kind for integration tests. |
| 27 | + |
| 28 | + steps: |
| 29 | + - uses: actions/checkout@v2 |
| 30 | + - uses: actions/setup-go@v2 |
| 31 | + - name: Install Kubebuilder |
| 32 | + id: install-kubebuilder |
| 33 | + run: | |
| 34 | + os=$(go env GOOS) |
| 35 | + arch=$(go env GOARCH) |
| 36 | + curl -L https://go.kubebuilder.io/dl/2.3.1/${os}/${arch} | tar -xz -C /tmp/ |
| 37 | + sudo mv /tmp/kubebuilder_2.3.1_${os}_${arch} /usr/local/kubebuilder |
| 38 | + - run: make test |
| 39 | + |
| 40 | + build: |
| 41 | + name: Container Build |
| 42 | + runs-on: ubuntu-latest |
| 43 | + needs: |
| 44 | + - test |
| 45 | + - lint |
| 46 | + if: github.event_name != 'pull_request' |
| 47 | + |
| 48 | + steps: |
| 49 | + - uses: actions/checkout@v2 |
| 50 | + - name: Docker Prep |
| 51 | + id: prep |
| 52 | + run: | |
| 53 | + DOCKER_IMAGE=ghcr.io/coderanger/migrations-operator |
| 54 | + VERSION=edge |
| 55 | + if [[ $GITHUB_REF == refs/tags/* ]]; then |
| 56 | + VERSION=${GITHUB_REF#refs/tags/} |
| 57 | + elif [[ $GITHUB_REF == refs/heads/* ]]; then |
| 58 | + VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g') |
| 59 | + elif [[ $GITHUB_REF == refs/pull/* ]]; then |
| 60 | + VERSION=pr-${{ github.event.number }} |
| 61 | + fi |
| 62 | + TAGS="${DOCKER_IMAGE}:${VERSION}" |
| 63 | + if [ "${{ github.event_name }}" = "push" ]; then |
| 64 | + TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}" |
| 65 | + fi |
| 66 | + echo ::set-output name=version::${VERSION} |
| 67 | + echo ::set-output name=tags::${TAGS} |
| 68 | + echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ') |
| 69 | + - name: Set up Docker Buildx |
| 70 | + uses: docker/setup-buildx-action@v1 |
| 71 | + - name: Login to Github Container Registry |
| 72 | + uses: docker/login-action@v1 |
| 73 | + with: |
| 74 | + registry: ghcr.io |
| 75 | + username: ${{ github.repository_owner }} |
| 76 | + password: ${{ secrets.GHCR_PAT }} |
| 77 | + - name: Build and push |
| 78 | + uses: docker/build-push-action@v2 |
| 79 | + with: |
| 80 | + context: . |
| 81 | + file: ./Dockerfile |
| 82 | + push: true |
| 83 | + tags: ${{ steps.prep.outputs.tags }} |
| 84 | + labels: | |
| 85 | + org.opencontainers.image.source=${{ github.event.repository.html_url }} |
| 86 | + org.opencontainers.image.created=${{ steps.prep.outputs.created }} |
| 87 | + org.opencontainers.image.revision=${{ github.sha }} |
0 commit comments