From cbd0f1923c9b008b90961e7fec5545fe0fbf9609 Mon Sep 17 00:00:00 2001 From: Hiep Mai Date: Thu, 11 Jul 2024 18:47:32 +0700 Subject: [PATCH] feat: Add reusable workflows --- .github/workflows/build_docker.yml | 73 ------------------------------ .github/workflows/ci.yml | 21 +++++++++ .github/workflows/publish.yml | 23 ++++++++++ .github/workflows/push_docker.yml | 38 ---------------- 4 files changed, 44 insertions(+), 111 deletions(-) delete mode 100644 .github/workflows/build_docker.yml create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/push_docker.yml diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml deleted file mode 100644 index c2534ab..0000000 --- a/.github/workflows/build_docker.yml +++ /dev/null @@ -1,73 +0,0 @@ -name: build_docker - -on: - push: - branches: - - '**' - tags: - - '**' - -jobs: - build_lint_test: - runs-on: ubuntu-22.04 - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: 1.22.3 - - - name: Print Go environment - run: go env - - - name: Cache Go modules - id: go-cache - uses: actions/cache@v4 - with: - path: | - ~/.go/pkg/mod - ~/.cache/go-build - key: go-mod-${{ hashFiles('**/go.sum') }} - restore-keys: | - go-mod- - - - name: Install Dependencies - run: sudo apt-get install libzmq3-dev - - - name: Build staking-indexer - run: make build - - - name: Lint - run: | - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.55.2 - ./bin/golangci-lint run --timeout 5m0s - - - name: Run tests - run: make test - - - name: Run integration tests - run: make test-e2e - - build_docker: - runs-on: ubuntu-22.04 - needs: build_lint_test - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Build Docker image - uses: docker/build-push-action@v6 - with: - tags: staking-indexer:${{ github.sha }} - outputs: type=docker,dest=/tmp/staking-indexer.tar - - - name: Upload Docker image to workspace - uses: actions/upload-artifact@v4 - with: - name: staking-indexer - path: /tmp/staking-indexer.tar \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..9e6d7ae --- /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@hiep/add-reusable-workflows + with: + install-dependencies-command: 'sudo apt-get install libzmq3-dev' + run-unit-tests: true + run-integration-tests: true + + docker_pipeline: + needs: ["lint_test"] + uses: babylonchain/.github/.github/workflows/reusable_docker_pipeline.yml@hiep/add-reusable-workflows + secrets: inherit + with: + publish: false \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..84f99ad --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,23 @@ +name: push_docker + +on: + push: + branches: + - 'hiep/add-github-actions' + tags: + - 'hiep/add-github-actions' + +jobs: + lint_test: + uses: babylonchain/.github/.github/workflows/reusable_go_lint_test.yml@hiep/add-reusable-workflows + with: + install-dependencies-command: 'sudo apt-get install libzmq3-dev' + run-unit-tests: true + run-integration-tests: true + + docker_pipeline: + needs: ["lint_test"] + uses: babylonchain/.github/.github/workflows/reusable_docker_pipeline.yml@hiep/add-reusable-workflows + secrets: inherit + with: + publish: true \ No newline at end of file diff --git a/.github/workflows/push_docker.yml b/.github/workflows/push_docker.yml deleted file mode 100644 index 4455be4..0000000 --- a/.github/workflows/push_docker.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: push_docker - -on: - workflow_run: - workflows: - - "build_docker" - branches: - - main - - dev - types: - - completed - -jobs: - push_docker: - runs-on: ubuntu-22.04 - steps: - - name: Download Docker image from workspace - uses: actions/download-artifact@v4 - with: - name: staking-indexer - path: /tmp/ - run-id: ${{ github.event.workflow_run.id }} - # automatically generated token - github-token: ${{ secrets.GITHUB_TOKEN }} - - - name: Load Docker image - run: docker load -i /tmp/staking-indexer.tar - - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Push Docker image - run: | - docker tag staking-indexer:${{ github.sha }} ${{ secrets.DOCKERHUB_REGISTRY_ID }}/staking-indexer:${{ github.sha }} - docker push ${{ secrets.DOCKERHUB_REGISTRY_ID }}/staking-indexer:${{ github.sha }}