Support build docker image (#209) #1065
This file contains 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: Build | |
on: [push, pull_request] | |
jobs: | |
test: | |
name: test (postgres ${{ matrix.pgVersion }}) | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
pgVersion: ['14.8', '15.3', '16.0', 'latest'] | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '1.21' | |
- name: Run tests | |
run: go test ./... | |
env: | |
POSTGRES_VERSION: ${{ matrix.pgVersion }} | |
lint: | |
name: lint | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '1.21' | |
- name: golangci-lint | |
uses: golangci/golangci-lint-action@v3 | |
with: | |
# Require: The version of golangci-lint to use. | |
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version. | |
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit. | |
version: v1.54.2 | |
# Optional: golangci-lint command line arguments. | |
# | |
# Note: By default, the `.golangci.yml` file should be at the root of the repository. | |
# The location of the configuration file can be changed by using `--config=` | |
args: --timeout=30m --out-format=colored-line-number --config=.golangci.yml | |
- name: Ensure JSON examples are formatted | |
run: | | |
for file in ./examples/*.json; do | |
if ! diff <(cat $file | jq) <(cat $file); then | |
echo "$file is not formatted: run 'cat $file | jq' to fix"; | |
exit 1; | |
fi | |
done | |
license-check: | |
name: License check | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Ensure .go files have a license reference | |
run: | | |
curl -s https://raw.githubusercontent.com/lluissm/license-header-checker/master/install.sh | bash | |
./bin/license-header-checker -a -r .github/license-header.txt . go && [[ -z `git status -s` ]] | |
examples: | |
name: examples (postgres ${{ matrix.pgVersion }}) | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
pgVersion: ['14.8', '15.3', '16.0', 'latest'] | |
services: | |
postgres: | |
image: postgres:${{ matrix.pgVersion }} | |
env: | |
POSTGRES_PASSWORD: postgres | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
ports: | |
- 5432:5432 | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '1.21' | |
- name: Run example migrations | |
run: | | |
go run . init | |
for file in ./examples/*.json; do | |
if [ -f "$file" ]; then | |
go run . start --complete $file; | |
fi | |
done | |
release: | |
runs-on: ubuntu-latest | |
needs: [test, lint, examples, license-check] | |
if: startsWith(github.ref, 'refs/tags/') | |
env: | |
DOCKER_CLI_EXPERIMENTAL: "enabled" | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- run: git fetch --force --tags | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GIT_TOKEN }} | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '1.21' | |
- name: Run GoReleaser | |
uses: goreleaser/goreleaser-action@v5 | |
with: | |
distribution: goreleaser | |
version: latest | |
args: release --clean | |
env: | |
GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }} | |
GITHUB_USERNAME: ${{ github.repository_owner }} | |
DOCKER_USERNAME: ghcr.io/${{ github.repository_owner }} |