-
Notifications
You must be signed in to change notification settings - Fork 0
103 lines (86 loc) · 3.52 KB
/
daily-random-commit.yml
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
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')
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