From 59a3b48ff08dc51a2a3809fadcd26393fba97486 Mon Sep 17 00:00:00 2001 From: Turusov Mihail Date: Thu, 7 Mar 2024 15:49:58 +0200 Subject: [PATCH 01/21] Initial commit --- .../workflows/build-and-deploy-to-qa-s3.yaml | 283 ++++++++++++++++++ 1 file changed, 283 insertions(+) create mode 100644 .github/workflows/build-and-deploy-to-qa-s3.yaml diff --git a/.github/workflows/build-and-deploy-to-qa-s3.yaml b/.github/workflows/build-and-deploy-to-qa-s3.yaml new file mode 100644 index 0000000..de883c0 --- /dev/null +++ b/.github/workflows/build-and-deploy-to-qa-s3.yaml @@ -0,0 +1,283 @@ +--- +name: Build and Deploy to QA + +on: + workflow_call: + inputs: + ecr_region: + type: string + default: "us-east-1" + required: false + ecr_region_eu: + type: string + default: "eu-central-1" + required: false + ecr_repository_name: + type: string + default: ${{ github.event.repository.name }} + required: false + docker_context: + type: string + default: "./" + required: false + docker_file: + type: string + default: "./Dockerfile" + required: false + build_instance_type: + type: string + default: "xlarge" + required: false + sync_policy: + type: string + default: "automated" + required: false + argocd_app_name: + type: string + required: true + argocd_app_fqdn: + type: string + required: true + helm_chart: + type: string + required: true + argocd_project: + type: string + required: true + argocd_server: + type: string + required: true + helm_repos: + type: string + required: true + kubernetes_url: + type: string + required: true + kubernetes_namespace: + type: string + required: true + argocd_additional_options: + type: string + default: "" + required: false + secrets: + argocd_qa_auth_token: + required: true + +concurrency: + group: ${{ github.event.repository.name }}-qa-${{ github.event.pull_request.number }} + cancel-in-progress: true + +jobs: + print-url: + name: Print the url of QA build + runs-on: ["self-hosted", "xsmall", "prod"] + if: github.event.action == 'opened' + timeout-minutes: 1 + steps: + - name: Leave comment with domain name + uses: mshick/add-pr-comment@v2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + message: | + Build will be available here: [https://${{ inputs.argocd_app_fqdn }}](https://${{ inputs.argocd_app_fqdn }}) + + build: + name: Build and upload docker image + runs-on: ["self-hosted", "${{ inputs.build_instance_type }}", "prod"] + if: github.event.action == 'opened' || github.event.action == 'synchronize' || github.event.action == 'reopened' + outputs: + IMAGE_TAG: ${{ steps.github-commit-details.outputs.date }}-${{ steps.github-commit-details.outputs.sha_short }} + steps: + - name: Checkout source code + uses: actions/checkout@v4 + timeout-minutes: 1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + timeout-minutes: 5 + + - name: Get commit details + id: github-commit-details + run: | + echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + echo "date=$(date +'%y.%m.%d%H%M')" >> $GITHUB_OUTPUT + echo "branch=$(echo ${{ github.head_ref }} | sed -e 's/\//_/g' -e 's/-/_/g' -e 's/./\L&/g')" >> $GITHUB_OUTPUT + echo "contributor=$(git log -1 --pretty=format:'%an' | tr -d '\n')" >> $GITHUB_OUTPUT + timeout-minutes: 1 + + - name: Login to Amazon US ECR + id: login-ecr + env: + AWS_REGION: ${{ inputs.ecr_region }} + timeout-minutes: 1 + uses: aws-actions/amazon-ecr-login@v2 + + - name: Login to Amazon EU ECR + id: login-ecr-eu + env: + AWS_REGION: ${{ inputs.ecr_region_eu }} + timeout-minutes: 1 + uses: aws-actions/amazon-ecr-login@v2 + + - name: Build, tag and push image + uses: docker/build-push-action@v5 + timeout-minutes: 30 + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY_NAME: ${{ inputs.ecr_repository_name }} + IMAGE_TAG: ${{ steps.github-commit-details.outputs.date }}-${{ steps.github-commit-details.outputs.sha_short }} + DOCKER_BUILDKIT: 1 + BUILDKIT_PROGRESS: plain + with: + context: ${{ inputs.docker_context }} + file: ${{ inputs.docker_file }} + push: true + build-args: | + BUILD_NUMBER=${{ env.IMAGE_TAG }} + tags: | + ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY_NAME }}:${{ env.IMAGE_TAG }} + labels: | + app.version=${{ env.IMAGE_TAG }} + description=Restream ${{ env.ECR_REPOSITORY_NAME }} service + git.branch=${{ steps.github-commit-details.outputs.branch }} + git.commit=${{ steps.github-commit-details.outputs.sha_short }} + git.contributor=${{ steps.github-commit-details.outputs.contributor }} + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Tag latest for master branch + uses: docker/build-push-action@v5 + if: github.ref == 'refs/heads/master' + timeout-minutes: 30 + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY_NAME: ${{ inputs.ecr_repository_name }} + IMAGE_TAG: ${{ steps.github-commit-details.outputs.date }}-${{ steps.github-commit-details.outputs.sha_short }} + DOCKER_BUILDKIT: 1 + BUILDKIT_PROGRESS: plain + with: + context: ${{ inputs.docker_context }} + file: ${{ inputs.docker_file }} + push: true + build-args: | + BUILD_NUMBER=${{ env.IMAGE_TAG }} + tags: | + ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY_NAME }}:latest + labels: | + app.version=${{ env.IMAGE_TAG }} + description=Restream ${{ env.ECR_REPOSITORY_NAME }} service + git.branch=${{ steps.github-commit-details.outputs.branch }} + git.commit=${{ steps.github-commit-details.outputs.sha_short }} + git.contributor=${{ steps.github-commit-details.outputs.contributor }} + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Build, tag and push image in EU + uses: docker/build-push-action@v5 + timeout-minutes: 30 + continue-on-error: true + env: + ECR_REGISTRY: ${{ steps.login-ecr-eu.outputs.registry }} + ECR_REPOSITORY_NAME: ${{ inputs.ecr_repository_name }} + IMAGE_TAG: ${{ steps.github-commit-details.outputs.date }}-${{ steps.github-commit-details.outputs.sha_short }} + DOCKER_BUILDKIT: 1 + BUILDKIT_PROGRESS: plain + with: + context: ${{ inputs.docker_context }} + file: ${{ inputs.docker_file }} + push: true + build-args: | + BUILD_NUMBER=${{ env.IMAGE_TAG }} + tags: | + ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY_NAME }}:${{ env.IMAGE_TAG }} + labels: | + app.version=${{ env.IMAGE_TAG }} + description=Restream ${{ env.ECR_REPOSITORY_NAME }} service + git.branch=${{ steps.github-commit-details.outputs.branch }} + git.commit=${{ steps.github-commit-details.outputs.sha_short }} + git.contributor=${{ steps.github-commit-details.outputs.contributor }} + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Tag latest for master branch in EU + uses: docker/build-push-action@v5 + if: github.ref == 'refs/heads/master' + timeout-minutes: 30 + continue-on-error: true + env: + ECR_REGISTRY: ${{ steps.login-ecr-eu.outputs.registry }} + ECR_REPOSITORY_NAME: ${{ inputs.ecr_repository_name }} + IMAGE_TAG: ${{ steps.github-commit-details.outputs.date }}-${{ steps.github-commit-details.outputs.sha_short }} + DOCKER_BUILDKIT: 1 + BUILDKIT_PROGRESS: plain + with: + context: ${{ inputs.docker_context }} + file: ${{ inputs.docker_file }} + push: true + build-args: | + BUILD_NUMBER=${{ env.IMAGE_TAG }} + tags: | + ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY_NAME }}:latest + labels: | + app.version=${{ env.IMAGE_TAG }} + description=Restream ${{ env.ECR_REPOSITORY_NAME }} service + git.branch=${{ steps.github-commit-details.outputs.branch }} + git.commit=${{ steps.github-commit-details.outputs.sha_short }} + git.contributor=${{ steps.github-commit-details.outputs.contributor }} + cache-from: type=gha + cache-to: type=gha,mode=max + + argocd-create: + name: Update application in ArgoCD + needs: + - build + runs-on: ["self-hosted", "xsmall", "prod"] + steps: + - name: Update application in argocd + id: argocd-update + if: github.event.action != 'closed' + continue-on-error: true + timeout-minutes: 1 + env: + IMAGE_TAG: ${{ needs.build.outputs.IMAGE_TAG }} + run: > + argocd app set ${{ inputs.argocd_app_name }} --server ${{ inputs.argocd_server }} + --project ${{ inputs.argocd_project }} --auth-token ${{ secrets.argocd_qa_auth_token }} + --helm-set-string image.tag=${{ env.IMAGE_TAG }} --grpc-web + + - name: Create application in argocd + id: argocd-create + if: steps.argocd-update.outcome == 'failure' + timeout-minutes: 1 + env: + IMAGE_TAG: ${{ needs.build.outputs.IMAGE_TAG }} + run: > + argocd app create ${{ inputs.argocd_app_name }} --server ${{ inputs.argocd_server }} + --repo https://github.com/${{ inputs.helm_repos }} --path ${{ inputs.helm_chart }} + --dest-server ${{ inputs.kubernetes_url }} --sync-policy ${{ inputs.sync_policy }} + --project ${{ inputs.argocd_project }} --dest-namespace ${{ inputs.kubernetes_namespace }} + --auth-token ${{ secrets.argocd_qa_auth_token }} --helm-set-string image.tag=${{ env.IMAGE_TAG }} + --helm-set ingress.enabled=true --helm-set-string ingress.host=${{ inputs.argocd_app_fqdn }} + --self-heal --auto-prune --grpc-web ${{ inputs.argocd_additional_options }} + + - name: Wait for the application to be ready + id: argocd-wait + if: steps.argocd-create.outcome == 'success' || steps.argocd-update.outcome == 'success' + timeout-minutes: 5 + run: > + argocd app wait ${{ inputs.argocd_app_name }} --server ${{ inputs.argocd_server }} + --auth-token ${{ secrets.argocd_qa_auth_token }} --grpc-web + + argocd-delete: + name: Delete application in ArgoCD + runs-on: ["self-hosted", "xsmall", "prod"] + if: github.event.action == 'closed' + steps: + - name: Delete application in argocd + continue-on-error: true + timeout-minutes: 1 + run: > + argocd app delete ${{ inputs.argocd_app_name }} --server ${{ inputs.argocd_server }} + --auth-token ${{ secrets.argocd_qa_auth_token }} -y --grpc-web From 54d568e81bb39174458b625b4823d004b3ce38a3 Mon Sep 17 00:00:00 2001 From: Turusov Mihail Date: Fri, 15 Mar 2024 14:20:30 +0200 Subject: [PATCH 02/21] chore: switch file/name --- .../workflows/build-and-deploy-to-qa-s3.yaml | 283 ------------------ .github/workflows/build-and-deploy-to-s3.yaml | 183 +++++++++++ 2 files changed, 183 insertions(+), 283 deletions(-) delete mode 100644 .github/workflows/build-and-deploy-to-qa-s3.yaml create mode 100644 .github/workflows/build-and-deploy-to-s3.yaml diff --git a/.github/workflows/build-and-deploy-to-qa-s3.yaml b/.github/workflows/build-and-deploy-to-qa-s3.yaml deleted file mode 100644 index de883c0..0000000 --- a/.github/workflows/build-and-deploy-to-qa-s3.yaml +++ /dev/null @@ -1,283 +0,0 @@ ---- -name: Build and Deploy to QA - -on: - workflow_call: - inputs: - ecr_region: - type: string - default: "us-east-1" - required: false - ecr_region_eu: - type: string - default: "eu-central-1" - required: false - ecr_repository_name: - type: string - default: ${{ github.event.repository.name }} - required: false - docker_context: - type: string - default: "./" - required: false - docker_file: - type: string - default: "./Dockerfile" - required: false - build_instance_type: - type: string - default: "xlarge" - required: false - sync_policy: - type: string - default: "automated" - required: false - argocd_app_name: - type: string - required: true - argocd_app_fqdn: - type: string - required: true - helm_chart: - type: string - required: true - argocd_project: - type: string - required: true - argocd_server: - type: string - required: true - helm_repos: - type: string - required: true - kubernetes_url: - type: string - required: true - kubernetes_namespace: - type: string - required: true - argocd_additional_options: - type: string - default: "" - required: false - secrets: - argocd_qa_auth_token: - required: true - -concurrency: - group: ${{ github.event.repository.name }}-qa-${{ github.event.pull_request.number }} - cancel-in-progress: true - -jobs: - print-url: - name: Print the url of QA build - runs-on: ["self-hosted", "xsmall", "prod"] - if: github.event.action == 'opened' - timeout-minutes: 1 - steps: - - name: Leave comment with domain name - uses: mshick/add-pr-comment@v2 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - message: | - Build will be available here: [https://${{ inputs.argocd_app_fqdn }}](https://${{ inputs.argocd_app_fqdn }}) - - build: - name: Build and upload docker image - runs-on: ["self-hosted", "${{ inputs.build_instance_type }}", "prod"] - if: github.event.action == 'opened' || github.event.action == 'synchronize' || github.event.action == 'reopened' - outputs: - IMAGE_TAG: ${{ steps.github-commit-details.outputs.date }}-${{ steps.github-commit-details.outputs.sha_short }} - steps: - - name: Checkout source code - uses: actions/checkout@v4 - timeout-minutes: 1 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - timeout-minutes: 5 - - - name: Get commit details - id: github-commit-details - run: | - echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT - echo "date=$(date +'%y.%m.%d%H%M')" >> $GITHUB_OUTPUT - echo "branch=$(echo ${{ github.head_ref }} | sed -e 's/\//_/g' -e 's/-/_/g' -e 's/./\L&/g')" >> $GITHUB_OUTPUT - echo "contributor=$(git log -1 --pretty=format:'%an' | tr -d '\n')" >> $GITHUB_OUTPUT - timeout-minutes: 1 - - - name: Login to Amazon US ECR - id: login-ecr - env: - AWS_REGION: ${{ inputs.ecr_region }} - timeout-minutes: 1 - uses: aws-actions/amazon-ecr-login@v2 - - - name: Login to Amazon EU ECR - id: login-ecr-eu - env: - AWS_REGION: ${{ inputs.ecr_region_eu }} - timeout-minutes: 1 - uses: aws-actions/amazon-ecr-login@v2 - - - name: Build, tag and push image - uses: docker/build-push-action@v5 - timeout-minutes: 30 - env: - ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} - ECR_REPOSITORY_NAME: ${{ inputs.ecr_repository_name }} - IMAGE_TAG: ${{ steps.github-commit-details.outputs.date }}-${{ steps.github-commit-details.outputs.sha_short }} - DOCKER_BUILDKIT: 1 - BUILDKIT_PROGRESS: plain - with: - context: ${{ inputs.docker_context }} - file: ${{ inputs.docker_file }} - push: true - build-args: | - BUILD_NUMBER=${{ env.IMAGE_TAG }} - tags: | - ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY_NAME }}:${{ env.IMAGE_TAG }} - labels: | - app.version=${{ env.IMAGE_TAG }} - description=Restream ${{ env.ECR_REPOSITORY_NAME }} service - git.branch=${{ steps.github-commit-details.outputs.branch }} - git.commit=${{ steps.github-commit-details.outputs.sha_short }} - git.contributor=${{ steps.github-commit-details.outputs.contributor }} - cache-from: type=gha - cache-to: type=gha,mode=max - - - name: Tag latest for master branch - uses: docker/build-push-action@v5 - if: github.ref == 'refs/heads/master' - timeout-minutes: 30 - env: - ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} - ECR_REPOSITORY_NAME: ${{ inputs.ecr_repository_name }} - IMAGE_TAG: ${{ steps.github-commit-details.outputs.date }}-${{ steps.github-commit-details.outputs.sha_short }} - DOCKER_BUILDKIT: 1 - BUILDKIT_PROGRESS: plain - with: - context: ${{ inputs.docker_context }} - file: ${{ inputs.docker_file }} - push: true - build-args: | - BUILD_NUMBER=${{ env.IMAGE_TAG }} - tags: | - ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY_NAME }}:latest - labels: | - app.version=${{ env.IMAGE_TAG }} - description=Restream ${{ env.ECR_REPOSITORY_NAME }} service - git.branch=${{ steps.github-commit-details.outputs.branch }} - git.commit=${{ steps.github-commit-details.outputs.sha_short }} - git.contributor=${{ steps.github-commit-details.outputs.contributor }} - cache-from: type=gha - cache-to: type=gha,mode=max - - - name: Build, tag and push image in EU - uses: docker/build-push-action@v5 - timeout-minutes: 30 - continue-on-error: true - env: - ECR_REGISTRY: ${{ steps.login-ecr-eu.outputs.registry }} - ECR_REPOSITORY_NAME: ${{ inputs.ecr_repository_name }} - IMAGE_TAG: ${{ steps.github-commit-details.outputs.date }}-${{ steps.github-commit-details.outputs.sha_short }} - DOCKER_BUILDKIT: 1 - BUILDKIT_PROGRESS: plain - with: - context: ${{ inputs.docker_context }} - file: ${{ inputs.docker_file }} - push: true - build-args: | - BUILD_NUMBER=${{ env.IMAGE_TAG }} - tags: | - ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY_NAME }}:${{ env.IMAGE_TAG }} - labels: | - app.version=${{ env.IMAGE_TAG }} - description=Restream ${{ env.ECR_REPOSITORY_NAME }} service - git.branch=${{ steps.github-commit-details.outputs.branch }} - git.commit=${{ steps.github-commit-details.outputs.sha_short }} - git.contributor=${{ steps.github-commit-details.outputs.contributor }} - cache-from: type=gha - cache-to: type=gha,mode=max - - - name: Tag latest for master branch in EU - uses: docker/build-push-action@v5 - if: github.ref == 'refs/heads/master' - timeout-minutes: 30 - continue-on-error: true - env: - ECR_REGISTRY: ${{ steps.login-ecr-eu.outputs.registry }} - ECR_REPOSITORY_NAME: ${{ inputs.ecr_repository_name }} - IMAGE_TAG: ${{ steps.github-commit-details.outputs.date }}-${{ steps.github-commit-details.outputs.sha_short }} - DOCKER_BUILDKIT: 1 - BUILDKIT_PROGRESS: plain - with: - context: ${{ inputs.docker_context }} - file: ${{ inputs.docker_file }} - push: true - build-args: | - BUILD_NUMBER=${{ env.IMAGE_TAG }} - tags: | - ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY_NAME }}:latest - labels: | - app.version=${{ env.IMAGE_TAG }} - description=Restream ${{ env.ECR_REPOSITORY_NAME }} service - git.branch=${{ steps.github-commit-details.outputs.branch }} - git.commit=${{ steps.github-commit-details.outputs.sha_short }} - git.contributor=${{ steps.github-commit-details.outputs.contributor }} - cache-from: type=gha - cache-to: type=gha,mode=max - - argocd-create: - name: Update application in ArgoCD - needs: - - build - runs-on: ["self-hosted", "xsmall", "prod"] - steps: - - name: Update application in argocd - id: argocd-update - if: github.event.action != 'closed' - continue-on-error: true - timeout-minutes: 1 - env: - IMAGE_TAG: ${{ needs.build.outputs.IMAGE_TAG }} - run: > - argocd app set ${{ inputs.argocd_app_name }} --server ${{ inputs.argocd_server }} - --project ${{ inputs.argocd_project }} --auth-token ${{ secrets.argocd_qa_auth_token }} - --helm-set-string image.tag=${{ env.IMAGE_TAG }} --grpc-web - - - name: Create application in argocd - id: argocd-create - if: steps.argocd-update.outcome == 'failure' - timeout-minutes: 1 - env: - IMAGE_TAG: ${{ needs.build.outputs.IMAGE_TAG }} - run: > - argocd app create ${{ inputs.argocd_app_name }} --server ${{ inputs.argocd_server }} - --repo https://github.com/${{ inputs.helm_repos }} --path ${{ inputs.helm_chart }} - --dest-server ${{ inputs.kubernetes_url }} --sync-policy ${{ inputs.sync_policy }} - --project ${{ inputs.argocd_project }} --dest-namespace ${{ inputs.kubernetes_namespace }} - --auth-token ${{ secrets.argocd_qa_auth_token }} --helm-set-string image.tag=${{ env.IMAGE_TAG }} - --helm-set ingress.enabled=true --helm-set-string ingress.host=${{ inputs.argocd_app_fqdn }} - --self-heal --auto-prune --grpc-web ${{ inputs.argocd_additional_options }} - - - name: Wait for the application to be ready - id: argocd-wait - if: steps.argocd-create.outcome == 'success' || steps.argocd-update.outcome == 'success' - timeout-minutes: 5 - run: > - argocd app wait ${{ inputs.argocd_app_name }} --server ${{ inputs.argocd_server }} - --auth-token ${{ secrets.argocd_qa_auth_token }} --grpc-web - - argocd-delete: - name: Delete application in ArgoCD - runs-on: ["self-hosted", "xsmall", "prod"] - if: github.event.action == 'closed' - steps: - - name: Delete application in argocd - continue-on-error: true - timeout-minutes: 1 - run: > - argocd app delete ${{ inputs.argocd_app_name }} --server ${{ inputs.argocd_server }} - --auth-token ${{ secrets.argocd_qa_auth_token }} -y --grpc-web diff --git a/.github/workflows/build-and-deploy-to-s3.yaml b/.github/workflows/build-and-deploy-to-s3.yaml new file mode 100644 index 0000000..a8e03c9 --- /dev/null +++ b/.github/workflows/build-and-deploy-to-s3.yaml @@ -0,0 +1,183 @@ +--- +name: Build and deploy to CloudFront + +concurrency: + group: ${{ github.event.repository.name }}-build-n-deploy-${{ github.event.pull_request.number }} + cancel-in-progress: true + +on: + workflow_call: + inputs: + # ===== + # Setup + # ===== + instance_type: + type: string + default: xlarge + required: false + node_version: + type: string + # If set to '' version will be extracted from .nvmrc file + default: "16" + required: false + node_options: + type: string + required: false + package_manager: + type: string + default: yarn + required: false + # ===== + # Build + # ===== + build_command: + type: string + default: yarn build + required: false + build_cache_path: + type: string + required: false + build_path: + type: string + default: ./dist + required: false + # =========== + # Source maps + # =========== + upload_source_maps: + type: boolean + default: false + required: false + # If not specified, will use package.json version + sentry_release_version: + type: string + required: false + sentry_org: + type: string + default: restream-io + required: false + # If not specified, Sentry step won't run + sentry_project: + type: string + required: false + datadog_release_version: + type: string + required: false + # ====== + # Deploy + # ====== + s3_bucket_name: + type: string + required: true + invalidate_cloudfront_cache: + type: boolean + default: true + required: false + secrets: + sentry_auth_token: + required: false + datadog_api_key: + required: false + +jobs: + build: + name: Build and deploy to CloudFront + runs-on: ["self-hosted", "${{ inputs.instance_type }}", "prod"] + steps: + - name: Show context + env: + # To make debugging easier in case of issues + GITHUB_CONTEXT_JSON: ${{ toJson(github) }} + INPUTS_JSON: ${{ toJson(inputs) }} + run: | + echo Github context: "$GITHUB_CONTEXT_JSON" + echo Inputs: "$INPUTS_JSON" + + - name: Checkout source code + uses: actions/checkout@v4 + timeout-minutes: 1 + + - name: Setup Node + uses: actions/setup-node@v4 + timeout-minutes: 5 + with: + node-version: ${{ inputs.node_version }} + node-version-file: .nvmrc + cache: ${{ inputs.package_manager }} + + - name: Get package version + # Version needed only for source maps, so disable it if project doesn't post them to Sentry or DataDog + if: inputs.upload_source_maps + id: 'get_package_version' + run: | + echo Package version: "$(npm pkg get version --workspaces=false | sed 's/"//g')" + echo "package_version=$(npm pkg get version --workspaces=false | sed 's/"//g')" >> $GITHUB_OUTPUT + + - name: Install dependencies + run: ${{ (inputs.package_manager == 'yarn') && 'npm install -g yarn && yarn install --frozen-lockfile' || 'npm ci' }} + timeout-minutes: 10 + + - name: Cache build + if: inputs.build_cache_path + timeout-minutes: 5 + uses: actions/cache@v4 + with: + path: ${{ inputs.build_cache_path }} + key: build-cache-${{ (inputs.package_manager == 'yarn') && hashFiles('yarn.lock') || hashFiles('package-lock.json') }}-${{ github.ref }} + restore-keys: | + build-cache-${{ (inputs.package_manager == 'yarn') && hashFiles('yarn.lock') || hashFiles('package-lock.json') }} + build-cache- + + - name: Build + run: ${{ inputs.build_command }} + timeout-minutes: 15 + env: + COMMIT_HASH: ${{ github.sha }} + NODE_OPTIONS: ${{ inputs.node_options }} + + - name: Upload source maps to Sentry + if: inputs.upload_source_maps && inputs.sentry_project + uses: getsentry/action-release@v1.7.0 + env: + SENTRY_AUTH_TOKEN: ${{ secrets.sentry_auth_token }} + SENTRY_ORG: ${{ inputs.sentry_org }} + SENTRY_PROJECT: ${{ inputs.sentry_project }} + timeout-minutes: 5 + with: + environment: ${{ (github.ref == 'refs/heads/master') && 'production' || 'staging' }} + # We do not use Github integration, hence it will always fail + set_commits: skip + version: ${{ inputs.sentry_release_version && inputs.sentry_release_version || steps.get_package_version.outputs.package_version }} + + - name: Upload source maps to DataDog + if: inputs.upload_source_maps + run: | + npx @datadog/datadog-ci sourcemaps upload ${{ inputs.build_path }} \ + --service=${{ github.event.repository.name }} \ + --release-version=${{ inputs.datadog_release_version && inputs.datadog_release_version || steps.get_package_version.outputs.package_version }} \ + --minified-path-prefix=/ + timeout-minutes: 5 + env: + DATADOG_API_KEY: ${{ secrets.datadog_api_key }} + + - name: Deploy to CloudFront + if: github.ref == 'refs/heads/master' + timeout-minutes: 15 + run: | + cd ${{ inputs.build_path }} + aws s3 cp . "s3://${{ inputs.s3_bucket_name }}" --recursive --no-progress --exclude "*.js.map" + + - name: Invalidate CloudFront cache + if: ${{ (inputs.invalidate_cloudfront_cache) && (github.ref == 'refs/heads/master') }} + timeout-minutes: 5 + env: + ORIGIN: ${{ inputs.s3_bucket_name }}.s3.amazonaws.com + run: | + echo "DISTRIBUTIONS=$(aws cloudfront list-distributions \ + --query "DistributionList.Items[*].{id:Id,origin:Origins.Items[0].Id}[?origin=='${{ env.ORIGIN }}'].id" \ + --output text \ + )" >> $GITHUB_ENV + + for id in $DISTRIBUTIONS; do + aws cloudfront create-invalidation --distribution-id $id --paths "/*" + done From 8145058fb461a3fad5fc5d44a788e84e0a8eeb3e Mon Sep 17 00:00:00 2001 From: Turusov Mihail Date: Tue, 19 Mar 2024 13:03:06 +0200 Subject: [PATCH 03/21] feat: specify PR number for S3 directory --- .github/workflows/build-and-deploy-to-s3.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-and-deploy-to-s3.yaml b/.github/workflows/build-and-deploy-to-s3.yaml index a8e03c9..90069e4 100644 --- a/.github/workflows/build-and-deploy-to-s3.yaml +++ b/.github/workflows/build-and-deploy-to-s3.yaml @@ -165,7 +165,7 @@ jobs: timeout-minutes: 15 run: | cd ${{ inputs.build_path }} - aws s3 cp . "s3://${{ inputs.s3_bucket_name }}" --recursive --no-progress --exclude "*.js.map" + aws s3 cp . "s3://${{ inputs.s3_bucket_name }}/${{ github.event.pull_request.number }}" --recursive --no-progress --exclude "*.js.map" - name: Invalidate CloudFront cache if: ${{ (inputs.invalidate_cloudfront_cache) && (github.ref == 'refs/heads/master') }} @@ -181,3 +181,8 @@ jobs: for id in $DISTRIBUTIONS; do aws cloudfront create-invalidation --distribution-id $id --paths "/*" done + + - name: Delete cloudfront directory on PR close + if: (github.event_name == 'pull_request' && github.event.action == 'closed') || (github.event_name == 'pull_request' && github.event.pull_request.merged == true) + run: | + aws s3 rm s3://${{ inputs.s3_bucket_name }}/${{ github.event.pull_request.number }} --recursive From 53d1fc587d1f91bdb1078a0db61aeef743456d03 Mon Sep 17 00:00:00 2001 From: Turusov Mihail Date: Wed, 20 Mar 2024 15:26:15 +0200 Subject: [PATCH 04/21] chore: cleanup --- .github/workflows/build-and-deploy-to-s3.yaml | 82 ++++--------------- 1 file changed, 14 insertions(+), 68 deletions(-) diff --git a/.github/workflows/build-and-deploy-to-s3.yaml b/.github/workflows/build-and-deploy-to-s3.yaml index 90069e4..d2a31c8 100644 --- a/.github/workflows/build-and-deploy-to-s3.yaml +++ b/.github/workflows/build-and-deploy-to-s3.yaml @@ -1,8 +1,8 @@ --- -name: Build and deploy to CloudFront +name: Build and deploy to S3 concurrency: - group: ${{ github.event.repository.name }}-build-n-deploy-${{ github.event.pull_request.number }} + group: ${{ github.event.repository.name }}-build-n-deploy-s3-${{ github.event.pull_request.number }} cancel-in-progress: true on: @@ -56,33 +56,18 @@ on: type: string default: restream-io required: false - # If not specified, Sentry step won't run - sentry_project: - type: string - required: false - datadog_release_version: - type: string - required: false # ====== # Deploy # ====== s3_bucket_name: type: string required: true - invalidate_cloudfront_cache: - type: boolean - default: true - required: false - secrets: - sentry_auth_token: - required: false - datadog_api_key: - required: false jobs: build: - name: Build and deploy to CloudFront + name: Build and deploy to S3 runs-on: ["self-hosted", "${{ inputs.instance_type }}", "prod"] + if: (github.event_name == 'pull_request' && github.event.action == 'push') steps: - name: Show context env: @@ -105,14 +90,6 @@ jobs: node-version-file: .nvmrc cache: ${{ inputs.package_manager }} - - name: Get package version - # Version needed only for source maps, so disable it if project doesn't post them to Sentry or DataDog - if: inputs.upload_source_maps - id: 'get_package_version' - run: | - echo Package version: "$(npm pkg get version --workspaces=false | sed 's/"//g')" - echo "package_version=$(npm pkg get version --workspaces=false | sed 's/"//g')" >> $GITHUB_OUTPUT - - name: Install dependencies run: ${{ (inputs.package_manager == 'yarn') && 'npm install -g yarn && yarn install --frozen-lockfile' || 'npm ci' }} timeout-minutes: 10 @@ -135,54 +112,23 @@ jobs: COMMIT_HASH: ${{ github.sha }} NODE_OPTIONS: ${{ inputs.node_options }} - - name: Upload source maps to Sentry - if: inputs.upload_source_maps && inputs.sentry_project - uses: getsentry/action-release@v1.7.0 - env: - SENTRY_AUTH_TOKEN: ${{ secrets.sentry_auth_token }} - SENTRY_ORG: ${{ inputs.sentry_org }} - SENTRY_PROJECT: ${{ inputs.sentry_project }} - timeout-minutes: 5 - with: - environment: ${{ (github.ref == 'refs/heads/master') && 'production' || 'staging' }} - # We do not use Github integration, hence it will always fail - set_commits: skip - version: ${{ inputs.sentry_release_version && inputs.sentry_release_version || steps.get_package_version.outputs.package_version }} - - - name: Upload source maps to DataDog - if: inputs.upload_source_maps - run: | - npx @datadog/datadog-ci sourcemaps upload ${{ inputs.build_path }} \ - --service=${{ github.event.repository.name }} \ - --release-version=${{ inputs.datadog_release_version && inputs.datadog_release_version || steps.get_package_version.outputs.package_version }} \ - --minified-path-prefix=/ - timeout-minutes: 5 - env: - DATADOG_API_KEY: ${{ secrets.datadog_api_key }} - - - name: Deploy to CloudFront + - name: Deploy to S3 if: github.ref == 'refs/heads/master' timeout-minutes: 15 run: | cd ${{ inputs.build_path }} aws s3 cp . "s3://${{ inputs.s3_bucket_name }}/${{ github.event.pull_request.number }}" --recursive --no-progress --exclude "*.js.map" + cd ../src/public + aws s3 cp . "s3://${{ inputs.s3_bucket_name }}/${{ github.event.pull_request.number }}" --recursive --no-progress --exclude "*.js.map" - - name: Invalidate CloudFront cache - if: ${{ (inputs.invalidate_cloudfront_cache) && (github.ref == 'refs/heads/master') }} - timeout-minutes: 5 - env: - ORIGIN: ${{ inputs.s3_bucket_name }}.s3.amazonaws.com - run: | - echo "DISTRIBUTIONS=$(aws cloudfront list-distributions \ - --query "DistributionList.Items[*].{id:Id,origin:Origins.Items[0].Id}[?origin=='${{ env.ORIGIN }}'].id" \ - --output text \ - )" >> $GITHUB_ENV - for id in $DISTRIBUTIONS; do - aws cloudfront create-invalidation --distribution-id $id --paths "/*" - done - - name: Delete cloudfront directory on PR close - if: (github.event_name == 'pull_request' && github.event.action == 'closed') || (github.event_name == 'pull_request' && github.event.pull_request.merged == true) + + cleanup: + name: Cleanup + runs-on: ["self-hosted", "${{ inputs.instance_type }}", "prod"] + if: (github.event_name == 'pull_request' && github.event.action == 'closed') || (github.event_name == 'pull_request' && github.event.pull_request.merged == true) + steps: + - name: Delete S3 directory on PR close run: | aws s3 rm s3://${{ inputs.s3_bucket_name }}/${{ github.event.pull_request.number }} --recursive From 1d83c022632e67d802cb561483981bf0a02204ef Mon Sep 17 00:00:00 2001 From: Turusov Mihail Date: Wed, 20 Mar 2024 15:26:47 +0200 Subject: [PATCH 05/21] chore: rename --- ...ild-and-deploy-to-s3.yaml => build-and-deploy-to-s3-qa.yaml} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{build-and-deploy-to-s3.yaml => build-and-deploy-to-s3-qa.yaml} (99%) diff --git a/.github/workflows/build-and-deploy-to-s3.yaml b/.github/workflows/build-and-deploy-to-s3-qa.yaml similarity index 99% rename from .github/workflows/build-and-deploy-to-s3.yaml rename to .github/workflows/build-and-deploy-to-s3-qa.yaml index d2a31c8..4edef49 100644 --- a/.github/workflows/build-and-deploy-to-s3.yaml +++ b/.github/workflows/build-and-deploy-to-s3-qa.yaml @@ -1,5 +1,5 @@ --- -name: Build and deploy to S3 +name: Build and deploy to S3 QA concurrency: group: ${{ github.event.repository.name }}-build-n-deploy-s3-${{ github.event.pull_request.number }} From d9c7d35e4fab2e50f4446a44812b4f10b6dae55d Mon Sep 17 00:00:00 2001 From: Turusov Mihail Date: Wed, 20 Mar 2024 15:38:52 +0200 Subject: [PATCH 06/21] formatting --- .github/workflows/build-and-deploy-to-s3-qa.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/build-and-deploy-to-s3-qa.yaml b/.github/workflows/build-and-deploy-to-s3-qa.yaml index 4edef49..6ce163c 100644 --- a/.github/workflows/build-and-deploy-to-s3-qa.yaml +++ b/.github/workflows/build-and-deploy-to-s3-qa.yaml @@ -121,9 +121,6 @@ jobs: cd ../src/public aws s3 cp . "s3://${{ inputs.s3_bucket_name }}/${{ github.event.pull_request.number }}" --recursive --no-progress --exclude "*.js.map" - - - cleanup: name: Cleanup runs-on: ["self-hosted", "${{ inputs.instance_type }}", "prod"] From bf3f693ee08f0a90a31b4c5f5dc88a548babe27a Mon Sep 17 00:00:00 2001 From: Turusov Mihail Date: Wed, 20 Mar 2024 17:16:59 +0200 Subject: [PATCH 07/21] chore: source maps delete --- .github/workflows/build-and-deploy-to-s3-qa.yaml | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/.github/workflows/build-and-deploy-to-s3-qa.yaml b/.github/workflows/build-and-deploy-to-s3-qa.yaml index 6ce163c..5789b67 100644 --- a/.github/workflows/build-and-deploy-to-s3-qa.yaml +++ b/.github/workflows/build-and-deploy-to-s3-qa.yaml @@ -41,21 +41,6 @@ on: type: string default: ./dist required: false - # =========== - # Source maps - # =========== - upload_source_maps: - type: boolean - default: false - required: false - # If not specified, will use package.json version - sentry_release_version: - type: string - required: false - sentry_org: - type: string - default: restream-io - required: false # ====== # Deploy # ====== From ef1bb14891c52a9f290c34aa3f683438db2bce0a Mon Sep 17 00:00:00 2001 From: Turusov Mihail Date: Thu, 25 Apr 2024 13:37:38 +0300 Subject: [PATCH 08/21] test: delete push requirement --- .github/workflows/build-and-deploy-to-s3-qa.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-deploy-to-s3-qa.yaml b/.github/workflows/build-and-deploy-to-s3-qa.yaml index 5789b67..476658e 100644 --- a/.github/workflows/build-and-deploy-to-s3-qa.yaml +++ b/.github/workflows/build-and-deploy-to-s3-qa.yaml @@ -52,7 +52,7 @@ jobs: build: name: Build and deploy to S3 runs-on: ["self-hosted", "${{ inputs.instance_type }}", "prod"] - if: (github.event_name == 'pull_request' && github.event.action == 'push') + if: (github.event_name == 'pull_request') steps: - name: Show context env: From 4e0552da30414c5d844c5867534af2eed61de3ad Mon Sep 17 00:00:00 2001 From: Turusov Mihail Date: Thu, 25 Apr 2024 14:09:21 +0300 Subject: [PATCH 09/21] test: checkout fetch depth 0 --- .github/workflows/build-and-deploy-to-s3-qa.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build-and-deploy-to-s3-qa.yaml b/.github/workflows/build-and-deploy-to-s3-qa.yaml index 476658e..36effae 100644 --- a/.github/workflows/build-and-deploy-to-s3-qa.yaml +++ b/.github/workflows/build-and-deploy-to-s3-qa.yaml @@ -65,6 +65,8 @@ jobs: - name: Checkout source code uses: actions/checkout@v4 + with: + fetch-depth: 0 timeout-minutes: 1 - name: Setup Node From 8299c2ca2d78411cb96fac7a70fe32c92e950e61 Mon Sep 17 00:00:00 2001 From: Turusov Mihail Date: Thu, 25 Apr 2024 15:12:51 +0300 Subject: [PATCH 10/21] test: deploy all the time --- .github/workflows/build-and-deploy-to-s3-qa.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build-and-deploy-to-s3-qa.yaml b/.github/workflows/build-and-deploy-to-s3-qa.yaml index 36effae..1024fa0 100644 --- a/.github/workflows/build-and-deploy-to-s3-qa.yaml +++ b/.github/workflows/build-and-deploy-to-s3-qa.yaml @@ -100,7 +100,6 @@ jobs: NODE_OPTIONS: ${{ inputs.node_options }} - name: Deploy to S3 - if: github.ref == 'refs/heads/master' timeout-minutes: 15 run: | cd ${{ inputs.build_path }} From d48e17ca58310e06ba00fb950f044b1ec6578b45 Mon Sep 17 00:00:00 2001 From: Anatolii Mandrychenko Date: Thu, 25 Apr 2024 14:50:30 +0100 Subject: [PATCH 11/21] fix: remove upload public folder --- .github/workflows/build-and-deploy-to-s3-qa.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/build-and-deploy-to-s3-qa.yaml b/.github/workflows/build-and-deploy-to-s3-qa.yaml index 1024fa0..3e5e53a 100644 --- a/.github/workflows/build-and-deploy-to-s3-qa.yaml +++ b/.github/workflows/build-and-deploy-to-s3-qa.yaml @@ -104,8 +104,6 @@ jobs: run: | cd ${{ inputs.build_path }} aws s3 cp . "s3://${{ inputs.s3_bucket_name }}/${{ github.event.pull_request.number }}" --recursive --no-progress --exclude "*.js.map" - cd ../src/public - aws s3 cp . "s3://${{ inputs.s3_bucket_name }}/${{ github.event.pull_request.number }}" --recursive --no-progress --exclude "*.js.map" cleanup: name: Cleanup From 1d5c195bc1102fbe73d805cf24b535e07a4307f3 Mon Sep 17 00:00:00 2001 From: Anatolii Mandrychenko Date: Fri, 26 Apr 2024 13:23:42 +0100 Subject: [PATCH 12/21] feat(build-and-deploy-to-s3-qa): add with_nx option --- .github/workflows/build-and-deploy-to-s3-qa.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/build-and-deploy-to-s3-qa.yaml b/.github/workflows/build-and-deploy-to-s3-qa.yaml index 3e5e53a..b6d9f27 100644 --- a/.github/workflows/build-and-deploy-to-s3-qa.yaml +++ b/.github/workflows/build-and-deploy-to-s3-qa.yaml @@ -48,6 +48,11 @@ on: type: string required: true + with_nx: + type: boolean + default: false + required: false + jobs: build: name: Build and deploy to S3 @@ -92,6 +97,12 @@ jobs: build-cache-${{ (inputs.package_manager == 'yarn') && hashFiles('yarn.lock') || hashFiles('package-lock.json') }} build-cache- + - uses: nrwl/nx-set-shas@v3 + if: inputs.with_nx + + - run: git branch --track master origin/master + if: ${{ github.event_name == 'pull_request' && inputs.with_nx }} + - name: Build run: ${{ inputs.build_command }} timeout-minutes: 15 From 078c84c8a92bd1852e6b6d82874e3fc087be7e93 Mon Sep 17 00:00:00 2001 From: Anatolii Mandrychenko Date: Fri, 26 Apr 2024 14:09:03 +0100 Subject: [PATCH 13/21] feat(build-and-deploy-to-cloudfront): add with_nx option --- .../workflows/build-and-deploy-to-cloudfront.yaml | 14 ++++++++++++++ .github/workflows/build-and-deploy-to-s3-qa.yaml | 4 +++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-and-deploy-to-cloudfront.yaml b/.github/workflows/build-and-deploy-to-cloudfront.yaml index a8e03c9..b616434 100644 --- a/.github/workflows/build-and-deploy-to-cloudfront.yaml +++ b/.github/workflows/build-and-deploy-to-cloudfront.yaml @@ -73,6 +73,14 @@ on: type: boolean default: true required: false + # ====== + # NX monorepo tools + # ====== + with_nx: + type: boolean + default: false + required: false + secrets: sentry_auth_token: required: false @@ -128,6 +136,12 @@ jobs: build-cache-${{ (inputs.package_manager == 'yarn') && hashFiles('yarn.lock') || hashFiles('package-lock.json') }} build-cache- + - uses: nrwl/nx-set-shas@v3 + if: inputs.with_nx + + - run: git branch --track master origin/master + if: ${{ github.event_name == 'pull_request' && inputs.with_nx }} + - name: Build run: ${{ inputs.build_command }} timeout-minutes: 15 diff --git a/.github/workflows/build-and-deploy-to-s3-qa.yaml b/.github/workflows/build-and-deploy-to-s3-qa.yaml index b6d9f27..eca4034 100644 --- a/.github/workflows/build-and-deploy-to-s3-qa.yaml +++ b/.github/workflows/build-and-deploy-to-s3-qa.yaml @@ -47,7 +47,9 @@ on: s3_bucket_name: type: string required: true - + # ====== + # NX monorepo tools + # ====== with_nx: type: boolean default: false From 6138a43388b24f7ec63d18d8efafda8868647709 Mon Sep 17 00:00:00 2001 From: Anatolii Mandrychenko Date: Fri, 26 Apr 2024 14:52:44 +0100 Subject: [PATCH 14/21] feat(build-and-deploy-to-cloudfront): add with_nx option --- .github/workflows/build-and-deploy-to-cloudfront.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build-and-deploy-to-cloudfront.yaml b/.github/workflows/build-and-deploy-to-cloudfront.yaml index b616434..a05a3f0 100644 --- a/.github/workflows/build-and-deploy-to-cloudfront.yaml +++ b/.github/workflows/build-and-deploy-to-cloudfront.yaml @@ -104,6 +104,8 @@ jobs: - name: Checkout source code uses: actions/checkout@v4 timeout-minutes: 1 + with: + fetch-depth: 0 - name: Setup Node uses: actions/setup-node@v4 From b4c046acd6909e5e4307ee52fec403501c35dbce Mon Sep 17 00:00:00 2001 From: Anatolii Mandrychenko Date: Fri, 26 Apr 2024 16:34:01 +0100 Subject: [PATCH 15/21] fix: set nx main-branch-name --- .github/workflows/build-and-deploy-to-cloudfront.yaml | 2 ++ .github/workflows/build-and-deploy-to-s3-qa.yaml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.github/workflows/build-and-deploy-to-cloudfront.yaml b/.github/workflows/build-and-deploy-to-cloudfront.yaml index a05a3f0..71c85cb 100644 --- a/.github/workflows/build-and-deploy-to-cloudfront.yaml +++ b/.github/workflows/build-and-deploy-to-cloudfront.yaml @@ -139,6 +139,8 @@ jobs: build-cache- - uses: nrwl/nx-set-shas@v3 + with: + main-branch-name: "master" if: inputs.with_nx - run: git branch --track master origin/master diff --git a/.github/workflows/build-and-deploy-to-s3-qa.yaml b/.github/workflows/build-and-deploy-to-s3-qa.yaml index eca4034..a817ce5 100644 --- a/.github/workflows/build-and-deploy-to-s3-qa.yaml +++ b/.github/workflows/build-and-deploy-to-s3-qa.yaml @@ -100,6 +100,8 @@ jobs: build-cache- - uses: nrwl/nx-set-shas@v3 + with: + main-branch-name: "master" if: inputs.with_nx - run: git branch --track master origin/master From f7c06e15c5b0e42516562a295f23a3e57f04461f Mon Sep 17 00:00:00 2001 From: Anatolii Mandrychenko Date: Tue, 30 Apr 2024 12:08:43 +0100 Subject: [PATCH 16/21] fix(build-and-deploy-to-s3-qa) : do not track master branch on pr close --- .github/workflows/build-and-deploy-to-s3-qa.yaml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-and-deploy-to-s3-qa.yaml b/.github/workflows/build-and-deploy-to-s3-qa.yaml index a817ce5..764ab19 100644 --- a/.github/workflows/build-and-deploy-to-s3-qa.yaml +++ b/.github/workflows/build-and-deploy-to-s3-qa.yaml @@ -56,6 +56,19 @@ on: required: false jobs: + print-url: + name: Print the url of QA build + runs-on: ["self-hosted", "xsmall", "prod"] + if: github.event.action == 'opened' + timeout-minutes: 1 + steps: + - name: Leave comment with domain name + uses: mshick/add-pr-comment@v2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + message: | + QA Build will be available here: [https://${{ github.event.repository.name }}-pr-${{ github.event.pull_request.number }}.qa.restream.io](https://${{ github.event.repository.name }}-pr-${{ github.event.pull_request.number }}.qa.restream.io) build: name: Build and deploy to S3 runs-on: ["self-hosted", "${{ inputs.instance_type }}", "prod"] @@ -105,7 +118,7 @@ jobs: if: inputs.with_nx - run: git branch --track master origin/master - if: ${{ github.event_name == 'pull_request' && inputs.with_nx }} + if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' && github.event.pull_request.merged != true && inputs.with_nx }} - name: Build run: ${{ inputs.build_command }} From aefc1f788eb3b392dc276ab210d26b1657d8b3d5 Mon Sep 17 00:00:00 2001 From: Anatolii Mandrychenko Date: Tue, 30 Apr 2024 14:43:52 +0100 Subject: [PATCH 17/21] fix(build-and-deploy-to-s3-qa) : do not build on close/merge PR --- .github/workflows/build-and-deploy-to-s3-qa.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-deploy-to-s3-qa.yaml b/.github/workflows/build-and-deploy-to-s3-qa.yaml index 764ab19..bce6c4f 100644 --- a/.github/workflows/build-and-deploy-to-s3-qa.yaml +++ b/.github/workflows/build-and-deploy-to-s3-qa.yaml @@ -72,7 +72,7 @@ jobs: build: name: Build and deploy to S3 runs-on: ["self-hosted", "${{ inputs.instance_type }}", "prod"] - if: (github.event_name == 'pull_request') + if: (github.event_name == 'pull_request' && github.event.action != 'closed' && github.event.pull_request.merged != true) steps: - name: Show context env: From 17a363b4c45df0a04a5b094b8635f8015b2ad6d8 Mon Sep 17 00:00:00 2001 From: Turusov Mihail Date: Wed, 10 Jul 2024 18:12:22 +0300 Subject: [PATCH 18/21] fix: directly pass github repo name and pr number --- .github/workflows/build-and-deploy-to-s3-qa.yaml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-and-deploy-to-s3-qa.yaml b/.github/workflows/build-and-deploy-to-s3-qa.yaml index bce6c4f..bc2cff5 100644 --- a/.github/workflows/build-and-deploy-to-s3-qa.yaml +++ b/.github/workflows/build-and-deploy-to-s3-qa.yaml @@ -1,9 +1,6 @@ --- name: Build and deploy to S3 QA -concurrency: - group: ${{ github.event.repository.name }}-build-n-deploy-s3-${{ github.event.pull_request.number }} - cancel-in-progress: true on: workflow_call: @@ -28,6 +25,15 @@ on: default: yarn required: false # ===== + # Github Context variables + # ===== + repo_name: + type: string + required: true + pr_number: + type: string + required: true + # ===== # Build # ===== build_command: @@ -55,6 +61,10 @@ on: default: false required: false +concurrency: + group: ${{ repo_name }}-build-n-deploy-s3-${{ pr_number }} + cancel-in-progress: true + jobs: print-url: name: Print the url of QA build From eda9c1406ae990b00bf1bc296c409c05fe80f5f8 Mon Sep 17 00:00:00 2001 From: Turusov Mihail Date: Wed, 10 Jul 2024 18:34:41 +0300 Subject: [PATCH 19/21] feat: allow runs on master --- .github/workflows/build-and-deploy-to-s3-qa.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-and-deploy-to-s3-qa.yaml b/.github/workflows/build-and-deploy-to-s3-qa.yaml index bc2cff5..dc34bb7 100644 --- a/.github/workflows/build-and-deploy-to-s3-qa.yaml +++ b/.github/workflows/build-and-deploy-to-s3-qa.yaml @@ -29,10 +29,10 @@ on: # ===== repo_name: type: string - required: true + required: false pr_number: type: string - required: true + required: false # ===== # Build # ===== From 39a2aa0bef430a2cd1952fd366f8c9e028c3ae3a Mon Sep 17 00:00:00 2001 From: Turusov Mihail Date: Wed, 10 Jul 2024 19:25:46 +0300 Subject: [PATCH 20/21] feat: set default name for context values --- .github/workflows/build-and-deploy-to-s3-qa.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build-and-deploy-to-s3-qa.yaml b/.github/workflows/build-and-deploy-to-s3-qa.yaml index dc34bb7..8935f93 100644 --- a/.github/workflows/build-and-deploy-to-s3-qa.yaml +++ b/.github/workflows/build-and-deploy-to-s3-qa.yaml @@ -30,9 +30,11 @@ on: repo_name: type: string required: false + default: ${{ github.event.repository.name }} pr_number: type: string required: false + default: ${{ github.event.pull_request.number }} # ===== # Build # ===== From e59bb3bd6344e9ce08cdee6e1c0f533b2a4e024f Mon Sep 17 00:00:00 2001 From: Turusov Mihail Date: Wed, 10 Jul 2024 19:26:35 +0300 Subject: [PATCH 21/21] fix: inputs reference --- .github/workflows/build-and-deploy-to-s3-qa.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-deploy-to-s3-qa.yaml b/.github/workflows/build-and-deploy-to-s3-qa.yaml index 8935f93..167e32d 100644 --- a/.github/workflows/build-and-deploy-to-s3-qa.yaml +++ b/.github/workflows/build-and-deploy-to-s3-qa.yaml @@ -64,7 +64,7 @@ on: required: false concurrency: - group: ${{ repo_name }}-build-n-deploy-s3-${{ pr_number }} + group: ${{ inputs.repo_name }}-build-n-deploy-s3-${{ inputs.pr_number }} cancel-in-progress: true jobs: