From b8b3861c1c2f8e3d811ef73a36eda9e08c57a2ae Mon Sep 17 00:00:00 2001 From: Rotem Tamir Date: Thu, 27 Jul 2023 12:27:22 +0300 Subject: [PATCH] all: basic project --- .github/workflows/Dockerfile | 16 +++++++ .github/workflows/ci-go.yaml | 84 ++++++++++++++++++++++++++++++++++++ action.yml | 17 ++++++++ go.mod | 7 +++ go.sum | 4 ++ internal/action/action.yml | 3 ++ main.go | 8 ++++ main_test.go | 7 +++ 8 files changed, 146 insertions(+) create mode 100644 .github/workflows/Dockerfile create mode 100644 .github/workflows/ci-go.yaml create mode 100644 action.yml create mode 100644 go.mod create mode 100644 go.sum create mode 100644 internal/action/action.yml create mode 100644 main.go create mode 100644 main_test.go diff --git a/.github/workflows/Dockerfile b/.github/workflows/Dockerfile new file mode 100644 index 0000000..7a8d648 --- /dev/null +++ b/.github/workflows/Dockerfile @@ -0,0 +1,16 @@ +FROM golang:1.20 as build + +WORKDIR /go/src/app +COPY . . + +RUN go mod download +RUN go vet -v +RUN go test -v + +RUN CGO_ENABLED=0 go build -o /go/bin/app + +FROM gcr.io/distroless/static-debian11 + +COPY --from=build /go/bin/app / + +CMD ["/app"] \ No newline at end of file diff --git a/.github/workflows/ci-go.yaml b/.github/workflows/ci-go.yaml new file mode 100644 index 0000000..00116a2 --- /dev/null +++ b/.github/workflows/ci-go.yaml @@ -0,0 +1,84 @@ +name: CI (Go) +on: + push: + workflow_dispatch: +jobs: + golangci-lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v4 + with: + go-version: "1.20" + - uses: actions/cache@v3 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - name: Run Go linters + uses: golangci/golangci-lint-action@v3 + with: + args: --timeout=15m --verbose --enable whitespace,gocritic,goimports,revive + skip-pkg-cache: true + unit-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v4 + with: + go-version: "1.20" + - uses: actions/cache@v3 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - name: Run tests + run: | + go test -race ./... + integration-tests: + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + steps: + - uses: actions/checkout@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Build + uses: docker/build-push-action@v2 + with: + context: . + file: ./.github/workflows/Dockerfile + tags: local + load: true + - run: docker images + - name: sanity + uses: ./internal/action + with: + url: sqlite://file.db + docker: + runs-on: ubuntu-latest + needs: [golangci-lint, unit-tests, integration-tests] + if: github.ref == 'refs/heads/master' + steps: + - uses: actions/checkout@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + push: true + file: ./.github/workflows/Dockerfile + tags: arigaio/atlas-deploy-action:latest \ No newline at end of file diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..e8480bc --- /dev/null +++ b/action.yml @@ -0,0 +1,17 @@ +name: 'atlas-deploy-action' +description: 'Deploy your database schema migrations using Atlas' +branding: + icon: database +author: 'Ariga' +inputs: + url: + description: 'URL to target database (should be passed as a secret).' + required: true + cloud-token: + description: 'Token for using Atlas Cloud (should be passed as a secret).' + required: false + cloud-dir: + description: 'Name of the migration directory in the cloud' +runs: + using: 'docker' + image: 'docker://arigaio/atlas-deploy-action:latest' diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..21b3449 --- /dev/null +++ b/go.mod @@ -0,0 +1,7 @@ +module github.com/ariga/atlas-deploy-action + +go 1.20 + +require github.com/sethvargo/go-githubactions v1.1.0 + +require github.com/sethvargo/go-envconfig v0.9.0 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..757224e --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +github.com/sethvargo/go-envconfig v0.9.0 h1:Q6FQ6hVEeTECULvkJZakq3dZMeBQ3JUpcKMfPQbKMDE= +github.com/sethvargo/go-envconfig v0.9.0/go.mod h1:Iz1Gy1Sf3T64TQlJSvee81qDhf7YIlt8GMUX6yyNFs0= +github.com/sethvargo/go-githubactions v1.1.0 h1:mg03w+b+/s5SMS298/2G6tHv8P0w0VhUFaqL1THIqzY= +github.com/sethvargo/go-githubactions v1.1.0/go.mod h1:qIboSF7yq2Qnaw2WXDsqCReM0Lo1gU4QXUWmhBC3pxE= diff --git a/internal/action/action.yml b/internal/action/action.yml new file mode 100644 index 0000000..03c31d6 --- /dev/null +++ b/internal/action/action.yml @@ -0,0 +1,3 @@ +runs: + using: 'docker' + image: 'docker://local' \ No newline at end of file diff --git a/main.go b/main.go new file mode 100644 index 0000000..71f8b06 --- /dev/null +++ b/main.go @@ -0,0 +1,8 @@ +package main + +import "github.com/sethvargo/go-githubactions" + +func main() { + act := githubactions.New() + act.Infof("Hello, world!") +} diff --git a/main_test.go b/main_test.go new file mode 100644 index 0000000..6c86277 --- /dev/null +++ b/main_test.go @@ -0,0 +1,7 @@ +package main + +import "testing" + +func Test(t *testing.T) { + t.Skip("skipping") +}