mirror of
https://github.com/TECHNOFAB11/dbmate.git
synced 2025-12-12 08:00:04 +01:00
Build using native OS workers (#231)
This commit is contained in:
parent
06d8bb7567
commit
f69f1dea03
7 changed files with 123 additions and 96 deletions
104
.github/workflows/ci.yml
vendored
104
.github/workflows/ci.yml
vendored
|
|
@ -3,44 +3,94 @@ name: CI
|
|||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
tags: "v*"
|
||||
tags: "*"
|
||||
pull_request:
|
||||
branches: [main]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: linux
|
||||
image: ubuntu-latest
|
||||
arch: amd64
|
||||
env: {}
|
||||
- os: linux
|
||||
image: ubuntu-latest
|
||||
arch: arm64
|
||||
setup: sudo apt-get update && sudo apt-get install -qq gcc-aarch64-linux-gnu
|
||||
env:
|
||||
CC: aarch64-linux-gnu-gcc
|
||||
CXX: aarch64-linux-gnu-g++
|
||||
- os: macos
|
||||
image: macos-latest
|
||||
arch: amd64
|
||||
env: {}
|
||||
- os: macos
|
||||
image: macos-latest
|
||||
arch: arm64
|
||||
env: {}
|
||||
- os: windows
|
||||
image: windows-latest
|
||||
arch: amd64
|
||||
env: {}
|
||||
|
||||
name: Build (${{ matrix.os }}/${{ matrix.arch }})
|
||||
runs-on: ${{ matrix.image }}
|
||||
env: ${{ matrix.env }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: "1.17"
|
||||
|
||||
- name: Setup environment
|
||||
run: ${{ matrix.setup }}
|
||||
|
||||
- run: go mod download
|
||||
|
||||
- run: make build ls
|
||||
env:
|
||||
GOARCH: ${{ matrix.arch }}
|
||||
OUTPUT: dbmate-${{ matrix.os }}-${{ matrix.arch }}
|
||||
|
||||
- run: dist/dbmate-${{ matrix.os }}-${{ matrix.arch }} --help
|
||||
if: ${{ matrix.arch == 'amd64' }}
|
||||
|
||||
- name: Publish binaries
|
||||
uses: softprops/action-gh-release@v1
|
||||
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
|
||||
with:
|
||||
files: dist/dbmate-*
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
docker:
|
||||
name: Docker Test (linux/amd64)
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Environment
|
||||
- name: Check docker environment
|
||||
run: |
|
||||
set -x
|
||||
docker version
|
||||
docker-compose version
|
||||
|
||||
- name: Cache
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
key: cache
|
||||
path: .cache
|
||||
|
||||
- name: Build docker image
|
||||
run: |
|
||||
set -x
|
||||
docker-compose build
|
||||
docker-compose run --rm --no-deps dbmate --version
|
||||
|
||||
- name: Build binaries
|
||||
run: |
|
||||
set -x
|
||||
docker-compose run --rm --no-deps dev make build-all
|
||||
dist/dbmate-linux-amd64 --version
|
||||
- name: Run make build
|
||||
run: docker-compose run --rm --no-deps dev make build ls
|
||||
|
||||
- name: Lint
|
||||
- name: Run make lint
|
||||
run: docker-compose run --rm --no-deps dev make lint
|
||||
|
||||
- name: Start test dependencies
|
||||
|
|
@ -48,12 +98,10 @@ jobs:
|
|||
set -x
|
||||
docker-compose pull --quiet
|
||||
docker-compose up --detach
|
||||
|
||||
- name: Run tests
|
||||
run: |
|
||||
set -x
|
||||
docker-compose run --rm dev make wait
|
||||
docker-compose run --rm dev make test
|
||||
|
||||
- name: Run make test
|
||||
run: docker-compose run --rm dev make test
|
||||
|
||||
- name: Publish docker image
|
||||
if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') }}
|
||||
|
|
@ -65,12 +113,4 @@ jobs:
|
|||
GHCR_IMAGE: ghcr.io/${{ github.repository }}
|
||||
GHCR_USERNAME: ${{ github.actor }}
|
||||
GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: .github/workflows/publish-docker.sh
|
||||
|
||||
- name: Publish release binaries
|
||||
uses: softprops/action-gh-release@v1
|
||||
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
|
||||
with:
|
||||
files: dist/*
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: ci/publish-docker.sh
|
||||
|
|
|
|||
43
.github/workflows/publish-docker.sh
vendored
43
.github/workflows/publish-docker.sh
vendored
|
|
@ -1,43 +0,0 @@
|
|||
#!/bin/bash
|
||||
# Tag and publish Docker image
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
echo "$DOCKERHUB_TOKEN" | (set -x && docker login --username "$DOCKERHUB_USERNAME" --password-stdin)
|
||||
echo "$GHCR_TOKEN" | (set -x && docker login ghcr.io --username "$GHCR_USERNAME" --password-stdin)
|
||||
|
||||
# Tag and push docker image
|
||||
function docker_push {
|
||||
src=$1
|
||||
dst=$2
|
||||
echo # newline
|
||||
|
||||
(
|
||||
set -x
|
||||
docker tag "$src" "$dst"
|
||||
docker push "$dst"
|
||||
)
|
||||
}
|
||||
|
||||
# Publish image to both Docker Hub and GitHub Container Registry
|
||||
function publish {
|
||||
tag=$1
|
||||
docker_push "$SRC_IMAGE" "$DOCKERHUB_IMAGE:$tag"
|
||||
docker_push "$SRC_IMAGE" "$GHCR_IMAGE:$tag"
|
||||
}
|
||||
|
||||
if [[ "$GITHUB_REF" = refs/tags/v* ]]; then
|
||||
# Publish major/minor/patch/latest version tags
|
||||
ver=${GITHUB_REF#refs/tags/v}
|
||||
|
||||
publish "$ver" # e.g. `1.2.3`
|
||||
publish "${ver%.*}" # e.g. `1.2`
|
||||
publish "${ver%%.*}" # e.g. `1`
|
||||
publish "latest"
|
||||
else
|
||||
# Publish branch
|
||||
publish "${GITHUB_REF##*/}"
|
||||
fi
|
||||
|
||||
# Clear credentials
|
||||
rm -f ~/.docker/config.json
|
||||
Loading…
Add table
Add a link
Reference in a new issue