Repository navigation
158 lines (138 loc) · 7.09 KB
/
Copy pathupdate-cli.yml
File metadata and controls
158 lines (138 loc) · 7.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
name: Update checkmarx Java wrapper
on:
workflow_dispatch:
repository_dispatch:
types: [java-wrapper-version-update]
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false
permissions:
contents: read
jobs:
update-checkmarx-cli:
name: Update Checkmarx CLI
runs-on: cx-public-ubuntu-x64
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
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
lfs: true
persist-credentials: false
- name: Install Git LFS
run: git lfs install
- name: Configure Git user
run: |
git config --global user.name github-actions[bot]
git config --global user.email github-actions[bot]@users.noreply.github.com
- name: Get Latest Checkmarx Java Wrapper Version
id: ast-cli-java-wrapper
env:
DISPATCH_VERSION: ${{ github.event.client_payload.version }}
run: |
if [ -n "$DISPATCH_VERSION" ]; then
latest_tag="${DISPATCH_VERSION#v}"
if ! [[ "$latest_tag" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::error::Invalid version in the dispatch event: $DISPATCH_VERSION"
exit 1
fi
else
latest_tag=$(curl -s "https://repo1.maven.org/maven2/com/checkmarx/ast/ast-cli-java-wrapper/maven-metadata.xml" | grep -oPm1 "(?<=<latest>)[^<]+")
fi
current_tag=$(<ast-cli-java-wrapper.version)
echo "Latest Tag: $latest_tag"
echo "Current Tag: $current_tag"
if [ "$latest_tag" = "$current_tag" ]; then
echo "The tags match."
else
echo "The tags do not match."
fi
echo "release_tag=$latest_tag" >> $GITHUB_OUTPUT
echo "current_tag=$current_tag" >> $GITHUB_OUTPUT
- name: Update Checkmarx Java wrapper version
if: steps.ast-cli-java-wrapper.outputs.current_tag != steps.ast-cli-java-wrapper.outputs.release_tag
env:
RELEASE_TAG: ${{ steps.ast-cli-java-wrapper.outputs.release_tag }}
CURRENT_TAG: ${{ steps.ast-cli-java-wrapper.outputs.current_tag }}
run: |
# Update current release
echo "$RELEASE_TAG" > ast-cli-java-wrapper.version
current_version=ast-cli-java-wrapper-$CURRENT_TAG.jar
new_version=ast-cli-java-wrapper-$RELEASE_TAG.jar
sed -i "s/$current_version/$new_version/g" checkmarx-ast-eclipse-plugin/build.properties
sed -i "s/$current_version/$new_version/g" checkmarx-ast-eclipse-plugin/.classpath
sed -i "s/$current_version/$new_version/g" checkmarx-ast-eclipse-plugin/META-INF/MANIFEST.MF
cd checkmarx-ast-eclipse-plugin/lib/
rm -rf "$current_version"
curl -fL "https://repo1.maven.org/maven2/com/checkmarx/ast/ast-cli-java-wrapper/$RELEASE_TAG/${new_version}" --output "$new_version"
ls -la
cd ../..
# Track the new JAR file with LFS
FILE_PATH="checkmarx-ast-eclipse-plugin/lib/$new_version" # Correct path
echo "FILE_PATH: $FILE_PATH"
# Create the directory if it doesn't exist (important!)
# mv $new_version $FILE_PATH
# Ensure the file exists after download
if [ ! -f "$FILE_PATH" ]; then
echo "Error: File $FILE_PATH not found after download."
exit 1 # Fail the workflow
fi
git lfs track "$FILE_PATH"
git add .gitattributes
git add "$FILE_PATH"
git commit -m "Update ast-cli-java-wrapper to $RELEASE_TAG"
- name: Configure AWS credentials
if: steps.ast-cli-java-wrapper.outputs.current_tag != steps.ast-cli-java-wrapper.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.ast-cli-java-wrapper.outputs.current_tag != steps.ast-cli-java-wrapper.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.ast-cli-java-wrapper.outputs.current_tag != steps.ast-cli-java-wrapper.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.ast-cli-java-wrapper.outputs.current_tag != steps.ast-cli-java-wrapper.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.ast-cli-java-wrapper.outputs.current_tag != steps.ast-cli-java-wrapper.outputs.release_tag
run: echo "PLUGINS_APP_KEY=" >> "${GITHUB_ENV}"
- name: Create Pull Request
id: create_pull_request
if: steps.ast-cli-java-wrapper.outputs.current_tag != steps.ast-cli-java-wrapper.outputs.release_tag
uses: step-security/create-pull-request@50c103da2b9ca12cd5bc013fc6931051a5aa872b # v8.1.1
with:
token: ${{ steps.app-token.outputs.token }}
commit-message: Update ast-cli-java-wrapper to ${{ steps.ast-cli-java-wrapper.outputs.release_tag }}
title: Update ast-cli-java-wrapper with ${{ steps.ast-cli-java-wrapper.outputs.release_tag }}
body: |
Updates [ast-cli-java-wrapper][1] to ${{ steps.ast-cli-java-wrapper.outputs.release_tag }}
Auto-generated by [create-pull-request][2]
[1]: https://github.com/Checkmarx/ast-cli-java-wrapper
labels: cxone
branch: other/update_java_wrapper_${{ steps.ast-cli-java-wrapper.outputs.release_tag }}
- name: Enable auto-merge (squash after 2 cx-maintainers approvals)
if: steps.create_pull_request.outputs.pull-request-number != ''
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
PR_NUMBER: ${{ steps.create_pull_request.outputs.pull-request-number }}
run: gh pr merge "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" --auto --squash