From fcc7a07bf30ef78768b0c7da7a3edc97639ff4b6 Mon Sep 17 00:00:00 2001 From: Maxence Maireaux Date: Mon, 5 Jul 2021 20:37:49 +0200 Subject: [PATCH 1/2] feat(CI): Add GoReleaser --- .github/workflows/release.yml | 37 ++++++++++------------------------- .goreleaser.yml | 23 ++++++++++++++++++++++ 2 files changed, 33 insertions(+), 27 deletions(-) create mode 100644 .goreleaser.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 059635186..261cfcffe 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,52 +1,35 @@ name: release on: release: - types: - - created + types: [created] +permissions: + contents: write jobs: build: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest strategy: matrix: include: - arch: amd64 cc: gcc - env: GOOS: linux GOARCH: ${{ matrix.arch }} - steps: - uses: actions/setup-go@v2 with: go-version: '1.16' - - uses: actions/checkout@v2 - - name: Configure git for private modules env: TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} run: git config --global url."https://altitude:${TOKEN}@github.com".insteadOf "https://github.com" - - name: get deps run: go get - - - id: get-release - uses: bruceadams/get-release@v1.2.2 - env: - GITHUB_TOKEN: ${{ github.token }} - - - name: build - run: | - CGO_ENABLED=1 go build -o numary - tar -czvf numary-${{ steps.get-release.outputs.tag_name }}-${{ env.GOOS }}-${{ env.GOARCH }}.tar.gz numary - - - name: upload release - uses: actions/upload-release-asset@v1.0.2 - env: - GITHUB_TOKEN: ${{ github.token }} + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 with: - upload_url: ${{ steps.get-release.outputs.upload_url }} - asset_path: numary-${{ steps.get-release.outputs.tag_name }}-${{ env.GOOS }}-${{ env.GOARCH }}.tar.gz - asset_name: numary-${{ steps.get-release.outputs.tag_name }}-${{ env.GOOS }}-${{ env.GOARCH }}.tar.gz - asset_content_type: application/gzip \ No newline at end of file + version: latest + args: release --parallelism 2 --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 000000000..ef5b44050 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,23 @@ +before: + hooks: + - go build +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + main: ./main +archives: + - replacements: + linux: Linux + amd64: x86_64 +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ .Tag }}-next" +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' From e216557962c7a0167d86527fd62fa51662be3205 Mon Sep 17 00:00:00 2001 From: Maxence Maireaux Date: Mon, 5 Jul 2021 20:44:46 +0200 Subject: [PATCH 2/2] feat(CI): Improve CI --- .github/workflows/main.yml | 66 ++++++++++++++++++++++++++++++++ .github/workflows/oas-readme.yml | 16 -------- .github/workflows/pr_open.yml | 59 ++++++++++++++++++++++++++++ .github/workflows/release.yml | 8 ++++ .github/workflows/test.yml | 22 ----------- .gitignore | 3 +- .goreleaser.yml | 6 +-- Dockerfile | 4 +- 8 files changed, 140 insertions(+), 44 deletions(-) create mode 100644 .github/workflows/main.yml delete mode 100644 .github/workflows/oas-readme.yml create mode 100644 .github/workflows/pr_open.yml delete mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 000000000..6bb99b32c --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,66 @@ +on: + push: + branches: + - main +name: Main +jobs: + oas: + name: 'OAS Readme' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: readmeio/github-readme-sync@v2 + with: + readme-oas-key: ${{ secrets.README_OAS_KEY }} + oas-file-path: './spec/http.yml' + api-version: 'v1.0.0' + terraform: + name: 'Terraform' + runs-on: ubuntu-latest + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + steps: + - uses: actions/setup-go@v2 + with: + go-version: '1.16' + - uses: actions/checkout@v2 + - name: Configure git for private modules + env: + TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} + run: git config --global url."https://altitude:${TOKEN}@github.com".insteadOf "https://github.com" + - uses: actions/cache@v2 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - name: get deps + run: go get + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + version: latest + args: build --parallelism 4 --rm-dist --skip-validate + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: eu-west-1 + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + - name: Build, tag, and push image to Amazon ECR + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY: numary-preprod-ecr + IMAGE_TAG: ${{ github.sha }} + run: | + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + diff --git a/.github/workflows/oas-readme.yml b/.github/workflows/oas-readme.yml deleted file mode 100644 index eb8b45bbc..000000000 --- a/.github/workflows/oas-readme.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: Sync OAS to ReadMe -on: - push: - branches: - - master - - main -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: readmeio/github-readme-sync@v2 - with: - readme-oas-key: ${{ secrets.README_OAS_KEY }} - oas-file-path: './spec/http.yml' - api-version: 'v1.0.0' \ No newline at end of file diff --git a/.github/workflows/pr_open.yml b/.github/workflows/pr_open.yml new file mode 100644 index 000000000..27bda692f --- /dev/null +++ b/.github/workflows/pr_open.yml @@ -0,0 +1,59 @@ +name: Pull Request - Open +on: + pull_request: + types: [opened, reopened, synchronize] +jobs: + Test: + name: 'Test' + runs-on: ubuntu-latest + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + steps: + - uses: actions/setup-go@v2 + with: + go-version: '1.16' + - uses: actions/checkout@v2 + - name: Configure git for private modules + env: + TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} + run: git config --global url."https://altitude:${TOKEN}@github.com".insteadOf "https://github.com" + - uses: actions/cache@v2 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - name: get deps + run: go get + - name: run tests + run: go test -v -coverpkg=./... -coverprofile=coverage.out ./... + Lint: + name: 'Lint' + runs-on: ubuntu-latest + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + steps: + - uses: actions/setup-go@v2 + with: + go-version: '1.16' + - uses: actions/checkout@v2 + - name: Configure git for private modules + env: + TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} + run: git config --global url."https://altitude:${TOKEN}@github.com".insteadOf "https://github.com" + - uses: actions/cache@v2 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - name: get deps + run: go get + - name: run vet + run: go vet . diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 261cfcffe..02162b23e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -24,6 +24,14 @@ jobs: env: TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} run: git config --global url."https://altitude:${TOKEN}@github.com".insteadOf "https://github.com" + - uses: actions/cache@v2 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- - name: get deps run: go get - name: Run GoReleaser diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index d6e36bdbc..000000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: test -on: push -jobs: - test: - runs-on: ubuntu-20.04 - steps: - - uses: actions/setup-go@v2 - with: - go-version: '1.16' - - - uses: actions/checkout@v2 - - - name: Configure git for private modules - env: - TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} - run: git config --global url."https://altitude:${TOKEN}@github.com".insteadOf "https://github.com" - - - name: get deps - run: go get - - - name: run tests - run: go test -v -coverpkg=./... -coverprofile=coverage.out ./... diff --git a/.gitignore b/.gitignore index abc5033b6..0ecddfab9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ numary -coverage.out \ No newline at end of file +coverage.out +/dist/ diff --git a/.goreleaser.yml b/.goreleaser.yml index ef5b44050..27cf511a2 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,12 +1,12 @@ before: hooks: - - go build + - go build -o numary builds: - env: - - CGO_ENABLED=0 + - CGO_ENABLED=1 goos: - linux - main: ./main + binary: numary archives: - replacements: linux: Linux diff --git a/Dockerfile b/Dockerfile index a79b6acfd..db62fc737 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM alpine:latest -ADD numary /usr/local/bin/numary +ADD dist/ledger_linux_amd64/numary /usr/local/bin/numary EXPOSE 3068 -CMD ["numary", "server", "start"] \ No newline at end of file +CMD ["numary", "server", "start"]