From 04e0ae4cc08eecfb41e62dfd6e5210518eb0cb97 Mon Sep 17 00:00:00 2001 From: dfeldick Date: Fri, 10 May 2024 11:27:08 -0700 Subject: [PATCH] APIGOV-27565 - refactor workflows --- .github/workflows/build-agents.yml | 76 +++++++++++++++ .../build-apigee-discovery-agent-docker.yml | 2 +- .../build-apigee-discovery-agent.yml | 5 +- ...build-apigee-traceability-agent-docker.yml | 2 +- .../build-apigee-traceability-agent.yml | 4 +- .github/workflows/build-docker-images.yml | 94 +++++++++++++++++++ .github/workflows/run-da-tests.yml | 26 +++++ .github/workflows/run-ta-tests.yml | 26 +++++ 8 files changed, 228 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/build-agents.yml create mode 100644 .github/workflows/build-docker-images.yml create mode 100644 .github/workflows/run-da-tests.yml create mode 100644 .github/workflows/run-ta-tests.yml diff --git a/.github/workflows/build-agents.yml b/.github/workflows/build-agents.yml new file mode 100644 index 00000000..ea37d759 --- /dev/null +++ b/.github/workflows/build-agents.yml @@ -0,0 +1,76 @@ +name: Build agents +on: + push: + branches: [main, "*"] + +jobs: + testDiscoveryAgent: + uses: ./.github/workflows/run-da-tests.yml + + testTraceabilityAgent: + uses: ./.github/workflows/run-ta-tests.yml + + buildDiscoveryAgent: + needs: testDiscoveryAgent + env: + GOFLAGS: "-mod=mod" + GOWORK: "off" + defaults: + run: + working-directory: ${{ env.GOPATH }}/discovery + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.21 + + - name: Build discovery agent + working-directory: discovery + run: | + git fetch --all --tags --quiet + git branch --show-current > commit_id + git tag -l --sort='version:refname' | grep -Eo '[0-9]{1,}\.[0-9]{1,}\.[0-9]{1,3}$' | tail -1 > version + make build + + - uses: actions/upload-artifact@v4 + with: + name: apigee_discovery_agent + path: discovery/bin/apigee_discovery_agent + + buildTraceabilityAgent: + needs: testTraceabilityAgent + env: + GOFLAGS: "-mod=mod" + GOWORK: "off" + defaults: + run: + working-directory: ${{ env.GOPATH }}/traceability + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.21 + + - name: Build traceability agent + working-directory: traceability + run: | + git fetch --all --tags --quiet + git branch --show-current > commit_id + git tag -l --sort='version:refname' | grep -Eo '[0-9]{1,}\.[0-9]{1,}\.[0-9]{1,3}$' | tail -1 > version + make build + + - uses: actions/upload-artifact@v4 + with: + name: apigee_traceability_agent + path: traceability/bin/apigee_traceability_agent + + - uses: actions/upload-artifact@v4 + with: + name: apigee_traceability_agent.yml + path: traceability/apigee_traceability_agent.yml diff --git a/.github/workflows/build-apigee-discovery-agent-docker.yml b/.github/workflows/build-apigee-discovery-agent-docker.yml index 1a23b343..f50ad4fc 100644 --- a/.github/workflows/build-apigee-discovery-agent-docker.yml +++ b/.github/workflows/build-apigee-discovery-agent-docker.yml @@ -3,7 +3,7 @@ name: Discovery Agent Docker on: push: tags: - - "*" + - "*xxx" jobs: buildDiscoveryAgentDocker: diff --git a/.github/workflows/build-apigee-discovery-agent.yml b/.github/workflows/build-apigee-discovery-agent.yml index 4c21f140..9f343684 100644 --- a/.github/workflows/build-apigee-discovery-agent.yml +++ b/.github/workflows/build-apigee-discovery-agent.yml @@ -2,9 +2,9 @@ name: Build Apigee Discovery Agent on: push: - branches: [main, "*"] + # branches: [main, "*"] tags: - - "*" + - "*xxx" jobs: testDiscoveryAgent: @@ -56,4 +56,3 @@ jobs: with: name: apigee_discovery_agent path: discovery/bin/apigee_discovery_agent - \ No newline at end of file diff --git a/.github/workflows/build-apigee-traceability-agent-docker.yml b/.github/workflows/build-apigee-traceability-agent-docker.yml index 905230d6..367ac35a 100644 --- a/.github/workflows/build-apigee-traceability-agent-docker.yml +++ b/.github/workflows/build-apigee-traceability-agent-docker.yml @@ -3,7 +3,7 @@ name: Traceability Agent Docker on: push: tags: - - "*" + - "*xxx" jobs: buildtraceabilityAgentDocker: diff --git a/.github/workflows/build-apigee-traceability-agent.yml b/.github/workflows/build-apigee-traceability-agent.yml index 6086bacc..25402948 100644 --- a/.github/workflows/build-apigee-traceability-agent.yml +++ b/.github/workflows/build-apigee-traceability-agent.yml @@ -2,9 +2,9 @@ name: Build Apigee Traceability Agent on: push: - branches: [main, "*"] + # branches: [main, "*"] tags: - - "*" + - "*xxx" jobs: testTraceabilityAgent: diff --git a/.github/workflows/build-docker-images.yml b/.github/workflows/build-docker-images.yml new file mode 100644 index 00000000..5974c2ed --- /dev/null +++ b/.github/workflows/build-docker-images.yml @@ -0,0 +1,94 @@ +name: Discovery Agent Docker + +on: + push: + tags: + - "*" + +jobs: + testDiscoveryAgent: + uses: ./.github/workflows/run-da-tests.yml + + testTraceabilityAgent: + uses: ./.github/workflows/run-ta-tests.yml + + buildDiscoveryAgentDocker: + needs: testDiscoveryAgent + env: + GOFLAGS: "-mod=mod" + GOWORK: "off" + IMAGE_NAME: apigee_discovery_agent + ORG_NAME: Axway + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Create commit_id & version files + working-directory: discovery + run: | + git branch --show-current > commit_id + echo "${{ github.ref_name }}" > version + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + flavor: latest=false + images: ghcr.io/${{ env.ORG_NAME }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: discovery/docker/Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + + buildtraceabilityAgentDocker: + needs: testTraceabilityAgent + env: + GOFLAGS: "-mod=mod" + GOWORK: "off" + IMAGE_NAME: apigee_traceability_agent + ORG_NAME: Axway + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Create commit_id & version files + working-directory: traceability + run: | + git branch --show-current > commit_id + echo "${{ github.ref_name }}" > version + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + flavor: latest=false + images: ghcr.io/${{ env.ORG_NAME }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: traceability/docker/Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/run-da-tests.yml b/.github/workflows/run-da-tests.yml new file mode 100644 index 00000000..145e2105 --- /dev/null +++ b/.github/workflows/run-da-tests.yml @@ -0,0 +1,26 @@ +# This action is shared by workflows that want to run the unit tests +name: Test the agents + +on: + workflow_call + +jobs: + testDiscoveryAgent: + env: + GOFLAGS: "-mod=mod" + GOWORK: "off" + defaults: + run: + working-directory: ${{ env.GOPATH }}/discovery + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.21 + + - name: Test discovery agent + working-directory: discovery + run: make test diff --git a/.github/workflows/run-ta-tests.yml b/.github/workflows/run-ta-tests.yml new file mode 100644 index 00000000..c120cb31 --- /dev/null +++ b/.github/workflows/run-ta-tests.yml @@ -0,0 +1,26 @@ +# This action is shared by workflows that want to run the unit tests +name: Test the agents + +on: + workflow_call + +jobs: + testTraceabilityAgent: + env: + GOFLAGS: "-mod=mod" + GOWORK: "off" + defaults: + run: + working-directory: ${{ env.GOPATH }}/traceability + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.21 + + - name: Test traceability agent + working-directory: traceability + run: make test