-
Notifications
You must be signed in to change notification settings - Fork 0
118 lines (98 loc) · 4.15 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
name: Random Daily Commits
on:
schedule:
- cron: "0 11 * * *"
workflow_dispatch:
push:
branches:
- main
permissions:
contents: write
pull-requests: write
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."
# Gera um prefixo aleatório
PREFIX=$(shuf -i 10000-99999 -n 1)
FILENAME="auto_src/${PREFIX}_commit.txt"
# Loop para gerar os commits
for i in $(seq 1 $RANDOM_COMMITS); do
echo "Commit número $i em $(date)" >> $FILENAME
git add $FILENAME
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 }}
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
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Git user for merge
run: |
git config --global user.name "peregrinno"
git config --global user.email "[email protected]"
- 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 chaos and delete merged branches
env:
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
BRANCHES: ${{ env.BRANCHES }}
run: |
git checkout chaos
git pull origin chaos
# Itera sobre as branches e faz merge de cada uma usando a referência origin/<branch>
for BRANCH in $(echo $BRANCHES); do
BRANCH=$(echo $BRANCH | tr -d '"') # Remove quaisquer aspas que ainda possam estar presentes
echo "Fazendo merge da branch origin/$BRANCH para chaos"
git merge --no-ff "origin/$BRANCH" || { echo "Falha ao fazer merge da branch origin/$BRANCH"; continue; }
# Se o merge for bem-sucedido, apaga a branch
echo "Merge bem-sucedido. Apagando branch origin/$BRANCH"
git push origin --delete "$BRANCH" || echo "Falha ao apagar a branch origin/$BRANCH"
done
# Push após o merge
git push origin chaos