From 852c87bae3c2864a660c3f890b7928f9a6990b96 Mon Sep 17 00:00:00 2001 From: Hiep Mai Date: Wed, 24 Jul 2024 17:39:39 +0700 Subject: [PATCH] feat: Add github actions --- .circleci/config.yml | 105 ---------------------------------- .github/workflows/ci.yml | 21 +++++++ .github/workflows/publish.yml | 25 ++++++++ Makefile | 2 +- bin/local-startup.sh | 5 +- 5 files changed, 50 insertions(+), 108 deletions(-) delete mode 100644 .circleci/config.yml create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/publish.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 29f2ff1..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,105 +0,0 @@ -version: 2.1 - -orbs: - aws-ecr: circleci/aws-ecr@8.2.1 - go: circleci/go@1.9.0 - kubernetes: circleci/kubernetes@1.3.1 - helm: circleci/helm@2.0.1 - -jobs: - build_lint_tests: - machine: - image: ubuntu-2204:2024.01.1 - resource_class: large - steps: - - go/install: - version: "1.21.4" - - checkout - - run: - name: Print Go environment - command: "go env" - - restore_cache: # restores saved cache if no changes are detected since last run - keys: - - go-mod-v6-{{ checksum "go.sum" }} - - add_ssh_keys - - run: - name: Build Staking API Service - command: make build - - save_cache: - key: go-mod-v6-{{ checksum "go.sum" }} - paths: - - "/home/circleci/.go_workspace/pkg/mod" - # TODO: https://github.com/babylonchain/staking-api-service/issues/29 - # - run: - # name: Lint - # command: | - # curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.55.2 - # ./bin/golangci-lint run - - run: - name: Run tests - command: | - make tests - - build_docker: - machine: - image: ubuntu-2204:2024.01.1 - resource_class: large - steps: - - checkout - - add_ssh_keys - - aws-ecr/build-image: - push-image: false - dockerfile: Dockerfile - path: ./contrib/images/staking-api-service/ - build-path: ./ - tag: "$CIRCLE_SHA1,$CIRCLE_TAG" - repo: "staking-api-service" - - run: - name: Save Docker image to export it to workspace - command: | - docker save $(docker image ls --format '{{.Repository}}:{{.Tag}}') > /tmp/staking-api-service.tar - - persist_to_workspace: - root: /tmp - paths: - - staking-api-service.tar - - push_docker: - machine: - image: ubuntu-2204:2024.01.1 - resource_class: large - steps: - - add_ssh_keys - - attach_workspace: - at: /tmp - - run: - name: Load Docker image from workspace - command: | - docker load -i /tmp/staking-api-service.tar - - aws-ecr/ecr-login: - aws-access-key-id: AWS_ACCESS_KEY_ID - aws-secret-access-key: AWS_SECRET_ACCESS_KEY - region: "$AWS_REGION" - - aws-ecr/push-image: - registry-id: AWS_ECR_REGISTRY_ID - region: "$AWS_REGION" - repo: "staking-api-service" - tag: "$CIRCLE_SHA1,$CIRCLE_TAG" - -workflows: - CICD: - jobs: - - build_lint_tests - - build_docker: - filters: - tags: - only: /.*/ - - push_docker: - requires: - - build_docker - filters: - tags: - only: /.*/ - branches: - only: - - main - - dev diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..facc47c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,21 @@ +name: ci + +on: + pull_request: + branches: + - '**' + +jobs: + lint_test: + uses: babylonchain/.github/.github/workflows/reusable_go_lint_test.yml@v0.1.0 + with: + run-unit-tests: true + run-integration-tests: false + run-lint: false + + docker_pipeline: + uses: babylonchain/.github/.github/workflows/reusable_docker_pipeline.yml@v0.1.0 + secrets: inherit + with: + publish: false + dockerfile: ./contrib/images/staking-api-service/Dockerfile \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..8c080e2 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,25 @@ +name: docker_publish + +on: + push: + branches: + - 'main' + - 'dev' + tags: + - '*' + +jobs: + lint_test: + uses: babylonchain/.github/.github/workflows/reusable_go_lint_test.yml@v0.1.0 + with: + run-unit-tests: true + run-integration-tests: false + run-lint: false + + docker_pipeline: + needs: ["lint_test"] + uses: babylonchain/.github/.github/workflows/reusable_docker_pipeline.yml@v0.1.0 + secrets: inherit + with: + publish: true + dockerfile: ./contrib/images/staking-api-service/Dockerfile \ No newline at end of file diff --git a/Makefile b/Makefile index 8fd72ee..86b6a0a 100644 --- a/Makefile +++ b/Makefile @@ -61,7 +61,7 @@ generate-mock-interface: cd internal/clients/ordinals && mockery --name=OrdinalsClientInterface --output=../../../tests/mocks --outpkg=mocks --filename=mock_ordinal_client.go cd internal/clients/unisat && mockery --name=UnisatClientInterface --output=../../../tests/mocks --outpkg=mocks --filename=mock_unisat_client.go -tests: +test: ./bin/local-startup.sh; go test -v -cover -p 1 ./... -count=1 diff --git a/bin/local-startup.sh b/bin/local-startup.sh index 5e49df8..6931560 100755 --- a/bin/local-startup.sh +++ b/bin/local-startup.sh @@ -7,7 +7,7 @@ if [ $(docker ps -q -f name=^/${MONGO_CONTAINER_NAME}$) ]; then else echo "Starting MongoDB" # Start MongoDB - docker-compose up mongodb -d + docker-compose up -d mongodb fi # Check if the RabbitMQ container is already running @@ -17,5 +17,6 @@ if [ $(docker ps -q -f name=^/${RABBITMQ_CONTAINER_NAME}$) ]; then else echo "Starting RabbitMQ" # Start RabbitMQ - docker-compose up rabbitmq -d + docker-compose up -d rabbitmq + sleep 10 fi \ No newline at end of file