Skip to content

Commit

Permalink
chore(workflows): Improve workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
Rieb, Elias authored and Rieb, Elias committed Dec 9, 2024
1 parent 844e03e commit a41f530
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 56 deletions.
62 changes: 28 additions & 34 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,23 @@ jobs:
name: 📦 Build & Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
- uses: actions/checkout@v3
- uses: docker/setup-buildx-action@v2
- uses: docker/login-action@v2
with:
go-version: '1.21'

- name: Build
run: go build

- name: Test
run: go test -coverpkg='./internal/...' -v './...'

- name: Vet
run: go vet ./...

- name: Run coverage
run: go test -coverpkg='./internal/...' -coverprofile=coverage.out -covermode=atomic ./...
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: meta
uses: docker/metadata-action@v5
images: ghcr.io/${{ github.repository }}
tags: |
type=ref,event=branch,pattern=snapshot-{{sha}}
- uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}

release:
name: 🚀 Release
Expand All @@ -38,25 +35,22 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
- uses: docker/login-action@v2
with:
go-version: '1.21'
- run: go build
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: go-semantic-release/action@v1
with:
hooks: goreleaser
prerelease: false
allow-initial-development-versions: true # remove to trigger an initial 1.0.0 release
changelog-generator-opt: "emojis=true"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# - name: Login to Docker Hub
# uses: docker/login-action@v2
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_TOKEN }}
# - name: Docker Hub Description
# uses: peter-evans/dockerhub-description@v3
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_PASSWORD }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- run: |
TAG=${{ steps.semantic-release.outputs.version }}
IMAGE=${{ needs.build.outputs.image }}
docker pull $IMAGE
docker tag $IMAGE ghcr.io/${{ github.repository }}:$TAG
docker push ghcr.io/${{ github.repository }}:${{ steps.semantic-release.outputs.version }}
12 changes: 1 addition & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
ARG GOLANG_VERSION=1-buster
ARG PACT_VERSION=1.88.63

FROM golang:${GOLANG_VERSION} as build
ARG PACT_VERSION

# Install pact contract testing standalone binaries (includes Ruby)
RUN curl -LO https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v${PACT_VERSION}/pact-${PACT_VERSION}-linux-x86_64.tar.gz; \
tar -C /usr/local -xzf pact-${PACT_VERSION}-linux-x86_64.tar.gz; \
rm pact-${PACT_VERSION}-linux-x86_64.tar.gz; \
mkdir -p /app

ENV PATH /usr/local/pact/bin:$PATH

COPY . /app
WORKDIR /app
Expand All @@ -27,4 +17,4 @@ COPY --from=build /app/main /main
COPY --from=build /etc/ssl/certs /etc/ssl/certs
COPY --from=build /app/api/openapi-v3-spec.yaml /api/openapi-v3-spec.yaml

ENTRYPOINT ["/main"]
ENTRYPOINT ["/main"]
12 changes: 1 addition & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,16 +270,6 @@ Clone this outside your GOPATH (on linux, defaults to ~/go)

_Tip: On Windows, you should NOT place the GOPATH in your profile, because a large body of source code goes there._

### contract test setup

This service uses [pact-go](https://github.com/pact-foundation/pact-go) for consumer driven contract tests.
We only interact with the vault api, so we are a _consumer_, and there is no pact-aware implementation
for the _producer_ side, instead this repository just comes with the relevant recordings,
which were manually created.

Download and install the pact command line tools and add them to your path as described in the
[pact-go manual](https://github.com/pact-foundation/pact-go#installation).

### generate api model classes

**The generated models are checked in, so you only need to run this step if there is a change in the openapi specs.**
Expand All @@ -296,7 +286,7 @@ In a git bash (or on Linux), run `./api-generator/generate.sh`.

We have _given-when-then_ style acceptance tests.

Run all tests, including the acceptance and contract tests (will need to have pact installed):
Run all tests, including the acceptance:

`go test -coverpkg='./internal/...' -v './...'`

Expand Down

0 comments on commit a41f530

Please sign in to comment.