From 8c9a68e88ac45dbea084214ab94b8b305b236cb8 Mon Sep 17 00:00:00 2001 From: Lior Poterman <191881919+cx-lior-poterman@users.noreply.github.com> Date: Thu, 26 Nov 2026 17:33:37 +0200 Subject: [PATCH] ci: open version-update PRs with the plugins release App (AST-192752) The update workflow runs in the release-automation environment, takes the version from the dispatch event and opens the PR with the plugins release GitHub App (private key from AWS Secrets Manager, masked). It then enables auto-merge; the PR still needs 2 cx-maintainers approvals. Restores the cli-version-update trigger; checksum downloads now fail on HTTP errors. Co-Authored-By: Claude Opus 4.8 (1M context) --- .github/workflows/update-cli.yml | 61 ++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/.github/workflows/update-cli.yml b/.github/workflows/update-cli.yml index 8171b3ea..a761f958 100644 --- a/.github/workflows/update-cli.yml +++ b/.github/workflows/update-cli.yml @@ -6,6 +6,8 @@ on: new_cli_version: description: 'New CLI version (optional)' required: false + repository_dispatch: + types: [cli-version-update] concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -17,6 +19,10 @@ permissions: jobs: update-checkmarx-cli: name: Update Checkmarx AST CLI + environment: release-automation + permissions: + contents: read # for actions/checkout; the branch push and the PR use the GitHub App token + id-token: write # for configure-aws-credentials to assume the AWS role via OIDC runs-on: cx-public-ubuntu-x64 steps: @@ -28,9 +34,13 @@ jobs: - name: Get Latest Checkmarx API version id: checkmarx-ast-cli env: - NEW_CLI_VERSION: ${{ github.event.inputs.new_cli_version }} + NEW_CLI_VERSION: ${{ github.event.inputs.new_cli_version || github.event.client_payload.version }} run: | if [ "$NEW_CLI_VERSION" ]; then + if ! [[ "$NEW_CLI_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "::error::Invalid CLI version: $NEW_CLI_VERSION" + exit 1 + fi LATEST_VERSION="$NEW_CLI_VERSION" else LATEST_VERSION=$(curl -sL https://api.github.com/repos/Checkmarx/ast-cli/releases/latest | jq -r ".tag_name") @@ -77,7 +87,7 @@ jobs: # Download binary TEMP_FILE="/tmp/ast-cli_${KEY}.${EXT}" - if curl -sL -o "$TEMP_FILE" "$URL"; then + if curl -fsL -o "$TEMP_FILE" "$URL"; then # Calculate SHA-256 CHECKSUM=$(sha256sum "$TEMP_FILE" | awk '{print $1}') echo "✓ ${KEY}: ${CHECKSUM}" @@ -98,13 +108,51 @@ jobs: echo "Checksums updated:" cat checkmarx-ast-cli.checksums + - name: Configure AWS credentials + if: steps.checkmarx-ast-cli.outputs.current_tag != steps.checkmarx-ast-cli.outputs.release_tag + uses: step-security/configure-aws-credentials@1448016543d4432bd608e0de7871c7bf9e9be925 # v6.2.1 + with: + role-to-assume: ${{ secrets.PLUGINS_APP_ROLE_ARN }} + aws-region: ${{ secrets.PLUGINS_APP_AWS_REGION }} + role-session-name: plugins-release-update-pr + + - name: Fetch GitHub App private key + if: steps.checkmarx-ast-cli.outputs.current_tag != steps.checkmarx-ast-cli.outputs.release_tag + uses: step-security/aws-secretsmanager-get-secrets@102b6b2a2528747bcc321bb99ef326d8be7ef58f # v3.0.1 + with: + secret-ids: PLUGINS_APP_KEY,${{ secrets.PLUGINS_APP_SECRET_NAME }} + + - name: Mask each line of the private key + if: steps.checkmarx-ast-cli.outputs.current_tag != steps.checkmarx-ast-cli.outputs.release_tag + run: | + while IFS= read -r line; do + line="${line%$'\r'}" + if [ -n "${line}" ]; then + echo "::add-mask::${line}" + fi + done <<< "${PLUGINS_APP_KEY}" + + - name: Create GitHub App token + id: app-token + if: steps.checkmarx-ast-cli.outputs.current_tag != steps.checkmarx-ast-cli.outputs.release_tag + uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0 + with: + client-id: ${{ secrets.PLUGINS_APP_CLIENT_ID }} + private-key: ${{ env.PLUGINS_APP_KEY }} + permission-contents: write # push the update branch + permission-pull-requests: write # open the PR and enable auto-merge + + - name: Remove the private key from the environment + if: steps.checkmarx-ast-cli.outputs.current_tag != steps.checkmarx-ast-cli.outputs.release_tag + run: echo "PLUGINS_APP_KEY=" >> "${GITHUB_ENV}" + # Create a Pull Request with the version changes - name: Create Pull Request id: cretae_pull_request if: steps.checkmarx-ast-cli.outputs.current_tag != steps.checkmarx-ast-cli.outputs.release_tag uses: step-security/create-pull-request@50c103da2b9ca12cd5bc013fc6931051a5aa872b # v8.1.1 with: - token: ${{ secrets.AUTOMATION_TOKEN }} + token: ${{ steps.app-token.outputs.token }} commit-message: Update checkmarx-ast-cli to ${{ steps.checkmarx-ast-cli.outputs.release_tag }} title: Update checkmarx-ast-cli binaries with ${{ steps.checkmarx-ast-cli.outputs.release_tag }} body: | @@ -115,3 +163,10 @@ jobs: [1]: https://github.com/Checkmarx/checkmarx-ast-cli labels: cxone branch: feature/update_cli_${{ steps.checkmarx-ast-cli.outputs.release_tag }} + + - name: Enable auto-merge (squash after 2 cx-maintainers approvals) + if: steps.cretae_pull_request.outputs.pull-request-number != '' + env: + GH_TOKEN: ${{ steps.app-token.outputs.token }} + PR_NUMBER: ${{ steps.cretae_pull_request.outputs.pull-request-number }} + run: gh pr merge "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" --auto --squash