diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..155efeb --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,34 @@ +name: Build and Test +on: + push: + pull-request: + - opened + branches: + - main + +jobs: + build-and-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: "1.20" + - name: Cache Go modules + id: cache-go + uses: actions/cache@v3 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - name: Download Go modules + shell: bash + if: ${{ steps.cache-go.outputs.cache-hit != 'true' }} + run: go mod download + - name: Go build + shell: bash + run: go build ./... + - name: Go test + shell: bash + run: go test ./... diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 0000000..4f07334 --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,33 @@ + +name: Docker build and push + +on: + workflow_run: + workflows: ["Build and Test"] + branches: ["main"] + types: + - completed + +jobs: + docker-build: + runs-on: ubuntu-latest + env: + IMAGE_NAME: docker_state_exporter + steps: + - uses: actions/checkout@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GH_ACCESS_TOKEN }} + - name: Build and push + uses: docker/build-push-action@v4 + with: + context: ./ + push: true + tags: | + ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest +