Skip to content

Commit

Permalink
Add a Docker image capable of running tests (#608)
Browse files Browse the repository at this point in the history
This change adds a new GHA workflow that runs tests in a Docker
container. It appears as a new check but it's not required, for now.

Other changes:
* GoReleaser update
* Docker image release in GoReleaser config
* Moving of tests setup from Makefile entirely to Go

Closes #605
  • Loading branch information
adambabik authored Jun 11, 2024
1 parent 53cf215 commit 033006a
Show file tree
Hide file tree
Showing 27 changed files with 402 additions and 250 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ jobs:
path: cover.out
if-no-files-found: error

test-in-docker:
name: Test in Docker
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Test
run: make test-docker

build-and-robustness-test:
name: Test parser against vast amount of READMEs
runs-on: ubuntu-latest
Expand Down
25 changes: 20 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Prepare
id: prepare
run: |
Expand All @@ -28,29 +29,41 @@ jobs:
if [[ "$ref_name" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]]; then
echo "pre_release=false" >> $GITHUB_ENV
fi
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.22"

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Auth to GCP
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}
create_credentials_file: true
export_environment_variables: true
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Set up gcloud
uses: google-github-actions/setup-gcloud@v2

- name: Release notes
run: |
owner="${{ vars.RELEASE_OWNER || github.actor }}"
go run ./cmd/release-notes/main.go -version "${GITHUB_REF_NAME}" -owner "$owner" > ${{ runner.temp }}/releasenotes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
Expand All @@ -62,9 +75,11 @@ jobs:
HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }}
SCOOP_BUCKET_GITHUB_TOKEN: ${{ secrets.SCOOP_BUCKET_GITHUB_TOKEN }}
GS_BUCKET: ${{ secrets.GS_BUCKET }}

- name: Copy to latest
if: env.pre_release == 'false'
run: gsutil -m cp "gs://${{ secrets.GS_BUCKET }}/${{ env.version }}/*" gs://${{ secrets.GS_BUCKET }}/latest

- name: Bump Homebrew Formula
uses: mislav/bump-homebrew-formula-action@v3
# skip prereleases
Expand Down
111 changes: 63 additions & 48 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,22 @@ blobs:
bucket: "{{ .Env.GS_BUCKET }}"
ids:
- cli
folder: "{{ .Version }}"
directory: "{{ .Version }}"

brews:
- name: runme
ids:
- cli
homepage: https://runme.dev
description: "Execute your runbooks, docs, and READMEs."
tap:
repository:
owner: stateful
name: homebrew-tap
token: "{{ .Env.HOMEBREW_TAP_GITHUB_TOKEN }}"
url_template: "https://download.stateful.com/runme/{{ .Version }}/{{ .ArtifactName }}"
dependencies: []
skip_upload: auto
folder: Formula
directory: Formula
download_strategy: CurlDownloadStrategy
commit_author:
name: release-bot
Expand Down Expand Up @@ -131,70 +131,85 @@ nfpms:
- apk
- rpm

scoop:
url_template: "https://download.stateful.com/runme/{{ .Version }}/{{ .ArtifactName }}"
bucket:
owner: stateful
name: scoop-bucket
token: "{{ .Env.SCOOP_BUCKET_GITHUB_TOKEN }}"
commit_author:
name: release-bot
email: bot@stateful.com
homepage: https://runme.dev
description: "Execute your runbooks, docs, and READMEs."
skip_upload: auto
scoops:
- url_template: "https://download.stateful.com/runme/{{ .Version }}/{{ .ArtifactName }}"
repository:
owner: stateful
name: scoop-bucket
token: "{{ .Env.SCOOP_BUCKET_GITHUB_TOKEN }}"
commit_author:
name: release-bot
email: bot@stateful.com
homepage: https://runme.dev
description: "Execute your runbooks, docs, and READMEs."
skip_upload: auto

dockers:
- goos: linux
goarch: amd64
image_templates:
- "statefulhq/runme:latest"
- image_templates:
- "statefulhq/runme:{{ .Version }}-alpine-amd64"
skip_push: auto
dockerfile: Dockerfile.alpine
- goos: linux
use: buildx
dockerfile: docker/alpine.Dockerfile
goos: linux
goarch: amd64
image_templates:
- "statefulhq/runme:latest"
build_flag_templates:
- "--platform=linux/amd64"
skip_push: auto
- image_templates:
- "statefulhq/runme:{{ .Version }}-ubuntu-amd64"
use: buildx
dockerfile: docker/ubuntu.Dockerfile
goos: linux
goarch: amd64
build_flag_templates:
- "--platform=linux/amd64"
skip_push: auto
dockerfile: Dockerfile.ubuntu
- goos: linux
- image_templates:
- "statefulhq/runme:{{ .Version }}-alpine-arm64v8"
use: buildx
dockerfile: docker/alpine.Dockerfile
goos: linux
goarch: arm64
image_templates:
- "statefulhq/runme:{{ .Version }}-alpine-arm64"
build_flag_templates:
- "--platform=linux/arm64/v8"
skip_push: auto
dockerfile: Dockerfile.alpine
- goos: linux
- image_templates:
- "statefulhq/runme:{{ .Version }}-ubuntu-arm64v8"
use: buildx
dockerfile: docker/ubuntu.Dockerfile
goos: linux
goarch: arm64
image_templates:
- "statefulhq/runme:{{ .Version }}-ubuntu-arm64"
build_flag_templates:
- "--platform=linux/arm64/v8"
skip_push: auto
dockerfile: Dockerfile.ubuntu

