diff --git a/.github/actions/env/action.yml b/.github/actions/env/action.yml new file mode 100644 index 0000000..6cb2e58 --- /dev/null +++ b/.github/actions/env/action.yml @@ -0,0 +1,29 @@ +name: Setup Env +description: Setup Env for Linux x64 +inputs: + token: + description: 'A Github PAT' + required: true +runs: + using: composite + steps: + - uses: earthly/actions-setup@v1 + with: + github-token: ${{ inputs.token }} + version: "latest" + use-cache: true + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: "Put back the git branch into git (Earthly uses it for tagging)" + shell: bash + run: | + branch="" + if [ -n "$GITHUB_HEAD_REF" ]; then + branch="$GITHUB_HEAD_REF" + else + branch="${GITHUB_REF##*/}" + fi + git checkout -b "$branch" || true + diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..696d5cf --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,29 @@ +version: 2 +updates: + - package-ecosystem: gomod + directory: "/" + schedule: + interval: daily + open-pull-requests-limit: 40 + labels: [ "dependencies" ] + # Groups are updated together in one pull request + groups: + otel: + patterns: + - "go.opentelemetry.io/otel*" + otel-collector: + patterns: + - "go.opentelemetry.io/collector*" + - "github.com/open-telemetry/o*-collector-contrib/*" + otel-instrumentation: + patterns: + - "go.opentelemetry.io/contrib/instrumentation/*" + go-openapi: + patterns: + - "github.com/go-openapi/*" + + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + labels: [ "dependencies" ] diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..c7c1cd3 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,115 @@ +name: Default +on: + merge_group: + push: + branches: + - main + - releases/* + pull_request: + types: [ assigned, opened, synchronize, reopened, labeled ] + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + PR: + if: github.event_name == 'pull_request' + name: Check PR Title + runs-on: ubuntu-latest + permissions: + statuses: write + steps: + - uses: amannn/action-semantic-pull-request@v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + Dirty: + runs-on: "ubuntu-latest" + steps: + - uses: 'actions/checkout@v4' + with: + fetch-depth: 0 + - name: Setup Env + uses: ./.github/actions/env + with: + token: ${{ secrets.NUMARY_GITHUB_TOKEN }} + - run: > + earthly + --allow-privileged + --secret SPEAKEASY_API_KEY=$SPEAKEASY_API_KEY + ${{ contains(github.event.pull_request.labels.*.name, 'no-cache') && '--no-cache' || '' }} + +pre-commit + env: + SPEAKEASY_API_KEY: ${{ secrets.SPEAKEASY_API_KEY }} + - name: Get changed files + id: changed-files + shell: bash + run: | + hasChanged=$(git status --porcelain) + if (( $(echo ${#hasChanged}) != 0 )); then + git status + echo "There are changes in the repository" + exit 1 + fi + + Tests: + runs-on: "ubuntu-latest" + needs: + - Dirty + steps: + - uses: 'actions/checkout@v4' + with: + fetch-depth: 0 + - name: Setup Env + uses: ./.github/actions/env + with: + token: ${{ secrets.NUMARY_GITHUB_TOKEN }} + - run: > + earthly + --no-output + --allow-privileged + --secret SPEAKEASY_API_KEY=$SPEAKEASY_API_KEY + ${{ contains(github.event.pull_request.labels.*.name, 'no-cache') && '--no-cache' || '' }} + +tests + env: + SPEAKEASY_API_KEY: ${{ secrets.SPEAKEASY_API_KEY }} + + GoReleaser: + runs-on: "ubuntu-latest" + if: contains(github.event.pull_request.labels.*.name, 'build-images') || github.ref == 'refs/heads/main' || github.event_name == 'merge_group' + needs: + - Dirty + steps: + - uses: earthly/actions-setup@v1 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + version: "latest" + - uses: 'actions/checkout@v4' + with: + fetch-depth: 0 + - name: Setup Env + uses: ./.github/actions/env + with: + token: ${{ secrets.NUMARY_GITHUB_TOKEN }} + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: "NumaryBot" + password: ${{ secrets.NUMARY_GITHUB_TOKEN }} + - run: > + earthly + --no-output + --allow-privileged + --secret SPEAKEASY_API_KEY=$SPEAKEASY_API_KEY + --secret GITHUB_TOKEN=$GITHUB_TOKEN + --secret FURY_TOKEN=$FURY_TOKEN + --secret GORELEASER_KEY=$GORELEASER_KEY + ${{ contains(github.event.pull_request.labels.*.name, 'no-cache') && '--no-cache' || '' }} + +release --mode=ci + env: + GITHUB_TOKEN: ${{ secrets.NUMARY_GITHUB_TOKEN }} + SPEAKEASY_API_KEY: ${{ secrets.SPEAKEASY_API_KEY }} + FURY_TOKEN: ${{ secrets.FURY_TOKEN }} + GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} \ No newline at end of file diff --git a/.github/workflows/releases.yml b/.github/workflows/releases.yml new file mode 100644 index 0000000..6a2fbad --- /dev/null +++ b/.github/workflows/releases.yml @@ -0,0 +1,74 @@ +name: Release +on: + push: + tags: + - 'v*.*.*' +permissions: + contents: write + +jobs: + Dirty: + runs-on: "ubuntu-latest" + steps: + - uses: 'actions/checkout@v4' + with: + fetch-depth: 0 + - name: Setup Env + uses: ./.github/actions/env + with: + token: ${{ secrets.NUMARY_GITHUB_TOKEN }} + - run: > + earthly + --allow-privileged + --secret SPEAKEASY_API_KEY=$SPEAKEASY_API_KEY + ${{ contains(github.event.pull_request.labels.*.name, 'no-cache') && '--no-cache' || '' }} + +pre-commit + env: + SPEAKEASY_API_KEY: ${{ secrets.SPEAKEASY_API_KEY }} + - name: Get changed files + id: changed-files + run: | + hasChanged=$(git status --porcelain) + if (( $(echo ${#hasChanged}) != 0 )); then + git status + echo "There are changes in the repository" + exit 1 + fi + + GoReleaser: + runs-on: "ubuntu-latest" + needs: + - Dirty + steps: + - uses: earthly/actions-setup@v1 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + version: "latest" + - uses: 'actions/checkout@v4' + with: + fetch-depth: 0 + - name: Setup Env + uses: ./.github/actions/env + with: + token: ${{ secrets.NUMARY_GITHUB_TOKEN }} + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: "NumaryBot" + password: ${{ secrets.NUMARY_GITHUB_TOKEN }} + - run: > + earthly + --no-output + --allow-privileged + --secret SPEAKEASY_API_KEY=$SPEAKEASY_API_KEY + --secret GITHUB_TOKEN=$GITHUB_TOKEN + --secret FURY_TOKEN=$FURY_TOKEN + --secret GORELEASER_KEY=$GORELEASER_KEY + ${{ contains(github.event.pull_request.labels.*.name, 'no-cache') && '--no-cache' || '' }} + +release --mode=release + env: + GITHUB_TOKEN: ${{ secrets.NUMARY_GITHUB_TOKEN }} + SPEAKEASY_API_KEY: ${{ secrets.SPEAKEASY_API_KEY }} + FURY_TOKEN: ${{ secrets.FURY_TOKEN }} + GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} \ No newline at end of file diff --git a/Earthfile b/Earthfile index 11d1279..bdb16b5 100644 --- a/Earthfile +++ b/Earthfile @@ -1,14 +1,13 @@ VERSION 0.8 -IMPORT github.com/formancehq/earthly:tags/v0.15.0 AS core -IMPORT ../.. AS stack -IMPORT .. AS ee +IMPORT github.com/formancehq/earthly:tags/v0.16.0 AS core + + FROM core+base-image sources: - WORKDIR src - WORKDIR /src/ee/stargate + WORKDIR /src COPY go.* . COPY --dir cmd internal . COPY main.go . @@ -17,7 +16,7 @@ sources: compile: FROM core+builder-image COPY (+sources/*) /src - WORKDIR /src/ee/stargate + WORKDIR /src ARG VERSION=latest DO --pass-args core+GO_COMPILE --VERSION=$VERSION @@ -33,7 +32,7 @@ build-image: tests: FROM core+builder-image COPY (+sources/*) /src - WORKDIR /src/ee/stargate + WORKDIR /src WITH DOCKER --pull=postgres:15-alpine DO --pass-args core+GO_TESTS END @@ -48,14 +47,14 @@ deploy: RUN kubectl patch Versions.formance.com default -p "{\"spec\":{\"stargate\": \"${tag}\"}}" --type=merge deploy-staging: - BUILD --pass-args stack+deployer-module --MODULE=stargate + BUILD --pass-args core+deployer-module --MODULE=stargate lint: FROM core+builder-image COPY (+sources/*) /src COPY --pass-args +tidy/go.* . - WORKDIR /src/ee/stargate - DO --pass-args stack+GO_LINT + WORKDIR /src + DO --pass-args core+GO_LINT SAVE ARTIFACT cmd AS LOCAL cmd SAVE ARTIFACT internal AS LOCAL internal SAVE ARTIFACT main.go AS LOCAL main.go @@ -72,8 +71,8 @@ openapi: tidy: FROM core+builder-image COPY --pass-args (+sources/src) /src - WORKDIR /src/ee/stargate - DO --pass-args stack+GO_TIDY + WORKDIR /src + DO --pass-args core+GO_TIDY grpc-generate: FROM core+grpc-base @@ -83,4 +82,7 @@ grpc-generate: SAVE ARTIFACT generated AS LOCAL internal/generated release: - BUILD --pass-args stack+goreleaser --path=ee/stargate \ No newline at end of file + FROM core+builder-image + ARG mode=local + COPY --dir . /src + DO core+GORELEASER --mode=$mode \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4f864e6 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +MIT License + +Copyright (c) 2021-present Formance Solutions + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/go.mod b/go.mod index db31915..299fddf 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/go-chi/cors v1.2.1 github.com/pkg/errors v0.9.1 github.com/spf13/cobra v1.8.1 - github.com/zitadel/oidc v1.13.4 + github.com/zitadel/oidc v1.13.5 go.opentelemetry.io/otel v1.30.0 go.opentelemetry.io/otel/metric v1.30.0 go.uber.org/fx v1.22.2 diff --git a/go.sum b/go.sum index 289716e..b5b137d 100644 --- a/go.sum +++ b/go.sum @@ -103,8 +103,8 @@ github.com/uptrace/opentelemetry-go-extra/otelutil v0.3.2 h1:3/aHKUq7qaFMWxyQV0W github.com/uptrace/opentelemetry-go-extra/otelutil v0.3.2/go.mod h1:Zit4b8AQXaXvA68+nzmbyDzqiyFRISyw1JiD5JqUBjw= github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= -github.com/zitadel/oidc v1.13.4 h1:+k2GKqP9Ld9S2MSFlj+KaNsoZ3J9oy+Ezw51EzSFuC8= -github.com/zitadel/oidc v1.13.4/go.mod h1:3h2DhUcP02YV6q/CA/BG4yla0o6rXjK+DkJGK/dwJfw= +github.com/zitadel/oidc v1.13.5 h1:7jhh68NGZitLqwLiVU9Dtwa4IraJPFF1vS+4UupO93U= +github.com/zitadel/oidc v1.13.5/go.mod h1:rHs1DhU3Sv3tnI6bQRVlFa3u0lCwtR7S21WHY+yXgPA= go.opentelemetry.io/contrib/instrumentation/host v0.55.0 h1:V/Cy5A2ydwvyED4ewwXJ441R3QllG+U8tXXVOjPeX4Y= go.opentelemetry.io/contrib/instrumentation/host v0.55.0/go.mod h1:fsY+EfHPwa1bQcxOUPv1FWaQXAwY+RliLRs6B6qgJes= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.55.0 h1:ZIg3ZT/aQ7AfKqdwp7ECpOK6vHqquXXuyTjIO8ZdmPs=