energia positiva #27
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Random Daily Commits | |
on: | |
schedule: | |
- cron: "0 11 * * *" # Executa uma vez ao dia as 11:00 UTC | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
permissions: | |
contents: write | |
pull-requests: write # Permissão para criar PR | |
jobs: | |
create_branch_and_commit: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up Git user | |
run: | | |
git config --global user.name "peregrinno" | |
git config --global user.email "[email protected]" | |
- name: Create new branch | |
run: | | |
BRANCH_NAME="random-commits-$(date +%Y%m%d_%H%M%S)" | |
echo "Branch criada: $BRANCH_NAME" | |
git checkout -b $BRANCH_NAME | |
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV # Define a variável de ambiente | |
- name: Generate random number of commits | |
run: | | |
# Gera um número aleatório entre 1 e 10 | |
RANDOM_COMMITS=$(( ( RANDOM % 10 ) + 1 )) | |
echo "Gerando $RANDOM_COMMITS commits para o dia." | |
# Loop para gerar os commits | |
for i in $(seq 1 $RANDOM_COMMITS); do | |
echo "Commit número $i em $(date)" >> commit.txt | |
git add commit.txt | |
git commit -m "Commit automático $i de $RANDOM_COMMITS no dia $(date)" | |
done | |
- name: Create Python Hello World file with random prefix | |
run: | | |
PREFIX=$(shuf -i 10000-99999 -n 1) | |
FILENAME="auto_src/${PREFIX}_helloworld.py" | |
echo 'print("Hello, World!")' > $FILENAME | |
git add $FILENAME | |
git commit -m "Adicionando Hello World em Python com prefixo aleatório: $FILENAME" | |
- name: Create JavaScript Hello World file with random prefix | |
run: | | |
PREFIX=$(shuf -i 10000-99999 -n 1) | |
FILENAME="auto_src/${PREFIX}_helloworld.js" | |
echo 'console.log("Hello, World!");' > $FILENAME | |
git add $FILENAME | |
git commit -m "Adicionando Hello World em JavaScript com prefixo aleatório: $FILENAME" | |
- name: Push commits to new branch | |
env: | |
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} # Substitua o GITHUB_TOKEN pelo PAT_TOKEN | |
run: | | |
# Certifique-se de que a nova branch seja enviada corretamente ao repositório remoto | |
git push --set-upstream https://x-access-token:${{ secrets.PAT_TOKEN }}@github.com/peregrinno/auto-commits.git $BRANCH_NAME | |
merge_created_branches: | |
runs-on: ubuntu-latest | |
needs: create_branch_and_commit # Job depende do Job anterior | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 # Necessário para pegar todas as branches | |
- name: List all branches that start with 'random-commits' | |
run: | | |
git fetch --all | |
# Lista todas as branches remotas que começam com 'random-commits' | |
BRANCHES=$(git branch -r | grep 'origin/random-commits' | sed 's/origin\///g' | xargs) | |
echo "Branches encontradas: $BRANCHES" | |
echo "BRANCHES=\"$BRANCHES\"" >> $GITHUB_ENV | |
- name: Merge branches into main | |
env: | |
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} | |
run: | | |
git checkout main | |
git pull origin main | |
# Itera sobre as branches e faz merge de cada uma | |
for BRANCH in $(echo $BRANCHES); do | |
echo "Fazendo merge da branch $BRANCH para main" | |
git merge --no-ff "$BRANCH" || echo "Falha ao fazer merge da branch $BRANCH" | |
done | |
# Push após o merge | |
git push origin main |