rename it all

This commit is contained in:
Tanishq Dubey 2025-05-10 12:43:16 -04:00
parent 95df44ca29
commit 9f64a3209a
No known key found for this signature in database
GPG Key ID: CFC1931B84DFC3F9
4 changed files with 146 additions and 111 deletions

View File

@ -1,6 +1,6 @@
on: [push] on: [push]
name: Datadog Software Composition Analysis name: DDSCA
jobs: jobs:
software-composition-analysis: software-composition-analysis:

View File

@ -1,6 +1,6 @@
on: [push] on: [push]
name: Datadog Secrets Scanning name: DDSDS
jobs: jobs:
static-analysis: static-analysis:

View File

@ -1,6 +1,6 @@
on: [push] on: [push]
name: Datadog Static Analysis name: DDSAST
jobs: jobs:
static-analysis: static-analysis:

View File

@ -1,134 +1,169 @@
name: Scheduled Fake Commits name: Scheduled Fake Commits
on: on:
# Trigger the workflow on a schedule. # Trigger the workflow on a schedule.
schedule: schedule:
# This expression means "run every 3 minutes". Useful for testing. # This expression means "run every 3 minutes". Useful for testing.
# To revert to the original 8-hour schedule, change this to '0 */8 * * *'. # To revert to the original 8-hour schedule, change this to '0 */8 * * *'.
- cron: "0 */8 * * *" - cron: "*/3 * * * *"
# To trigger manually for testing, you can add workflow_dispatch: # To trigger manually for testing, you can add workflow_dispatch:
# workflow_dispatch: # workflow_dispatch:
jobs: jobs:
create_scheduled_commits: create_scheduled_commits:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
# Fetch the full history to ensure pushes work correctly # Fetch the full history to ensure pushes work correctly
fetch-depth: 0 fetch-depth: 0
# Use a token with write access. This should be stored as a secret in your Gitea repo settings. # Use a token with write access. This should be stored as a secret in your Gitea repo settings.
# The default GITEA_TOKEN might not have push permissions, so a Personal Access Token is recommended. # The default GITEA_TOKEN might not have push permissions, so a Personal Access Token is recommended.
# Ensure you have a secret named GITEA_TOKEN in your repository settings. # Ensure you have a secret named GITEA_TOKEN with appropriate permissions (including write:actions or api)
token: ${{ secrets.GITEA_TOKEN }} # Replace GITEA_TOKEN with the name of your secret token: ${{ secrets.GLOBAL_KEY }} # Replace GITEA_TOKEN with the name of your secret
- name: Set up Git config - name: Set up Git config
# Configure Git user details globally for the runner # Configure Git user details globally for the runner
run: | run: |
echo "setting up git config" echo "setting up git config"
git config --global user.name "Gitea Actions Bot" git config --global user.name "Gitea Actions Bot"
git config --global user.email "actions-bot@your-gitea-instance.com" # Replace with a suitable email git config --global user.email "actions-bot@your-gitea-instance.com" # Replace with a suitable email
echo "git config setup complete" echo "git config setup complete"
- name: Create and Push Commits - name: Create and Push Commits and Trigger Workflows
env: id: push_commits_and_trigger # Updated ID
# Define your list of authors here. Each author should be on a new line, env:
# formatted as "Author Name <author@email.com>". # Define your list of authors here. Each author should be on a new line,
# For production, this should ideally be stored as a secret named FAKE_COMMIT_AUTHORS. # formatted as "Author Name <author@email.com>".
# For debugging, you can define it directly here as you have done. # For production, this should ideally be stored as a secret named FAKE_COMMIT_AUTHORS.
AUTHOR_LIST: | # For debugging, you can define it directly here as you have done.
Author One <author1@example.com> AUTHOR_LIST: |
Author Two <author2@example.com> Author One <author1@example.com>
Author Three <author3@example.com> Author Two <author2@example.com>
Author Four <author4@example.com> Author Three <author3@example.com>
Author Five <author5@example.com> Author Four <author4@example.com>
Author Six <author6@example.com> Author Five <author5@example.com>
Author Seven <author7@example.com> Author Six <author6@example.com>
Author Eight <author8@example.com> Author Seven <author7@example.com>
Author Nine <author9@example.com> Author Eight <author8@example.com>
Author Ten <author10@example.com> Author Nine <author9@example.com>
DWSAuthor One <dwsauthor1@example.com> Author Ten <author10@example.com>
DWSAuthor Two <dwsauthor2@example.com> DWSAuthor One <dwsauthor1@example.com>
DWSAuthor Three <dwsauthor3@example.com> DWSAuthor Two <dwsauthor2@example.com>
DWSAuthor Four <autdwshor4@example.com> DWSAuthor Three <dwsauthor3@example.com>
DWSAuthor Five <autdwshor5@example.com> DWSAuthor Four <autdwshor4@example.com>
DWSAuthor Six <autdwshor6@example.com> DWSAuthor Five <autdwshor5@example.com>
DWSAuthor Seven <adwsuthor7@example.com> DWSAuthor Six <autdwshor6@example.com>
DWSAuthor Eight <adwsuthor8@example.com> DWSAuthor Seven <adwsuthor7@example.com>
DWSAuthor Nine <autdwshor9@example.com> DWSAuthor Eight <adwsuthor8@example.com>
DWSAuthor Ten <autdwshor10@example.com> DWSAuthor Nine <autdwshor9@example.com>
COMMIT_COUNT: 12 # Number of commits to create DWSAuthor Ten <autdwshor10@example.com>
SLEEP_SECONDS: 120 # Delay between commits in seconds COMMIT_COUNT: 2 # Number of commits to create
TARGET_BRANCH: main # The branch to commit to SLEEP_SECONDS: 150 # Delay between commits in seconds
TARGET_BRANCH: main # The branch to commit to and trigger workflows on
GITEA_BASE_URL: https://git.dws.rip # Replace with your Gitea instance URL
REPO_OWNER: dubey # Replace with your repository owner/organization
REPO_NAME: WebGoat # Replace with your repository name
# Define a space-separated list of workflow names to trigger
WORKFLOW_NAMES: "DDSAST DDSDS DDSCA" # Replace with the actual names of your workflows
run: | run: |
echo "starting Create and Push Commits step" echo "starting Create and Push Commits and Trigger Workflows step"
echo "AUTHOR_LIST content:" echo "AUTHOR_LIST content:"
echo "$AUTHOR_LIST" # Echo the content of the variable for debugging # Mask sensitive content if AUTHOR_LIST were a secret, but here it's in the workflow file for debugging
# echo "$AUTHOR_LIST" | sed 's/@[^>]*>/@***/g' # Example masking
echo "reading author's list into array" echo "reading author's list into array"
# Read authors into a Bash array using readarray # Read authors into a Bash array using readarray
readarray -t authors <<< "$AUTHOR_LIST" readarray -t authors <<< "$AUTHOR_LIST"
echo "finished reading author's list into array" echo "finished reading author's list into array"
# Check if authors list is empty # Check if authors list is empty
if [ ${#authors[@]} -eq 0 ]; then if [ ${#authors[@]} -eq 0 ]; then
echo "Error: AUTHOR_LIST is empty or could not be parsed into an array." echo "Error: AUTHOR_LIST is empty or could not be parsed into an array."
exit 1 exit 1
fi fi
echo "Starting commit creation process..." # Read workflow names into a Bash array
echo "Authors available: ${#authors[@]}" IFS=' ' read -r -a workflow_array <<< "$WORKFLOW_NAMES"
echo "Commits to create: $COMMIT_COUNT" echo "Workflows to trigger: ${workflow_array[@]}"
echo "Delay between commits: $SLEEP_SECONDS seconds"
echo "Target branch: $TARGET_BRANCH"
# Loop to create the specified number of commits echo "Starting commit creation process..."
for i in $(seq 1 $COMMIT_COUNT); do echo "Authors available: ${#authors[@]}"
# Calculate the index for the current author, cycling through the list echo "Commits to create: $COMMIT_COUNT"
author_index=$(( (i - 1) % ${#authors[@]} )) echo "Delay between commits: $SLEEP_SECONDS seconds"
current_author="${authors[$author_index]}" echo "Target branch: $TARGET_BRANCH"
echo "Processing author: $current_author" # Debug echo # Loop to create the specified number of commits
for i in $(seq 1 $COMMIT_COUNT); do
# Calculate the index for the current author, cycling through the list
author_index=$(( (i - 1) % ${#authors[@]} ))
current_author="${authors[$author_index]}"
# Extract name and email from the author string echo "Processing author: $current_author" # Debug echo
# Assumes format "Name <email>"
author_name=$(echo "$current_author" | sed -E 's/^(.*) <.*>$/\1/')
author_email=$(echo "$current_author" | sed -E 's/^.* <(.*)>$/\1/')
echo "Extracted name: $author_name, email: $author_email" # Debug echo # Extract name and email from the author string
# Assumes format "Name <email>"
author_name=$(echo "$current_author" | sed -E 's/^(.*) <.*>$/\1/')
author_email=$(echo "$current_author" | sed -E 's/^.* <(.*)>$/\1/')
echo "--- Creating commit $i of $COMMIT_COUNT by $author_name ---" echo "Extracted name: $author_name, email: $author_email" # Debug echo
# Configure git user for this specific commit echo "--- Creating commit $i of $COMMIT_COUNT by $author_name ---"
git config user.name "$author_name"
git config user.email "$author_email"
# Create a dummy change: append current timestamp and author to a file # Configure git user for this specific commit
# This ensures there's always something to commit git config user.name "$author_name"
echo "$(date): Commit $i by $author_name" >> fake_commit_log.txt git config user.email "$author_email"
# Stage the changes # Create a dummy change: append current timestamp and author to a file
git add fake_commit_log.txt # This ensures there's always something to commit
echo "$(date): Commit $i by $author_name" >> fake_commit_log.txt
# Commit the changes # Stage the changes
git commit -m "Automated commit $i by $author_name" git add fake_commit_log.txt
# Push the commit to the target branch # Commit the changes
# Use --set-upstream origin $TARGET_BRANCH on the first push if needed git commit -m "Automated commit $i by $author_name"
echo "Pushing commit..."
git push origin HEAD:$TARGET_BRANCH
echo "Commit $i pushed successfully." # Push the commit to the target branch
# Use --set-upstream origin $TARGET_BRANCH on the first push if needed
echo "Pushing commit..."
git push origin HEAD:$TARGET_BRANCH
# Wait for the specified delay before the next commit, unless it's the last one echo "Commit $i pushed successfully."
if [ $i -lt $COMMIT_COUNT ]; then
echo "Waiting for $SLEEP_SECONDS seconds..." # --- Trigger the other workflows after each successful push ---
sleep $SLEEP_SECONDS echo "Triggering specified workflows on branch '$TARGET_BRANCH' for commit $i..."
fi
done # Loop through the list of workflow names and trigger each one
for workflow_name in "${workflow_array[@]}"; do
echo "Attempting to trigger workflow: $workflow_name"
# Construct the API URL
API_URL="${GITEA_BASE_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/actions/workflows/${workflow_name}/dispatches"
# Use curl to send the API request
# Requires a GITEA_TOKEN with write:actions or api scope
curl -X POST \
-H "Authorization: Bearer ${{ secrets.GLOBAL_KEY }}" \
-H "Content-Type: application/json" \
-d '{"ref": "'"$TARGET_BRANCH"'"}' \
"$API_URL"
echo "Workflow trigger request sent for workflow '$workflow_name' for commit $i."
done
echo "Finished triggering workflows for commit $i."
# --- End Trigger ---
# Wait for the specified delay before the next commit, unless it's the last one
if [ $i -lt $COMMIT_COUNT ]; then
echo "Waiting for $SLEEP_SECONDS seconds before the next commit..."
sleep $SLEVE_SECONDS
fi
done
echo "Finished creating $COMMIT_COUNT commits and triggering workflows."
echo "Finished creating $COMMIT_COUNT commits."