diff --git a/.github/workflows/env-release-nucleus.yml b/.github/workflows/env-release-nucleus.yml new file mode 100644 index 0000000..2afbea5 --- /dev/null +++ b/.github/workflows/env-release-nucleus.yml @@ -0,0 +1,57 @@ +name: Release to Environment Nucleus +on: + workflow_dispatch: + inputs: + environment: + description: 'Environment to Deploy' + required: true + type: choice + options: + - beta + - prod + version: + description: 'Version to be Published' + required: true + type: string + +jobs: + env-release: + + runs-on: ubuntu-latest + + steps: + + - name: Docker Login + uses: docker/login-action@v1.13.0 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_TOKEN }} + logout: true + + - name: Setup Environment + run: | + echo "BOTNAME=Test-at-Scale Nucleus Promoted: Version ${ENVIRONMENT} to ${VERSION}" >> $GITHUB_ENV + if [ ${ENVIRONMENT} == "prod" ] ; then + echo "IMAGE_TAG=latest-base" >> $GITHUB_ENV + else + echo "IMAGE_TAG=${ENVIRONMENT}-base" >> $GITHUB_ENV + fi + env: + ENVIRONMENT: ${{ github.event.inputs.environment }} + VERSION: ${{ github.event.inputs.version }} + + - name: Promote Docker Image + run: | + docker pull lambdatest/nucleus:${VERSION}-base + docker tag lambdatest/nucleus:${VERSION}-base lambdatest/nucleus:${{ env.IMAGE_TAG }} + docker push lambdatest/nucleus:${{ env.IMAGE_TAG }} + env: + VERSION: ${{ github.event.inputs.version }} + + - if: startsWith(matrix.label, 'release:') + name: Build Cloud Runners + run: | + gh workflow run -R ${{ secrets.WF_REPO }} ${{ secrets.WF_NAME }} -r main -f environment=${ENVIRONMENT} -f version=${{ steps.tag_version.outputs.new_tag }} + env: + GITHUB_TOKEN: ${{secrets.GH_API_TOKEN}} + ENVIRONMENT: ${{ github.event.inputs.environment }} diff --git a/.github/workflows/env-release-synapse.yml b/.github/workflows/env-release-synapse.yml new file mode 100644 index 0000000..11f3aa6 --- /dev/null +++ b/.github/workflows/env-release-synapse.yml @@ -0,0 +1,50 @@ +name: Release to Environment Synapse +on: + workflow_dispatch: + inputs: + environment: + description: 'Environment to Deploy' + required: true + type: choice + options: + - beta + - prod + version: + description: 'Version to be Published' + required: true + type: string + +jobs: + env-release: + + runs-on: ubuntu-latest + + steps: + + - name: Docker Login + uses: docker/login-action@v1.13.0 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_TOKEN }} + logout: true + + - name: Setup Environment + run: | + echo "BOTNAME=Test-at-Scale Synapse Promoted: Version ${ENVIRONMENT} to ${VERSION}" >> $GITHUB_ENV + if [ ${ENVIRONMENT} == "prod" ] ; then + echo "IMAGE_TAG=latest" >> $GITHUB_ENV + else + echo "IMAGE_TAG=${ENVIRONMENT}" >> $GITHUB_ENV + fi + env: + ENVIRONMENT: ${{ github.event.inputs.environment }} + VERSION: ${{ github.event.inputs.version }} + + - name: Promote Docker Image + run: | + docker pull lambdatest/synapse:${VERSION} + docker tag lambdatest/synapse:${VERSION} lambdatest/synapse:${{ env.IMAGE_TAG }} + docker push lambdatest/synapse:${{ env.IMAGE_TAG }} + env: + ENVIRONMENT: ${{ github.event.inputs.environment }} + VERSION: ${{ github.event.inputs.version }} diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml deleted file mode 100644 index 8c02e05..0000000 --- a/.github/workflows/golangci-lint.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: golangci-lint -on: - pull_request: -jobs: - golangci: - name: lint - runs-on: ubuntu-latest - steps: - - name: Install Go - uses: actions/setup-go@v2 - with: - go-version: 1.16 - - name: Checkout code - uses: actions/checkout@v2 - - name: Run golangci-lint - uses: golangci/golangci-lint-action@v2.5.2 - with: - version: latest - # skip cache because of flaky behaviors - skip-build-cache: true - skip-pkg-cache: true - skip-go-installation: true - only-new-issues: true - args: --skip-dirs=pkg/docs --timeout=3m diff --git a/.github/workflows/main.yml b/.github/workflows/premerge.yml similarity index 60% rename from .github/workflows/main.yml rename to .github/workflows/premerge.yml index d1bb940..f2704a8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/premerge.yml @@ -1,63 +1,95 @@ -name: Go report card & Test coverage +name: CI on: - push: - branches: - - main - - beta - - dev - tags: [ 'v*.*.*' ] - pull_request: branches: - main - - beta - - dev - workflow_dispatch: +jobs: -env: - REGISTRY_NAME: lambdatest + Linting: + + name: Golang CI - Linting + runs-on: ubuntu-latest + + steps: + + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.16 + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Run golangci-lint + uses: golangci/golangci-lint-action@v2.5.2 + with: + version: latest + # skip cache because of flaky behaviors + skip-build-cache: true + skip-pkg-cache: true + skip-go-installation: true + only-new-issues: true + args: --skip-dirs=pkg/docs --timeout=3m -jobs: Unit_Test_Cases: + + name: Unit Test Cases runs-on: ubuntu-latest + needs: [ Linting ] + steps: + - name: Install Go uses: actions/setup-go@v2 with: go-version: 1.17 + - name: Checkout code uses: actions/checkout@v2 + - name: Unit Test Cases env: ENV: "dev" run: go test ./... -parallel 4 Performance_Test_Cases: + + name: Performance Test Cases runs-on: ubuntu-latest + needs: [ Linting ] + steps: + - name: Install Go uses: actions/setup-go@v2 with: go-version: 1.17 + - name: Checkout code uses: actions/checkout@v2 + - name: Performance Test Cases env: ENV: "dev" run: go test ./... -parallel 4 -bench=. -benchmem Test_Coverage: + + name: Test Coverage runs-on: ubuntu-latest needs: [ Unit_Test_Cases, Performance_Test_Cases ] + steps: - name: Install Go uses: actions/setup-go@v2 with: go-version: 1.17 + - name: Checkout code uses: actions/checkout@v2 + - name: Test Code Coverage env: ENV: "dev" @@ -66,15 +98,20 @@ jobs: go tool cover -func profile.cov Go_Report_Card: + + name: Go Report Card runs-on: ubuntu-latest needs: [ Unit_Test_Cases, Performance_Test_Cases ] + steps: - name: Install Go uses: actions/setup-go@v2 with: go-version: 1.17 + - name: Checkout code uses: actions/checkout@v2 + - name: Run Go Report Card run: | issues_threshold=13 @@ -119,55 +156,3 @@ jobs: else exit 0 fi - - Build_To_Deploy: - if: ${{ github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/beta' || github.ref == 'refs/heads/main' }} - runs-on: ubuntu-latest - needs: [ Test_Coverage, Go_Report_Card ] - steps: - - name: Inject slug/short variables - uses: rlespinasse/github-slug-action@v3.x - - - name: Checkout - uses: actions/checkout@v2.4.0 - - - name: Build Cloud Runners - if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/beta' || github.ref == 'refs/heads/dev' }} - run: | - curl -X POST "https://api.github.com/repos/LambdaTest/test-at-scale-deployment/actions/workflows/main.yml/dispatches" -H "Authorization:Bearer ${{ secrets.GH_API_TOKEN }}" -d '{"ref":"${{env.GITHUB_REF_SLUG}}"}' - - - name: Setup Docker Image Tags - run: | - if [ ${GITHUB_REF_SLUG} == "main" ] ; then - echo "NUCLEUS_TAGS=${REGISTRY_NAME}/nucleus:base" >> $GITHUB_ENV - echo "SYNAPSE_TAGS=${REGISTRY_NAME}/synapse:latest","${REGISTRY_NAME}/synapse:prod" >> $GITHUB_ENV - else - echo "NUCLEUS_TAGS=${REGISTRY_NAME}/nucleus:base-${GITHUB_REF_SLUG}" >> $GITHUB_ENV - echo "SYNAPSE_TAGS=${REGISTRY_NAME}/synapse:${GITHUB_REF_SLUG}" >> $GITHUB_ENV - fi - - - name: Docker Login - uses: docker/login-action@v1.13.0 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_TOKEN }} - logout: true - - - name: Build and push Nucleus images - if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/beta' || github.ref == 'refs/heads/dev' || startsWith(github.ref, 'refs/tags/v') }} - uses: docker/build-push-action@v2.9.0 - with: - context: . - tags: ${{ env.NUCLEUS_TAGS }} - file: build/nucleus/Dockerfile - push: true - - - name: Build and push Synapse images - if: ${{ github.ref == 'refs/heads/beta' || github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') }} - uses: docker/build-push-action@v2.9.0 - with: - context: . - tags: ${{ env.SYNAPSE_TAGS }} - file: build/synapse/Dockerfile - push: true - diff --git a/.github/workflows/release-patch-wf.yml b/.github/workflows/release-patch-wf.yml new file mode 100644 index 0000000..99508f0 --- /dev/null +++ b/.github/workflows/release-patch-wf.yml @@ -0,0 +1,70 @@ +# This workflow will release a new patch version of nucleus and synapse +name: Release Patch Version + +on: + workflow_dispatch: + +jobs: + + Release: + + runs-on: ubuntu-latest + + steps: + + - name: Retrieving Release Type + run: | + echo "RELEASE_TYPE=patch" >> $GITHUB_ENV + echo "Releasing: ${release_type}" + + - name: Inject slug/short variables + uses: rlespinasse/github-slug-action@v3.x + + - name: Checkout + uses: actions/checkout@v2.4.0 + + - name: Bump version and push tag + id: tag_version + uses: mathieudutour/github-tag-action@v6.0 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + default_bump: ${{ env.RELEASE_TYPE }} + + - if: startsWith(matrix.label, 'release:') + name: Build Cloud Runners + run: | + gh workflow run -R ${{ secrets.WF_REPO }} ${{ secrets.WF_NAME }} -r main -f environment=dev -f version=${{ steps.tag_version.outputs.new_tag }} + env: + GITHUB_TOKEN: ${{secrets.GH_API_TOKEN}} + + - name: Setup Environment + run: | + echo "BOTNAME=Test-at-Scale Deployment Status: Version ${{ steps.tag_version.outputs.new_tag }} to dev" >> $GITHUB_ENV + + - name: Setup Docker Image Tags + run: | + echo "NUCLEUS_TAGS=lambdatest/nucleus:dev-base","lambdatest/nucleus:${{ steps.tag_version.outputs.new_tag }}-base" >> $GITHUB_ENV + echo "SYNAPSE_TAGS=lambdatest/synapse:dev","lambdatest/synapse:${{ steps.tag_version.outputs.new_tag }}" >> $GITHUB_ENV + + - name: Docker Login + uses: docker/login-action@v1.13.0 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_TOKEN }} + logout: true + + - name: Build and push Nucleus images + uses: docker/build-push-action@v2.9.0 + with: + context: . + tags: ${{ env.NUCLEUS_TAGS }} + file: build/nucleus/Dockerfile + push: true + + - name: Build and push Synapse images + uses: docker/build-push-action@v2.9.0 + with: + context: . + tags: ${{ env.SYNAPSE_TAGS }} + file: build/synapse/Dockerfile + push: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..18d21cd --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,100 @@ +name: Release on Dev + +on: + pull_request: + types: + - closed + branches: + - main + +jobs: + + Release: + + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + strategy: + matrix: + label: ${{ github.event.pull_request.labels.*.name }} + + steps: + + - if: startsWith(matrix.label, 'release:') + name: Retrieving Release Type + run: | + release_type=`echo ${{matrix.label}} | awk -F':' '{print $NF}'` + echo "RELEASE_TYPE=${release_type}" >> $GITHUB_ENV + echo "Releasing: ${release_type}" + + - if: startsWith(matrix.label, 'release:') + name: Inject slug/short variables + uses: rlespinasse/github-slug-action@v3.x + + - if: startsWith(matrix.label, 'release:') + name: Checkout + uses: actions/checkout@v2.4.0 + + - if: startsWith(matrix.label, 'release:') + name: Bump version and push tag + id: tag_version + uses: mathieudutour/github-tag-action@v6.0 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + default_bump: ${{ env.RELEASE_TYPE }} + + - if: startsWith(matrix.label, 'release:') + name: Creating Github Release + uses: ncipollo/release-action@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + draft: false + generateReleaseNotes: true + prerelease: false + tag: ${{ steps.tag_version.outputs.new_tag }} + name: Release ${{ steps.tag_version.outputs.new_tag }} + body: ${{ steps.changelog.outputs.changelog }} + + + - if: startsWith(matrix.label, 'release:') + name: Build Cloud Runners + run: | + gh workflow run -R ${{ secrets.WF_REPO }} ${{ secrets.WF_NAME }} -r main -f environment=dev -f version=${{ steps.tag_version.outputs.new_tag }} + env: + GITHUB_TOKEN: ${{secrets.GH_API_TOKEN}} + + - if: startsWith(matrix.label, 'release:') + name: Setup Environment + run: | + echo "BOTNAME=Test-at-Scale Deployment Status: Version ${{ steps.tag_version.outputs.new_tag }} to dev" >> $GITHUB_ENV + + - if: startsWith(matrix.label, 'release:') + name: Setup Docker Image Tags + run: | + echo "NUCLEUS_TAGS=lambdatest/nucleus:dev-base","lambdatest/nucleus:${{ steps.tag_version.outputs.new_tag }}-base" >> $GITHUB_ENV + echo "SYNAPSE_TAGS=lambdatest/synapse:dev","lambdatest/synapse:${{ steps.tag_version.outputs.new_tag }}" >> $GITHUB_ENV + + - if: startsWith(matrix.label, 'release:') + name: Docker Login + uses: docker/login-action@v1.13.0 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_TOKEN }} + logout: true + + - if: startsWith(matrix.label, 'release:') + name: Build and push Nucleus images + uses: docker/build-push-action@v2.9.0 + with: + context: . + tags: ${{ env.NUCLEUS_TAGS }} + file: build/nucleus/Dockerfile + push: true + + - if: startsWith(matrix.label, 'release:') + name: Build and push Synapse images + uses: docker/build-push-action@v2.9.0 + with: + context: . + tags: ${{ env.SYNAPSE_TAGS }} + file: build/synapse/Dockerfile + push: true