Skip to content

feat: add bucket upload workflow #275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 79 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
7cf472d
new workflow
cx-miguel-neiva Mar 14, 2025
d66ac45
test new version
cx-miguel-neiva Mar 14, 2025
49025e9
Descrição das alterações que fiz
cx-miguel-neiva Mar 14, 2025
3611e7e
Updated workflow
cx-miguel-neiva Mar 14, 2025
45a35f4
Workflow updatedd
cx-miguel-neiva Mar 14, 2025
e4774ed
updated
cx-miguel-neiva Mar 14, 2025
dd504f8
Updated workflow
cx-miguel-neiva Mar 14, 2025
dd6a3d9
Updated workflow artifact version 3
cx-miguel-neiva Mar 14, 2025
ee23e14
Updated workflow artifact version 4
cx-miguel-neiva Mar 14, 2025
c9dce68
Add debug feature
cx-miguel-neiva Mar 14, 2025
39f6ffb
Added print
cx-miguel-neiva Mar 14, 2025
8e31257
Change artifact upload
cx-miguel-neiva Mar 14, 2025
06ee450
Add trigger
cx-miguel-neiva Mar 14, 2025
3c79e90
Add pr-number hardcoded
cx-miguel-neiva Mar 17, 2025
e99ae93
Add pr-number env
cx-miguel-neiva Mar 17, 2025
7cbdabd
Add metadados.json
cx-miguel-neiva Mar 17, 2025
a485a12
Add metadados.json
cx-miguel-neiva Mar 17, 2025
f335074
Sintaxe update
cx-miguel-neiva Mar 17, 2025
46c5891
New working directory
cx-miguel-neiva Mar 17, 2025
b08cb32
New working directory
cx-miguel-neiva Mar 17, 2025
744056e
New Iam Policies
cx-miguel-neiva Mar 17, 2025
9eee8d4
organized
cx-miguel-neiva Mar 17, 2025
0f426e5
Change to pull request
cx-miguel-neiva Mar 17, 2025
d5211bb
change syntax
cx-miguel-neiva Mar 17, 2025
7510c31
Final version
cx-miguel-neiva Mar 17, 2025
6996bec
Syntax error updated
cx-miguel-neiva Mar 17, 2025
9189a6d
New timestamp
cx-miguel-neiva Mar 17, 2025
c42f7df
Correct Timestamp
cx-miguel-neiva Mar 17, 2025
af09117
Final version
cx-miguel-neiva Mar 17, 2025
15626d9
Final version v2
cx-miguel-neiva Mar 17, 2025
261cceb
Change 2ms version
cx-miguel-neiva Mar 17, 2025
9e9570d
Change 2ms version not showing
cx-miguel-neiva Mar 18, 2025
f063855
Final Version
cx-miguel-neiva Mar 18, 2025
f668b39
Updated 2ms version
cx-miguel-neiva Mar 18, 2025
5d9a163
Remove artifact
cx-miguel-neiva Mar 18, 2025
0349ebe
Build and compile 2ms from a commit or pr
cx-miguel-neiva Mar 18, 2025
acd3e6f
Corrected YAML syntaxe
cx-miguel-neiva Mar 18, 2025
3c61dda
Added shell
cx-miguel-neiva Mar 18, 2025
c16e177
Added shell to every step
cx-miguel-neiva Mar 18, 2025
fa250e1
Remove Composite
cx-miguel-neiva Mar 18, 2025
1f0c819
Run 2ms in workflow
cx-miguel-neiva Mar 19, 2025
68ec442
Trigger on pull_request
cx-miguel-neiva Mar 19, 2025
5c0c9da
added git fetch
cx-miguel-neiva Mar 19, 2025
7ea6c71
Changed worflow trigger
cx-miguel-neiva Mar 19, 2025
5028e9d
Changed workflow trigger v2
cx-miguel-neiva Mar 19, 2025
7b0945c
Change Load Repos from JSON
cx-miguel-neiva Mar 19, 2025
598344c
Change Load Repos from JSON v2
cx-miguel-neiva Mar 19, 2025
8ea3e96
CChange structure
cx-miguel-neiva Mar 19, 2025
210541c
Verify List of repos
cx-miguel-neiva Mar 19, 2025
f8bbefc
Check 2ms Scan
cx-miguel-neiva Mar 19, 2025
2828f1d
add Repos Son
cx-miguel-neiva Mar 19, 2025
5947f07
add binary 2ms
cx-miguel-neiva Mar 19, 2025
340733a
coment bugs
cx-miguel-neiva Mar 19, 2025
f2443c2
coment bugs v2
cx-miguel-neiva Mar 19, 2025
32cddc3
Yaml syntaxe
cx-miguel-neiva Mar 19, 2025
8928700
Change load Repos
cx-miguel-neiva Mar 19, 2025
579d296
Correct Syntaxe
cx-miguel-neiva Mar 19, 2025
5f15a7b
New Strucure
cx-miguel-neiva Mar 19, 2025
a7801b0
remove 2ms in json
cx-miguel-neiva Mar 19, 2025
20996b4
add dir repos
cx-miguel-neiva Mar 19, 2025
4c3d20b
Verify
cx-miguel-neiva Mar 19, 2025
1a28303
Try again
cx-miguel-neiva Mar 19, 2025
a4af693
On pull request
cx-miguel-neiva Mar 19, 2025
5ff120d
try
cx-miguel-neiva Mar 19, 2025
2caa4ed
Add branches
cx-miguel-neiva Mar 19, 2025
cae845b
Add branches
cx-miguel-neiva Mar 19, 2025
6fb7087
Add branches event
cx-miguel-neiva Mar 19, 2025
81dbac2
add artifact
cx-miguel-neiva Mar 19, 2025
e6a377f
add backup
cx-miguel-neiva Mar 19, 2025
9c0c5cd
add backup to results
cx-miguel-neiva Mar 19, 2025
6888dae
add backup to results
cx-miguel-neiva Mar 19, 2025
d742a70
add backup to results
cx-miguel-neiva Mar 19, 2025
98cfee1
add comment to pr
cx-miguel-neiva Mar 19, 2025
905e2a2
add comment to pr
cx-miguel-neiva Mar 19, 2025
4df6048
Error fix
cx-miguel-neiva Mar 19, 2025
e408994
Error fix
cx-miguel-neiva Mar 19, 2025
6155847
Errror fix
cx-miguel-neiva Mar 20, 2025
d676ac0
Errror fix table
cx-miguel-neiva Mar 20, 2025
bdbe575
Add green and red image for Table
cx-miguel-neiva Mar 20, 2025
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
145 changes: 145 additions & 0 deletions .github/workflows/bucket-upload.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
on:
pull_request:

