From 77d584c4491e2cfeaa70df56675a09ddfc287880 Mon Sep 17 00:00:00 2001 From: Maxence Maireaux Date: Wed, 19 Apr 2023 11:46:53 +0200 Subject: [PATCH 1/4] ci: Add build.Dockerfile & Use in GoReleaser --- .goreleaser.yml | 4 ++-- build.Dockerfile | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 build.Dockerfile diff --git a/.goreleaser.yml b/.goreleaser.yml index bd4419142..07db1ad98 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -130,7 +130,7 @@ publishers: dockers: - image_templates: ["ghcr.io/formancehq/{{ .ProjectName }}:{{ .Version }}-amd64"] - dockerfile: Dockerfile + dockerfile: build.Dockerfile use: buildx build_flag_templates: - --platform=linux/amd64 @@ -144,7 +144,7 @@ dockers: - --label=org.opencontainers.image.licenses=MIT - image_templates: [ "ghcr.io/formancehq/{{ .ProjectName }}:{{ .Version }}-arm64" ] goarch: arm64 - dockerfile: Dockerfile + dockerfile: build.Dockerfile use: buildx build_flag_templates: - --platform=linux/arm64/v8 diff --git a/build.Dockerfile b/build.Dockerfile new file mode 100644 index 000000000..4422ddd94 --- /dev/null +++ b/build.Dockerfile @@ -0,0 +1,6 @@ +FROM ubuntu:jammy +RUN apt update && apt install -y ca-certificates curl && rm -rf /var/lib/apt/lists/* +COPY numary /usr/bin/numary +ENV OTEL_SERVICE_NAME numary +ENTRYPOINT ["/usr/bin/numary"] +CMD ["serve", "start"] From ab366e33d41c9ecf4832fcf8a5f7ecef8337f6cf Mon Sep 17 00:00:00 2001 From: Maxence Maireaux Date: Wed, 19 Apr 2023 16:13:29 +0200 Subject: [PATCH 2/4] feat: Update config for release --- .github/CODEOWNERS | 9 ++ .github/ISSUE_TEMPLATE/bug_report.md | 27 ++++ .github/ISSUE_TEMPLATE/feature_request.md | 22 +++ .../pull_request_sdk_template.md | 8 + .../pull_request_template.md | 22 +++ .github/dependabot.yml | 8 + .github/labeler.yml | 23 +++ .github/workflows/benchmarks.yaml | 18 +++ .github/workflows/codeql.yml | 33 ++++ .github/workflows/main.yml | 144 ++++++++++++++++++ .github/workflows/pr_open_target.yml | 12 ++ .github/workflows/release.yml | 118 -------------- .github/workflows/template_build-control.yaml | 20 +++ .github/workflows/template_docker.yaml | 81 ++++++++++ .../workflows/template_goreleaser-build.yaml | 53 +++++++ .../template_goreleaser-release.yaml | 65 ++++++++ .github/workflows/template_sdk-generate.yaml | 35 +++++ .github/workflows/template_sdk-publish.yaml | 57 +++++++ .goreleaser.yml | 53 ++----- Dockerfile | 13 +- build.Dockerfile | 6 - 21 files changed, 657 insertions(+), 170 deletions(-) create mode 100644 .github/CODEOWNERS create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/PULL_REQUEST_TEMPLATE/pull_request_sdk_template.md create mode 100644 .github/PULL_REQUEST_TEMPLATE/pull_request_template.md create mode 100644 .github/dependabot.yml create mode 100644 .github/labeler.yml create mode 100644 .github/workflows/benchmarks.yaml create mode 100644 .github/workflows/codeql.yml create mode 100644 .github/workflows/main.yml create mode 100644 .github/workflows/pr_open_target.yml delete mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/template_build-control.yaml create mode 100644 .github/workflows/template_docker.yaml create mode 100644 .github/workflows/template_goreleaser-build.yaml create mode 100644 .github/workflows/template_goreleaser-release.yaml create mode 100644 .github/workflows/template_sdk-generate.yaml create mode 100644 .github/workflows/template_sdk-publish.yaml delete mode 100644 build.Dockerfile diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 000000000..c381fc0f5 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,9 @@ +/api/ @formancehq/dev-backend +/cmd/ @formancehq/dev-backend +/config/ @formancehq/dev-backend +/core/ @formancehq/dev-backend +/ledger/ @formancehq/dev-backend +*.go @formancehq/dev-backend + +/.devcontainer @flemzord +/.github @flemzord diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 000000000..f7757cdf9 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,27 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: bug +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Logs** +If applicable, add logs to help explain your problem. + +**Environment (please complete the following information):** + - OS: [e.g. ubuntu 20.04] + - Numary Version [e.g. 1.0.0-beta.4] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 000000000..b36319bac --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,22 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: enhancement, rfc +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Summary** + +**Solution proposal** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/PULL_REQUEST_TEMPLATE/pull_request_sdk_template.md b/.github/PULL_REQUEST_TEMPLATE/pull_request_sdk_template.md new file mode 100644 index 000000000..3f9f8c2a9 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE/pull_request_sdk_template.md @@ -0,0 +1,8 @@ +# SDK : OPEN API GENERATOR NAME + +__Please add a description to this PR.__ + +## How to deploy + +__Please provide steps to deploy the generated sdk to official channels.__ +__Please be as exhaustive as possible__ diff --git a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md new file mode 100644 index 000000000..3d9bbad90 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md @@ -0,0 +1,22 @@ +# Title + +__Please add a description to this PR.__ + +## Type of change + +- [ ] Bug fix (non-breaking change which fixes an issue) +- [ ] New feature (non-breaking change which adds functionality) +- [ ] Refactoring / Technical debt + +## What parts of the code are impacted ? +__Please describe the impacted parts of the code.__ + +# Checklist: + +- [ ] My code follows the style guidelines of this project +- [ ] I have performed a self-review of my code +- [ ] I have commented my code, particularly in hard-to-understand areas +- [ ] I have made corresponding changes to the documentation +- [ ] My changes generate no new warnings +- [ ] I have added tests that prove my fix is effective or that my feature works +- [ ] New and existing unit tests pass locally with my changes diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 000000000..cd51d2c60 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,8 @@ +version: 2 +updates: + + - package-ecosystem: "github-actions" + directory: "/" + schedule: + # Check for updates to GitHub Actions every weekday + interval: "daily" diff --git a/.github/labeler.yml b/.github/labeler.yml new file mode 100644 index 000000000..66ae675cd --- /dev/null +++ b/.github/labeler.yml @@ -0,0 +1,23 @@ +'@domain/core': + - core/* + - core/**/* + +'@domain/api': + - api/* + - api/**/* + +'@domain/ledger': + - ledger/* + - ledger/**/* + +'@domain/storage': + - storage/* + - storage/**/* + +'@domain/cmd': + - cmd/* + - cmd/**/* + +'@domain/ci': + - .github/* + - .github/**/* diff --git a/.github/workflows/benchmarks.yaml b/.github/workflows/benchmarks.yaml new file mode 100644 index 000000000..ec4a1ef34 --- /dev/null +++ b/.github/workflows/benchmarks.yaml @@ -0,0 +1,18 @@ +name: Benchmarks +on: + workflow_dispatch + +jobs: + bench: + runs-on: ubuntu-latest + steps: + - name: Install task + uses: arduino/setup-task@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version-file: 'go.mod' + - name: Run bench + run: task install:perf bench diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 000000000..773d9fba0 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,33 @@ +name: "CodeQL" + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + schedule: + - cron: '35 21 * * 5' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + strategy: + fail-fast: false + matrix: + language: [ 'go' ] + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 000000000..993c3433d --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,144 @@ +on: + push: + branches: + - main + pull_request: + types: [ assigned, opened, synchronize, reopened ] + release: + types: [ prereleased, released ] + +name: Main +jobs: + Pr: + if: github.event_name == 'pull_request' + uses: formancehq/gh-workflows/.github/workflows/pr-style.yml@main + + Lint: + uses: formancehq/gh-workflows/.github/workflows/golang-lint.yml@main + + Control: + name: 'Control' + needs: + - Lint + uses: ./.github/workflows/template_build-control.yaml + secrets: + NUMARY_GITHUB_TOKEN: ${{ secrets.NUMARY_GITHUB_TOKEN }} + + Test_postgres: + uses: formancehq/gh-workflows/.github/workflows/golang-test-postgres.yml@main + + Test_sqlite: + uses: formancehq/gh-workflows/.github/workflows/golang-test.yml@main + + Bench: + runs-on: ubuntu-latest + steps: + - name: Install task + uses: arduino/setup-task@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version-file: 'go.mod' + cache: true + - name: Run ledger package benchmarks + run: task install:perf bench PKG=./pkg/ledger RUN=BenchmarkLedger + + GoReleaserBuild: + if: github.event_name != 'release' + name: 'GoReleaser Build' + needs: + - Control + - Test_sqlite + - Test_postgres + uses: ./.github/workflows/template_goreleaser-build.yaml + secrets: + NUMARY_GITHUB_TOKEN: ${{ secrets.NUMARY_GITHUB_TOKEN }} + SEGMENT_WRITE_KEY_OSS: ${{ secrets.SEGMENT_WRITE_KEY_OSS }} + + GoReleaserRelease: + if: github.event_name == 'release' + name: 'GoReleaser Release' + needs: + - Control + - Test_sqlite + - Test_postgres + uses: ./.github/workflows/template_goreleaser-release.yaml + secrets: + NUMARY_GITHUB_TOKEN: ${{ secrets.NUMARY_GITHUB_TOKEN }} + SEGMENT_WRITE_KEY_OSS: ${{ secrets.SEGMENT_WRITE_KEY_OSS }} + FURY_TOKEN: ${{ secrets.FURY_TOKEN }} + + SdkGenerate: + needs: + - GoReleaserBuild + uses: ./.github/workflows/template_sdk-generate.yaml + secrets: + NUMARY_GITHUB_TOKEN: ${{ secrets.NUMARY_GITHUB_TOKEN }} + + SdkPublish: + needs: + - GoReleaserRelease + uses: ./.github/workflows/template_sdk-publish.yaml + with: + VERSION: ${{ github.event.release.tag_name }} + secrets: + NUMARY_GITHUB_TOKEN: ${{ secrets.NUMARY_GITHUB_TOKEN }} + + DockerRelease: + if: github.event_name == 'release' + uses: ./.github/workflows/template_docker.yaml + needs: + - Control + - Test_sqlite + - Test_postgres + with: + VERSION: ${{ github.event.release.tag_name }} + APP_SHA: ${{ github.sha }} + RELEASE: ${{ github.event.action }} + secrets: + NUMARY_GITHUB_TOKEN: ${{ secrets.NUMARY_GITHUB_TOKEN }} + SEGMENT_WRITE_KEY_OSS: ${{ secrets.SEGMENT_WRITE_KEY_OSS }} + + DockerBranch: + if: github.event_name != 'release' + uses: ./.github/workflows/template_docker.yaml + needs: + - Control + - Test_sqlite + - Test_postgres + with: + VERSION: develop + APP_SHA: ${{ github.sha }} + RELEASE: ${{ github.event.action }} + secrets: + NUMARY_GITHUB_TOKEN: ${{ secrets.NUMARY_GITHUB_TOKEN }} + SEGMENT_WRITE_KEY_OSS: ${{ secrets.SEGMENT_WRITE_KEY_OSS }} + +# Check-pkgs: +# if: github.event_name == 'release' +# runs-on: ubuntu-latest +# env: +# DOCKER_CLI_EXPERIMENTAL: "enabled" +# needs: +# - GoReleaserRelease +# strategy: +# matrix: +# format: [ deb, rpm ] +# steps: +# - uses: actions/checkout@v3 +# with: +# fetch-depth: 0 +# - uses: arduino/setup-task@v1 +# with: +# version: 3.x +# repo-token: ${{ secrets.GITHUB_TOKEN }} +# - uses: docker/setup-qemu-action@v1 +# - uses: actions/cache@v2 +# with: +# path: | +# ./dist/*.deb +# ./dist/*.rpm +# key: ${{ runner.os }}-go-${{ hashFiles('**/*.go') }}-${{ hashFiles('**/go.sum') }} +# - run: task goreleaser:test:${{ matrix.format }} diff --git a/.github/workflows/pr_open_target.yml b/.github/workflows/pr_open_target.yml new file mode 100644 index 000000000..3caf1e330 --- /dev/null +++ b/.github/workflows/pr_open_target.yml @@ -0,0 +1,12 @@ +name: "Pull Request Labeler" +on: + - pull_request_target +# - pull_request + +jobs: + Triage: + runs-on: ubuntu-latest + steps: + - uses: actions/labeler@v3 + with: + repo-token: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 67e2d9dc4..000000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,118 +0,0 @@ -name: Ledger - Release -on: - push: - tags: - - 'v*.*.*' - -jobs: - Control: - name: 'Build Control' - runs-on: ubuntu-latest - steps: - - run: curl -OL https://github.com/numary/control/releases/download/1.2.0/numary-control-1.2.0.tar.gz - - run: tar -zxvf numary-control-1.2.0.tar.gz - - run: rm -rf numary-control-1.2.0.tar.gz - - uses: actions/upload-artifact@v2 - with: - name: control-dist - path: ./** - - Lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Install Task - uses: arduino/setup-task@v1 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - - uses: actions/setup-go@v3 - with: - go-version-file: go.mod - cache-dependency-path: go.sum - cache: true - - run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.2 - - run: task lint - - Tests: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - name: Install Task - uses: arduino/setup-task@v1 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - - uses: actions/setup-go@v3 - with: - go-version-file: go.mod - cache-dependency-path: go.sum - cache: true - - run: task tests - - name: Upload coverage report to Codecov - uses: codecov/codecov-action@v3 - with: - name: 'Ledger' - fail_ci_if_error: false # optional (default = false) - verbose: true # optional (default = false) - - GoReleaser: - name: GoReleaser - strategy: - matrix: - os: [ ubuntu-latest, macos-latest ] - runs-on: ${{ matrix.os }} - env: - DOCKER_CLI_EXPERIMENTAL: "enabled" - needs: - - Tests - - Lint - - Control - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - uses: actions/setup-go@v3 - with: - go-version-file: 'go.mod' - cache: true - - name: fetch numary control - uses: actions/download-artifact@v2 - with: - name: control-dist - path: cmd/control/ - - run: sudo apt install gcc-aarch64-linux-gnu gcc-mingw-w64 -y - if: ${{ matrix.os == 'ubuntu-latest' }} - - name: Run GoReleaser for Linux - if: ${{ matrix.os == 'ubuntu-latest' }} - env: - GITHUB_TOKEN: ${{ secrets.NUMARY_GITHUB_TOKEN }} - FURY_TOKEN: ${{ secrets.FURY_TOKEN }} - SEGMENT_WRITE_KEY: ${{ secrets.SEGMENT_WRITE_KEY_OSS }} - uses: goreleaser/goreleaser-action@v4 - with: - version: latest - args: release --rm-dist - - name: Run GoReleaser for MacOS - if: ${{ matrix.os == 'macos-latest' }} - env: - GITHUB_TOKEN: ${{ secrets.NUMARY_GITHUB_TOKEN }} - FURY_TOKEN: ${{ secrets.FURY_TOKEN }} - SEGMENT_WRITE_KEY: ${{ secrets.SEGMENT_WRITE_KEY_OSS }} - uses: goreleaser/goreleaser-action@v4 - with: - version: latest - args: release -f .goreleaser-darwin.yml --rm-dist - - uses: actions/cache@v2 - with: - path: | - ./dist/*.deb - ./dist/*.rpm - ./dist/*.apk - key: ${{ runner.os }}-go-${{ hashFiles('**/*.go') }}-${{ hashFiles('**/go.sum') }} diff --git a/.github/workflows/template_build-control.yaml b/.github/workflows/template_build-control.yaml new file mode 100644 index 000000000..86b3f7eb9 --- /dev/null +++ b/.github/workflows/template_build-control.yaml @@ -0,0 +1,20 @@ +name: Build for Control +on: + workflow_call: + secrets: + NUMARY_GITHUB_TOKEN: + required: true + description: GitHub token with access to the repo + +jobs: + build: + name: 'Build Control' + runs-on: ubuntu-latest + steps: + - run: curl -OL https://github.com/numary/control/releases/download/1.2.0/numary-control-1.2.0.tar.gz + - run: tar -zxvf numary-control-1.2.0.tar.gz + - run: rm -rf numary-control-1.2.0.tar.gz + - uses: actions/upload-artifact@v2 + with: + name: control-dist + path: ./** diff --git a/.github/workflows/template_docker.yaml b/.github/workflows/template_docker.yaml new file mode 100644 index 000000000..50f774c0f --- /dev/null +++ b/.github/workflows/template_docker.yaml @@ -0,0 +1,81 @@ +name: Docker Build & Publish +on: + workflow_call: + inputs: + VERSION: + type: string + required: true + description: The tag name to use for Docker. + APP_SHA: + type: string + required: true + description: The sha to use for Docker. + RELEASE: + type: string + required: true + description: Whether to release the Docker image. + secrets: + NUMARY_GITHUB_TOKEN: + required: true + description: GitHub token with access to the repo + SEGMENT_WRITE_KEY_OSS: + required: true + description: Segment write key for the OSS repo + +jobs: + Docker: + name: 'Build & Publish Docker' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: fetch numary control + uses: actions/download-artifact@v2 + with: + name: control-dist + path: cmd/control/ + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: "NumaryBot" + password: ${{ secrets.NUMARY_GITHUB_TOKEN }} + - name: Build and push Released + if: inputs.RELEASE == 'released' + uses: docker/build-push-action@v2 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: ghcr.io/formancehq/ledger:latest,ghcr.io/formancehq/ledger:${{ inputs.VERSION }} + build-args: | + APP_SHA=${{ inputs.APP_SHA }} + VERSION=${{ inputs.VERSION }} + SEGMENT_WRITE_KEY=${{ secrets.SEGMENT_WRITE_KEY_OSS }} + - name: Build and push PreReleased + if: inputs.RELEASE == 'prereleased' + uses: docker/build-push-action@v2 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: ghcr.io/formancehq/ledger:${{ inputs.VERSION }} + build-args: | + APP_SHA=${{ inputs.APP_SHA }} + VERSION=${{ inputs.VERSION }} + SEGMENT_WRITE_KEY=${{ secrets.SEGMENT_WRITE_KEY_OSS }} + - name: Build and push + if: inputs.RELEASE != 'released' || inputs.RELEASE != 'prereleased' + uses: docker/build-push-action@v2 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: ghcr.io/formancehq/ledger:${{ inputs.APP_SHA }} + build-args: | + APP_SHA=${{ inputs.APP_SHA }} + VERSION=${{ inputs.VERSION }} + SEGMENT_WRITE_KEY=${{ secrets.SEGMENT_WRITE_KEY_OSS }} diff --git a/.github/workflows/template_goreleaser-build.yaml b/.github/workflows/template_goreleaser-build.yaml new file mode 100644 index 000000000..547bcee24 --- /dev/null +++ b/.github/workflows/template_goreleaser-build.yaml @@ -0,0 +1,53 @@ +name: GoReleaser Build +on: + workflow_call: + secrets: + NUMARY_GITHUB_TOKEN: + required: true + description: GitHub token with access to the repo + SEGMENT_WRITE_KEY_OSS: + required: true + description: Segment write key for the OSS repo + +jobs: + goreleaser: + name: GoReleaser Build + strategy: + matrix: + os: [ ubuntu-latest, macos-latest ] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version-file: 'go.mod' + cache: true + - name: fetch numary control + uses: actions/download-artifact@v2 + with: + name: control-dist + path: cmd/control/ + - run: sudo apt install gcc-aarch64-linux-gnu gcc-mingw-w64 -y + if: ${{ matrix.os == 'ubuntu-latest' }} + - name: Run GoReleaser for Linux + if: ${{ matrix.os == 'ubuntu-latest' }} + uses: goreleaser/goreleaser-action@v4 + with: + version: latest + args: build --parallelism 4 --rm-dist --skip-validate --snapshot + env: + GITHUB_TOKEN: ${{ secrets.NUMARY_GITHUB_TOKEN }} + SEGMENT_WRITE_KEY: ${{ secrets.SEGMENT_WRITE_KEY_OSS }} + - name: Run GoReleaser for MacOS + if: ${{ matrix.os == 'macos-latest' }} + uses: goreleaser/goreleaser-action@v4 + with: + version: latest + args: build -f .goreleaser-darwin.yml --parallelism 4 --rm-dist --skip-validate --snapshot + env: + GITHUB_TOKEN: ${{ secrets.NUMARY_GITHUB_TOKEN }} + SEGMENT_WRITE_KEY: ${{ secrets.SEGMENT_WRITE_KEY_OSS }} + - uses: actions/upload-artifact@v2 + with: + name: dist + path: ./dist/** diff --git a/.github/workflows/template_goreleaser-release.yaml b/.github/workflows/template_goreleaser-release.yaml new file mode 100644 index 000000000..141a6f2f7 --- /dev/null +++ b/.github/workflows/template_goreleaser-release.yaml @@ -0,0 +1,65 @@ +name: GoReleaser Release +on: + workflow_call: + secrets: + NUMARY_GITHUB_TOKEN: + required: true + description: GitHub token with access to the repo + SEGMENT_WRITE_KEY_OSS: + required: true + description: Segment write key for the OSS repo + FURY_TOKEN: + required: true + description: Fury token for the OSS repo + +jobs: + goreleaser: + name: GoReleaser Build + strategy: + matrix: + os: [ ubuntu-latest, macos-latest ] + runs-on: ${{ matrix.os }} + env: + DOCKER_CLI_EXPERIMENTAL: "enabled" + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - uses: actions/setup-go@v3 + with: + go-version-file: 'go.mod' + cache: true + - name: fetch numary control + uses: actions/download-artifact@v2 + with: + name: control-dist + path: cmd/control/ + - run: sudo apt install gcc-aarch64-linux-gnu gcc-mingw-w64 -y + if: ${{ matrix.os == 'ubuntu-latest' }} + - name: Run GoReleaser for Linux + if: ${{ matrix.os == 'ubuntu-latest' }} + env: + GITHUB_TOKEN: ${{ secrets.NUMARY_GITHUB_TOKEN }} + FURY_TOKEN: ${{ secrets.FURY_TOKEN }} + SEGMENT_WRITE_KEY: ${{ secrets.SEGMENT_WRITE_KEY_OSS }} + uses: goreleaser/goreleaser-action@v4 + with: + version: latest + args: release --rm-dist + - name: Run GoReleaser for MacOS + if: ${{ matrix.os == 'macos-latest' }} + env: + GITHUB_TOKEN: ${{ secrets.NUMARY_GITHUB_TOKEN }} + FURY_TOKEN: ${{ secrets.FURY_TOKEN }} + SEGMENT_WRITE_KEY: ${{ secrets.SEGMENT_WRITE_KEY_OSS }} + uses: goreleaser/goreleaser-action@v4 + with: + version: latest + args: release -f .goreleaser-darwin.yml --rm-dist + - uses: actions/cache@v2 + with: + path: | + ./dist/*.deb + ./dist/*.rpm + ./dist/*.apk + key: ${{ runner.os }}-go-${{ hashFiles('**/*.go') }}-${{ hashFiles('**/go.sum') }} diff --git a/.github/workflows/template_sdk-generate.yaml b/.github/workflows/template_sdk-generate.yaml new file mode 100644 index 000000000..d38bdcc4d --- /dev/null +++ b/.github/workflows/template_sdk-generate.yaml @@ -0,0 +1,35 @@ +name: SDK Generate +on: + workflow_call: + secrets: + NUMARY_GITHUB_TOKEN: + required: true + description: GitHub token with access to the repo + +jobs: + Sdk: + name: 'Generate SDK' + runs-on: ubuntu-latest + strategy: + matrix: + sdk: [ go, php, python, typescript-node, java ] + steps: + - uses: actions/checkout@v3 + with: + token: ${{ secrets.NUMARY_GITHUB_TOKEN }} + ref: ${{ inputs.VERSION }} + - uses: actions/checkout@v3 + with: + token: ${{ secrets.NUMARY_GITHUB_TOKEN }} + repository: formancehq/numary-sdk-${{ matrix.sdk }} + path: sdks/${{ matrix.sdk }} + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Install Task + uses: arduino/setup-task@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + - name: Launch Generate + run: task sdk:generate VERSION=main -- ${{ matrix.sdk }} diff --git a/.github/workflows/template_sdk-publish.yaml b/.github/workflows/template_sdk-publish.yaml new file mode 100644 index 000000000..e15dff219 --- /dev/null +++ b/.github/workflows/template_sdk-publish.yaml @@ -0,0 +1,57 @@ +name: SDK Publish +on: + workflow_dispatch: + inputs: + VERSION: + type: string + required: true + description: Version of the SDK to publish + workflow_call: + inputs: + VERSION: + type: string + required: true + description: Version of the SDK to publish + secrets: + NUMARY_GITHUB_TOKEN: + required: true + description: GitHub token with access to the repo + +jobs: + Sdk: + name: 'Publish SDK' + runs-on: ubuntu-latest + strategy: + matrix: + sdk: [ go, php, python, typescript-node, java ] + steps: + - uses: actions/checkout@v3 + with: + token: ${{ secrets.NUMARY_GITHUB_TOKEN }} + - uses: actions/checkout@v3 + with: + token: ${{ secrets.NUMARY_GITHUB_TOKEN }} + repository: numary/numary-sdk-${{ matrix.sdk }} + path: ./sdk/sdks/${{ matrix.sdk }} + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Install Task + uses: arduino/setup-task@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + - name: Launch Generate + run: task sdk:generate VERSION=${{ inputs.VERSION }} -- ${{ matrix.sdk }} + - uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: Upgrade Release to ${{ inputs.VERSION }} + create_branch: true + branch: release/${{ inputs.VERSION }} + repository: ./sdk/sdks/${{ matrix.sdk }} + commit_user_name: NumaryBot + commit_user_email: support@numary.com + - run: gh pr create --base main --head release/${{ inputs.VERSION }} --title "Upgrade to ${{ inputs.VERSION }}" --body "Upgrade to ${{ inputs.VERSION }}" + working-directory: ./sdk/sdks/${{ matrix.sdk }} + env: + GITHUB_TOKEN: ${{ secrets.NUMARY_GITHUB_TOKEN }} diff --git a/.goreleaser.yml b/.goreleaser.yml index 07db1ad98..51beb5193 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,4 +1,10 @@ project_name: numary +env: + - GO111MODULE=on + - GOPROXY=https://proxy.golang.org +before: + hooks: + - go mod download builds: - binary: numary @@ -73,7 +79,7 @@ archives: checksum: - name_template: '{{.ProjectName}}_checksums.txt' + name_template: 'checksums.txt' snapshot: name_template: "{{ .Tag }}" @@ -103,9 +109,11 @@ changelog: release: prerelease: auto footer: | + ## Want to try this version ? + [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/numary/ledger/tree/{{ .Tag }}&version={{ .Tag }}) ## What to do next? - - Read the [documentation](https://docs.formance.com/) - - Join our [Slack server](https://formance.com/slack) + - Read the [documentation](https://docs.numary.com/oss/ledger/get-started/installation) + - Join our [Discord server](https://discord.gg/xyHvcbzk4w) nfpms: - id: packages @@ -126,42 +134,3 @@ publishers: - packages dir: "{{ dir .ArtifactPath }}" cmd: curl -F package=@{{ .ArtifactName }} https://{{ .Env.FURY_TOKEN }}@push.fury.io/numary/ - - -dockers: - - image_templates: ["ghcr.io/formancehq/{{ .ProjectName }}:{{ .Version }}-amd64"] - dockerfile: build.Dockerfile - use: buildx - build_flag_templates: - - --platform=linux/amd64 - - --label=org.opencontainers.image.title={{ .ProjectName }} - - --label=org.opencontainers.image.description={{ .ProjectName }} - - --label=org.opencontainers.image.url=https://github.com/formancehq/stack - - --label=org.opencontainers.image.source=https://github.com/formancehq/stack - - --label=org.opencontainers.image.version={{ .Version }} - - --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }} - - --label=org.opencontainers.image.revision={{ .FullCommit }} - - --label=org.opencontainers.image.licenses=MIT - - image_templates: [ "ghcr.io/formancehq/{{ .ProjectName }}:{{ .Version }}-arm64" ] - goarch: arm64 - dockerfile: build.Dockerfile - use: buildx - build_flag_templates: - - --platform=linux/arm64/v8 - - --label=org.opencontainers.image.title={{ .ProjectName }} - - --label=org.opencontainers.image.description={{ .ProjectName }} - - --label=org.opencontainers.image.url=https://github.com/formancehq/stack - - --label=org.opencontainers.image.source=https://github.com/formancehq/stack - - --label=org.opencontainers.image.version={{ .Version }} - - --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }} - - --label=org.opencontainers.image.revision={{ .FullCommit }} - - --label=org.opencontainers.image.licenses=MIT -docker_manifests: - - name_template: ghcr.io/formancehq/{{ .ProjectName }}:{{ .Version }} - image_templates: - - ghcr.io/formancehq/{{ .ProjectName }}:{{ .Version }}-amd64 - - ghcr.io/formancehq/{{ .ProjectName }}:{{ .Version }}-arm64 - - name_template: ghcr.io/formancehq/{{ .ProjectName }}:latest - image_templates: - - ghcr.io/formancehq/{{ .ProjectName }}:{{ .Version }}-amd64 - - ghcr.io/formancehq/{{ .ProjectName }}:{{ .Version }}-arm64 diff --git a/Dockerfile b/Dockerfile index 7894421ff..70d0ee70a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=$BUILDPLATFORM golang:1.19 AS builder +FROM --platform=$BUILDPLATFORM golang:1.18 AS builder RUN apt-get update && \ apt-get install -y gcc-aarch64-linux-gnu gcc-x86-64-linux-gnu && \ ln -s /usr/bin/aarch64-linux-gnu-gcc /usr/bin/arm64-linux-gnu-gcc && \ @@ -9,9 +9,14 @@ ARG TARGETARCH ARG APP_SHA ARG VERSION ARG SEGMENT_WRITE_KEY -WORKDIR /src +WORKDIR /go/src/github.com/numary/ledger +# get deps first so it's cached +COPY go.mod . +COPY go.sum . +RUN --mount=type=cache,id=gomod,target=/go/pkg/mod \ + --mount=type=cache,id=gobuild,target=/root/.cache/go-build \ + go mod download COPY . . -RUN go mod download RUN --mount=type=cache,id=gomod,target=/go/pkg/mod \ --mount=type=cache,id=gobuild,target=/root/.cache/go-build \ CGO_ENABLED=1 GOOS=linux GOARCH=$TARGETARCH \ @@ -24,7 +29,7 @@ RUN --mount=type=cache,id=gomod,target=/go/pkg/mod \ FROM ubuntu:jammy as app RUN apt update && apt install -y ca-certificates wget && rm -rf /var/lib/apt/lists/* -COPY --from=builder /src/numary /usr/local/bin/numary +COPY --from=builder /go/src/github.com/numary/ledger/numary /usr/local/bin/numary EXPOSE 3068 ENTRYPOINT ["numary"] ENV OTEL_SERVICE_NAME ledger diff --git a/build.Dockerfile b/build.Dockerfile deleted file mode 100644 index 4422ddd94..000000000 --- a/build.Dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -FROM ubuntu:jammy -RUN apt update && apt install -y ca-certificates curl && rm -rf /var/lib/apt/lists/* -COPY numary /usr/bin/numary -ENV OTEL_SERVICE_NAME numary -ENTRYPOINT ["/usr/bin/numary"] -CMD ["serve", "start"] From 0faa2e9f77d2a65214e935ed884e16fec88fc57e Mon Sep 17 00:00:00 2001 From: Maxence Maireaux Date: Wed, 19 Apr 2023 16:18:23 +0200 Subject: [PATCH 3/4] ci: Update main.yml --- .github/workflows/main.yml | 73 ++------------------------------------ 1 file changed, 2 insertions(+), 71 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 993c3433d..7573db16c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,45 +13,15 @@ jobs: if: github.event_name == 'pull_request' uses: formancehq/gh-workflows/.github/workflows/pr-style.yml@main - Lint: - uses: formancehq/gh-workflows/.github/workflows/golang-lint.yml@main - Control: name: 'Control' - needs: - - Lint uses: ./.github/workflows/template_build-control.yaml secrets: NUMARY_GITHUB_TOKEN: ${{ secrets.NUMARY_GITHUB_TOKEN }} - Test_postgres: - uses: formancehq/gh-workflows/.github/workflows/golang-test-postgres.yml@main - - Test_sqlite: - uses: formancehq/gh-workflows/.github/workflows/golang-test.yml@main - - Bench: - runs-on: ubuntu-latest - steps: - - name: Install task - uses: arduino/setup-task@v1 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - - uses: actions/checkout@v3 - - uses: actions/setup-go@v3 - with: - go-version-file: 'go.mod' - cache: true - - name: Run ledger package benchmarks - run: task install:perf bench PKG=./pkg/ledger RUN=BenchmarkLedger - GoReleaserBuild: if: github.event_name != 'release' name: 'GoReleaser Build' - needs: - - Control - - Test_sqlite - - Test_postgres uses: ./.github/workflows/template_goreleaser-build.yaml secrets: NUMARY_GITHUB_TOKEN: ${{ secrets.NUMARY_GITHUB_TOKEN }} @@ -60,10 +30,6 @@ jobs: GoReleaserRelease: if: github.event_name == 'release' name: 'GoReleaser Release' - needs: - - Control - - Test_sqlite - - Test_postgres uses: ./.github/workflows/template_goreleaser-release.yaml secrets: NUMARY_GITHUB_TOKEN: ${{ secrets.NUMARY_GITHUB_TOKEN }} @@ -87,12 +53,8 @@ jobs: NUMARY_GITHUB_TOKEN: ${{ secrets.NUMARY_GITHUB_TOKEN }} DockerRelease: - if: github.event_name == 'release' + if: github.event_name == 'rxzelease' uses: ./.github/workflows/template_docker.yaml - needs: - - Control - - Test_sqlite - - Test_postgres with: VERSION: ${{ github.event.release.tag_name }} APP_SHA: ${{ github.sha }} @@ -104,41 +66,10 @@ jobs: DockerBranch: if: github.event_name != 'release' uses: ./.github/workflows/template_docker.yaml - needs: - - Control - - Test_sqlite - - Test_postgres with: VERSION: develop APP_SHA: ${{ github.sha }} RELEASE: ${{ github.event.action }} secrets: NUMARY_GITHUB_TOKEN: ${{ secrets.NUMARY_GITHUB_TOKEN }} - SEGMENT_WRITE_KEY_OSS: ${{ secrets.SEGMENT_WRITE_KEY_OSS }} - -# Check-pkgs: -# if: github.event_name == 'release' -# runs-on: ubuntu-latest -# env: -# DOCKER_CLI_EXPERIMENTAL: "enabled" -# needs: -# - GoReleaserRelease -# strategy: -# matrix: -# format: [ deb, rpm ] -# steps: -# - uses: actions/checkout@v3 -# with: -# fetch-depth: 0 -# - uses: arduino/setup-task@v1 -# with: -# version: 3.x -# repo-token: ${{ secrets.GITHUB_TOKEN }} -# - uses: docker/setup-qemu-action@v1 -# - uses: actions/cache@v2 -# with: -# path: | -# ./dist/*.deb -# ./dist/*.rpm -# key: ${{ runner.os }}-go-${{ hashFiles('**/*.go') }}-${{ hashFiles('**/go.sum') }} -# - run: task goreleaser:test:${{ matrix.format }} + SEGMENT_WRITE_KEY_OSS: ${{ secrets.SEGMENT_WRITE_KEY_OSS }} \ No newline at end of file From 5a3ba95095ce2e30c3bf224d921d4e32633a0b6a Mon Sep 17 00:00:00 2001 From: Maxence Maireaux Date: Wed, 19 Apr 2023 16:27:01 +0200 Subject: [PATCH 4/4] ci: Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7573db16c..551504fb6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -53,7 +53,7 @@ jobs: NUMARY_GITHUB_TOKEN: ${{ secrets.NUMARY_GITHUB_TOKEN }} DockerRelease: - if: github.event_name == 'rxzelease' + if: github.event_name == 'release' uses: ./.github/workflows/template_docker.yaml with: VERSION: ${{ github.event.release.tag_name }}