docker_manifests:
- name_template: 'statefulhq/runme:{{ .Version }}'
- name_template: "statefulhq/runme:latest"
image_templates:
- "statefulhq/runme:{{ .Version }}-alpine-amd64"
- "statefulhq/runme:{{ .Version }}-alpine-arm64v8"
skip_push: auto
- name_template: "statefulhq/runme:latest-alpine"
image_templates:
- 'statefulhq/runme:{{ .Version }}-alpine-amd64'
- 'statefulhq/runme:{{ .Version }}-alpine-arm64'
- name_template: 'statefulhq/runme:latest-alpine'
- "statefulhq/runme:{{ .Version }}-alpine-amd64"
- "statefulhq/runme:{{ .Version }}-alpine-arm64v8"
skip_push: auto
- name_template: "statefulhq/runme:latest-ubuntu"
image_templates:
- 'statefulhq/runme:{{ .Version }}-alpine-amd64'
- 'statefulhq/runme:{{ .Version }}-alpine-arm64'
- name_template: 'statefulhq/runme:latest-ubuntu'
- "statefulhq/runme:{{ .Version }}-ubuntu-amd64"
- "statefulhq/runme:{{ .Version }}-ubuntu-arm64v8"
skip_push: auto
- name_template: "statefulhq/runme:{{ .Version }}"
image_templates:
- 'statefulhq/runme:{{ .Version }}-ubuntu-amd64'
- 'statefulhq/runme:{{ .Version }}-ubuntu-arm64'
- name_template: 'statefulhq/runme:{{ .Version }}-alpine'
- "statefulhq/runme:{{ .Version }}-alpine-amd64"
- "statefulhq/runme:{{ .Version }}-alpine-arm64v8"
skip_push: auto
- name_template: "statefulhq/runme:{{ .Version }}-alpine"
skip_push: auto
image_templates:
- 'statefulhq/runme:{{ .Version }}-alpine-amd64'
- 'statefulhq/runme:{{ .Version }}-alpine-arm64'
- name_template: 'statefulhq/runme:{{ .Version }}-ubuntu'
- "statefulhq/runme:{{ .Version }}-alpine-amd64"
- "statefulhq/runme:{{ .Version }}-alpine-arm64v8"
- name_template: "statefulhq/runme:{{ .Version }}-ubuntu"
skip_push: auto
image_templates:
- 'statefulhq/runme:{{ .Version }}-ubuntu-amd64'
- 'statefulhq/runme:{{ .Version }}-ubuntu-arm64'
- "statefulhq/runme:{{ .Version }}-ubuntu-amd64"
- "statefulhq/runme:{{ .Version }}-ubuntu-arm64v8"
24 changes: 19 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ To request a new feature you should open an [issue](../../issues/new) and summar
This is an outline of what the workflow for code contributions looks like

- Check the list of open [issues](../../issues). Either assign an existing issue to yourself, or
create a new one that you would like work on and discuss your ideas and use cases.
create a new one that you would like work on and discuss your ideas and use cases.

It is always best to discuss your plans beforehand, to ensure that your contribution is in line with our goals.

Expand All @@ -51,7 +51,7 @@ This project uses a `Makefile` to manage build scripts. You will need `make` ins

You will need to have a `go` installation - ideally compatible with the project's current go version (see [go.mod](/go.mod)).

### OSX
### macOS

If you are using [`homebrew`](https://brew.sh/), you can install the required system modules with the following command:

Expand Down Expand Up @@ -145,19 +145,33 @@ pre-commit run --files */**

## Testing

Tests are run with go's default test runner. So, for example, you can run all tests with:
Tests are run with Go's default test runner wrapped in Makefile targets. So, for example, you can run all tests with:

```sh {"id":"01HF7BT3HEQBTBM9SSTS88ZSCF"}
make test
```

Generate HTML representation of coverage profile
Please notice that our tests include integration tests which depend on additional software like Python or node.js. If you don't want to install them or tests fail because of different versions, you can run all tests in a Docker container:

```sh
make test-docker
```

### Coverage

In order to generate a coverage report, run tests using

```sh {"name":"coverage-run"}
make test-coverage
```

And then:

```sh {"id":"01HJVHEVPX2AZJ86999P1MY5H0","name":"coverage-html"}
make test/coverage/html
```

Output coverage profile information for each function
Output coverage profile information for each function:

```sh {"id":"01HJVHHNMZRNK0ZGA154A9AJCZ","name":"coverage-func"}
make test/coverage/func
Expand Down
10 changes: 0 additions & 10 deletions Dockerfile.alpine

This file was deleted.

8 changes: 0 additions & 8 deletions Dockerfile.ubuntu

This file was deleted.

Loading

0 comments on commit 033006a

Please sign in to comment.