jobs:
bucket-upload-S3:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
ref: ${{ github.event.pull_request.head.sha }}

- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: "^1.22"

- name: Clone 2ms Repository and Checkout Commit SHA
run: |
git clone https://github.com/checkmarx/2ms.git $GITHUB_WORKSPACE/2ms
cd $GITHUB_WORKSPACE/2ms
git fetch --all
git checkout ${{ github.event.pull_request.head.sha }}
go build -o $GITHUB_WORKSPACE/2ms/dist/2ms main.go
chmod +x $GITHUB_WORKSPACE/2ms/dist/2ms

- name: Load Repos from JSON and Clone Each Repo
run: |
curl -o /tmp/repos.json https://raw.githubusercontent.com/cx-miguel-neiva/2ms-github-action/main/repos.json
REPOS_LIST=$(jq -r '.projects[]' /tmp/repos.json | tr '\n' ' ')
echo "repos=$REPOS_LIST" >> $GITHUB_ENV
for repo_url in $REPOS_LIST; do
repo_name=$(basename "$repo_url" .git)
mkdir -p "$GITHUB_WORKSPACE/repos/$repo_name"
git clone "$repo_url" "$GITHUB_WORKSPACE/repos/$repo_name"
done

- name: Run 2ms Scan for each repo
run: |
mkdir -p $GITHUB_WORKSPACE/results
IFS=' ' read -r -a REPOS_ARRAY <<< "$repos"
touch $GITHUB_WORKSPACE/scan_results.json
echo "[" > $GITHUB_WORKSPACE/scan_results.json
for repo_url in "${REPOS_ARRAY[@]}"; do
repo_name=$(basename "$repo_url" .git)
result_sarif="$GITHUB_WORKSPACE/results/$repo_name.sarif"
start_time=$(date +%s.%N)
if $GITHUB_WORKSPACE/2ms/dist/2ms filesystem --path "$GITHUB_WORKSPACE/repos/$repo_name" --ignore-on-exit results --report-path "$result_sarif"; then
scan_status="success"
else
scan_status="failure"
fi
end_time=$(date +%s.%N)
execution_time=$(echo "$end_time - $start_time" | bc)
execution_time_formatted=$(printf "%.2f" "$execution_time")
echo "{
\"repo_name\": \"$repo_name\",
\"scan_status\": \"$scan_status\",
\"execution_time\": \"$execution_time_formatted\"
}," >> $GITHUB_WORKSPACE/scan_results.json
done
sed -i '$ s/,$//' $GITHUB_WORKSPACE/scan_results.json
echo "]" >> $GITHUB_WORKSPACE/scan_results.json
cp -r $GITHUB_WORKSPACE/results $GITHUB_WORKSPACE/results_backup

