make patternizer into proper go CLI #3
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI Pipeline | |
| on: | |
| push: | |
| branches: | |
| - main | |
| tags: | |
| - 'v*' | |
| pull_request: | |
| branches: | |
| - main | |
| env: | |
| IMAGE_NAME: quay.io/dminnear/patternizer | |
| GO_VERSION: '1.24' | |
| jobs: | |
| lint-and-format: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: ${{ env.GO_VERSION }} | |
| - name: Run gofmt | |
| run: | | |
| if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then | |
| echo "The following files are not formatted:" | |
| gofmt -s -l . | |
| exit 1 | |
| fi | |
| working-directory: ./src | |
| - name: Run go vet | |
| run: go vet ./... | |
| working-directory: ./src | |
| - name: Install golangci-lint | |
| run: | | |
| curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.1.6 | |
| - name: Run golangci-lint | |
| run: $(go env GOPATH)/bin/golangci-lint run | |
| working-directory: ./src | |
| build-and-test: | |
| runs-on: ubuntu-latest | |
| needs: lint-and-format | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: ${{ env.GO_VERSION }} | |
| - name: Build binary | |
| run: go build -v -o patternizer . | |
| working-directory: ./src | |
| - name: Run unit tests | |
| run: go test -v ./... | |
| working-directory: ./src | |
| - name: Run integration tests | |
| run: ./test/integration_test.sh | |
| env: | |
| PATTERNIZER_BINARY: ./src/patternizer | |
| build-container: | |
| runs-on: ubuntu-latest | |
| needs: build-and-test | |
| if: github.event_name == 'push' | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Quay.io | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: quay.io | |
| username: ${{ secrets.QUAY_USERNAME }} | |
| password: ${{ secrets.QUAY_PASSWORD }} | |
| - name: Determine tags | |
| id: meta | |
| run: | | |
| echo "sha_tag=sha-$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | |
| if [[ $GITHUB_REF == refs/tags/* ]]; then | |
| echo "is_tag=true" >> $GITHUB_OUTPUT | |
| echo "git_tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT | |
| else | |
| echo "is_tag=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ./Containerfile | |
| push: true | |
| tags: | | |
| ${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.sha_tag }} | |
| ${{ steps.meta.outputs.is_tag == 'true' && format('{0}:{1}', env.IMAGE_NAME, steps.meta.outputs.git_tag) || '' }} | |
| ${{ steps.meta.outputs.is_tag == 'false' && format('{0}:latest', env.IMAGE_NAME) || '' }} |