diff --git a/.github/workflows/ci-standard-checks.yml b/.github/workflows/ci-standard-checks.yml index 7bbf256..0315c9c 100644 --- a/.github/workflows/ci-standard-checks.yml +++ b/.github/workflows/ci-standard-checks.yml @@ -12,6 +12,8 @@ on: - ready_for_review branches: - main + merge_group: + types: [ checks_requested ] jobs: ci-standard-checks: uses: Typeform/.github/.github/workflows/ci-standard-checks-workflow.yaml@v1 diff --git a/.github/workflows/comment-deploy-link.yaml b/.github/workflows/comment-deploy-link.yaml index 424ea19..a150ed9 100644 --- a/.github/workflows/comment-deploy-link.yaml +++ b/.github/workflows/comment-deploy-link.yaml @@ -12,6 +12,10 @@ on: version: type: string required: true + git-sha: + type: string + required: false + default: ${{ github.event.pull_request.head.sha }} update-comment: type: boolean required: false @@ -77,7 +81,7 @@ jobs: id: find-comment with: issue-number: ${{ github.event.number }} - body-includes: '🚀 Deploy this version in' + body-includes: "Deploy this version of `${{ inputs.service }}` in" - name: Create Comment uses: peter-evans/create-or-update-comment@v4 @@ -86,8 +90,8 @@ jobs: with: issue-number: ${{ github.event.number }} body: | - 🎉 Version `${{ inputs.version }}` created, hooray! - 🚀 Deploy this version in an **ephemeral environment** with `--reference`: + 🎉 Version `${{ inputs.version }}` of service `${{ inputs.service }}` from commit ${{ inputs.git-sha }} created, hooray! + 🚀 Deploy this version of `${{ inputs.service }}` in an **ephemeral environment** with `--reference`: ${{ steps.set-result.outputs.result }} - name: Update Comment @@ -97,8 +101,8 @@ jobs: with: issue-number: ${{ github.event.number }} body: | - 🎉 Version `${{ inputs.version }}` created, hooray! - 🚀 Deploy this version in an **ephemeral environment** with `--reference`: + 🎉 Version `${{ inputs.version }}` of service `${{ inputs.service }}` from commit ${{ inputs.git-sha }} created, hooray! + 🚀 Deploy this version of `${{ inputs.service }}` in an **ephemeral environment** with `--reference`: ${{ steps.set-result.outputs.result }} comment-id: ${{ steps.find-comment.outputs.comment-id }} edit-mode: replace diff --git a/.github/workflows/deep-purple-checks.yml b/.github/workflows/deep-purple-checks.yml index 870461b..fe694d5 100644 --- a/.github/workflows/deep-purple-checks.yml +++ b/.github/workflows/deep-purple-checks.yml @@ -9,6 +9,11 @@ on: required: true STAGING_PERSONAL_ACCESS_TOKEN: required: true + inputs: + app: + type: string + default: "" + required: false jobs: run-deep-purple-tests: @@ -24,7 +29,12 @@ jobs: - name: Extract app name from package.json run: | - echo "APP_NAME=$(jq -r '.name' package.json | sed 's/@typeform\///')" >> $GITHUB_ENV + APP="${{ inputs.app }}" + if [ -z "${APP}" ]; then + echo "APP_NAME=$(jq -r '.name' package.json | sed 's/@typeform\///')" >> $GITHUB_ENV + else + echo "APP_NAME=${APP}" >> $GITHUB_ENV + fi - name: Print extracted app name run: echo "Extracted APP_NAME is ${{ env.APP_NAME }}" diff --git a/.github/workflows/graphql-generate-persisted-operations.yml b/.github/workflows/graphql-generate-persisted-operations.yml new file mode 100644 index 0000000..a87c444 --- /dev/null +++ b/.github/workflows/graphql-generate-persisted-operations.yml @@ -0,0 +1,109 @@ +name: "Generate persisted operations" + +on: + workflow_call: + secrets: + GH_TOKEN: + required: true + +jobs: + update-allow-list: + runs-on: [self-hosted, ci-universal] + env: + GH_TOKEN: ${{ secrets.GH_TOKEN }} + GRAPHQL_ENDPOINTS: | + https://graphqlbff.staging.internal.tfdev.typeform.tf + https://graphqlbff.tfprod.internal.typeform.tf + https://graphqlbff.tfprod.internal.eu.typeform.tf + https://graphqlbff.tfprod.internal.eu-central-1.typeform.tf + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 22 + + - name: Install Yarn + run: npm install -g yarn@1.22.22 + + - name: Set GitHub packages registry + run: | + npm config set '//npm.pkg.github.com/:_authToken' ${{ secrets.GH_TOKEN }} + npm config set @typeform:registry https://npm.pkg.github.com/ + + - name: Check if GraphQL endpoints are reachable + run: | + readarray -t ENDPOINTS <<< "$GRAPHQL_ENDPOINTS" + for url in "${ENDPOINTS[@]}"; do + [[ -z "$url" ]] && continue # skip empty lines + echo "Pinging $url..." + curl_exit_code=0 + curl --max-time 10 "$url?runNumber=$GITHUB_RUN_NUMBER" || curl_exit_code=$? + if [ $curl_exit_code -ne 0 ]; then + echo "❌ Curl command failed with exit code $curl_exit_code" + exit $curl_exit_code + fi + done + + - name: Install only @typeform/generate-persisted-operations-manifest + run: | + mkdir persisted-ops-generator + cd persisted-ops-generator + yarn init -y + yarn add --no-lockfile --non-interactive --dev \ + @typeform/generate-persisted-operations-manifest \ + @apollo/generate-persisted-query-manifest@^1.2.2 \ + @apollo/client@^3.7.0 \ + graphql@^16.0.0 + cd .. + + - name: Generate Persisted Operations + run: | + node persisted-ops-generator/node_modules/@typeform/generate-persisted-operations-manifest/dist/index.js + env: + GQL_MANIFEST_DOCUMENTS: '["**/*.{js,ts,tsx,graphql}","!**/*.d.ts","!**/*.spec.{ts,tsx}","!**/*.test.{ts,tsx}","!node_modules/**","!persisted-ops-generator/**"]' + GQL_MANIFEST_OUTPUT: "generated/persisted-query-manifest.json" + + - name: List generated files + run: | + echo "Listing contents of ./generated directory:" + ls -la generated + + - name: Display persisted-query-manifest.json + run: | + echo "Contents of generated/persisted-query-manifest.json:" + cat generated/persisted-query-manifest.json + + - name: Extract app name from package.json + run: | + echo "APP_NAME=$(jq -r '.name' package.json | sed 's/@typeform\///')" >> $GITHUB_ENV + + - name: Print extracted app name + run: echo "Extracted APP_NAME is ${{ env.APP_NAME }}" + + - name: Upload manifest to internal allow list for all endpoints + run: | + mapfile -t ENDPOINTS <<< "${GRAPHQL_ENDPOINTS}" + curl_exit_code=0 + for url in "${ENDPOINTS[@]}"; do + [[ -z "$url" ]] && continue # skip empty lines + echo "Uploading manifest to $url/internal/operation-allow-list?deploymentRunNumber=$GITHUB_RUN_NUMBER&appName=${APP_NAME}" + curl --fail --max-time 30 -X PATCH "$url/internal/operation-allow-list?deploymentRunNumber=$GITHUB_RUN_NUMBER&appName=${APP_NAME}" \ + -H "Content-Type: application/json" \ + --data-binary "@generated/persisted-query-manifest.json" + + if [ $? -ne 0 ]; then + echo "❌ Failed to upload manifest to $url" + curl_exit_code=1 + else + echo "✅ Successfully uploaded to $url" + fi + done + + if [ $curl_exit_code -ne 0 ]; then + echo "❌ One or more uploads failed, failing workflow" + exit $curl_exit_code + fi diff --git a/reusable-workflows/graphql-generate-persisted-operations/graphql-generate-persisted-operations.yml b/reusable-workflows/graphql-generate-persisted-operations/graphql-generate-persisted-operations.yml new file mode 120000 index 0000000..b4c94fa --- /dev/null +++ b/reusable-workflows/graphql-generate-persisted-operations/graphql-generate-persisted-operations.yml @@ -0,0 +1 @@ +../../.github/workflows/graphql-generate-persisted-operations.yml \ No newline at end of file