Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 58 additions & 3 deletions .github/workflows/update-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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:
Expand All @@ -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")
Expand Down Expand Up @@ -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}"
Expand All @@ -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: |
Expand All @@ -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
Loading