- name: Get Results Directory
id: get_results_dir
run: |
echo "results_dir=results" >> $GITHUB_ENV

- name: Get 2ms Version
id: get_twoms_version
run: |
echo "twoms_version=$(curl -s https://api.github.com/repos/checkmarx/2ms/releases/latest | jq -r '.tag_name')" >> $GITHUB_ENV

- name: Set S3 Destination Path
id: set_s3_path
run: |
BRANCH_NAME="${{ github.head_ref || github.ref_name }}"
PR_NUMBER="${{ github.event.number }}"
ENGINE="2ms"
COMMIT_HASH="${{ github.sha }}"
PR_OWNER="${{ github.actor }}"
TARGET_BRANCH="master"
DEST_DIR="${ENGINE}/${TARGET_BRANCH}/${BRANCH_NAME}/${{ env.twoms_version }}/pr-${PR_NUMBER}"
echo "destination_dir=$DEST_DIR" >> $GITHUB_ENV
echo "results_dir=${{ env.results_dir }}" >> $GITHUB_ENV

- name: Organize SARIF files
run: |
mkdir -p "${{ env.results_dir }}/pr-${{ github.event.number }}"
for sarif_file in $GITHUB_WORKSPACE/results/*.sarif; do
if [[ -f "$sarif_file" ]]; then
project_name=$(basename "$sarif_file" .sarif)
mkdir -p "${{ env.results_dir }}/pr-${{ github.event.number }}/$project_name"
mv "$sarif_file" "${{ env.results_dir }}/pr-${{ github.event.number }}/$project_name/results.sarif"
fi
done

- name: Create Metadata File
run: |
COMMIT_TIMESTAMP=$(git log -1 --format=%ct)
METADATA_PATH="${{ env.results_dir }}/pr-${{ github.event.number }}/metadata.json"
echo '{
"seq": "'"${COMMIT_TIMESTAMP}"'",
"tag": "'"${{ github.event.number }}"'",
"comment": "'"${{ github.event.pull_request.title }}"'",
"commit": "'"${{ github.sha }}"'",
"owner": "'"${{ github.actor }}"'",
"branch": "'"${{ github.head_ref || github.ref_name }}"'",
"engine": "2ms",
"version": "'"${{ env.twoms_version }}"'"
}' > "$METADATA_PATH"

- name: Upload results to S3
run: |
aws s3 cp --recursive "${{ env.results_dir }}/pr-${{ github.event.number }}" "s3://${{ secrets.CES_AWS_BUCKET }}/${{ env.destination_dir }}" \
--storage-class STANDARD
env:
AWS_ACCESS_KEY_ID: ${{ secrets.CES_BUCKET_AWS_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.CES_BUCKET_AWS_SECRET_ACCESS_KEY }}

- name: Get Scan Results for Comment
id: scan_results
run: |
echo "| Repository | Status | Execution Time (seconds) |" > $GITHUB_WORKSPACE/scan_results_table.md
echo "|------------|--------|--------------------------|" >> $GITHUB_WORKSPACE/scan_results_table.md
jq -r '
.[] |
"| \(.repo_name) | " +
(if .scan_status == "success" then "✅" else "❌" end) +
" | \(.execution_time) |"' $GITHUB_WORKSPACE/scan_results.json >> $GITHUB_WORKSPACE/scan_results_table.md
echo "SCAN_RESULTS<<EOF" >> $GITHUB_ENV
cat $GITHUB_WORKSPACE/scan_results_table.md >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV

- name: Create PR Comment with Job Summary in Table
uses: peter-evans/create-or-update-comment@v2

Check warning on line 137 in .github/workflows/bucket-upload.yaml

View workflow job for this annotation

GitHub Actions / kics

[MEDIUM] Unpinned Actions Full Length Commit SHA

Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps mitigate the risk of a bad actor adding a backdoor to the action's repository, as they would need to generate a SHA-1 collision for a valid Git object payload. When selecting a SHA, you should verify it is from the action's repository and not a repository fork.
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
## 🛠 Scan Summary


${{ env.SCAN_RESULTS }}

Loading