Build Metadata and Create PR #11
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: Build Metadata and Create PR | |
on: | |
workflow_dispatch: # Permite que o fluxo de trabalho seja acionado manualmente | |
jobs: | |
run-script-and-create-pr: | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Checkout do repositório | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
# Step 2: Configurar Python | |
- name: Set up Python 3.x | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.x' | |
# Step 3: Instalar dependências (se houver) | |
- name: Install dependencies | |
run: | | |
pip install -r requirements.txt | |
# Step 4: Executar o script Python | |
- name: Run metadata generator script | |
run: | | |
python scripts/metadata-generator.py | |
# Step 5: Checkout do segundo repositório para criar a PR | |
- name: Checkout target repository | |
uses: actions/checkout@v3 | |
with: | |
repository: Chrystinne/pr-metadata-generator | |
path: pr-repo | |
token: ${{ secrets.MY_PERSONAL_TOKEN }} | |
# Step 6: Copiar a pasta datasets para o repositório de destino | |
- name: Copy datasets to target repo | |
run: | | |
cp -r datasets pr-repo/ | |
# Step 7: Criar um novo branch ou alternar para ele se já existir | |
- name: Create or switch to branch | |
run: | | |
cd pr-repo | |
git fetch origin | |
if git rev-parse --verify origin/metadata-update-branch; then | |
git reset --hard # Limpa quaisquer alterações locais que possam causar conflitos | |
git checkout -f metadata-update-branch # Força o checkout para sobrescrever arquivos | |
git pull origin metadata-update-branch | |
else | |
git checkout -b metadata-update-branch | |
fi | |
# Step 8: Configurar o usuário do Git | |
- name: Set up Git user | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "chrystinne" | |
# Step 9: Commit das mudanças (com debug) | |
- name: Commit changes | |
run: | | |
cd pr-repo | |
git status # Verifica se há mudanças detectadas pelo Git | |
git diff # Mostra as diferenças nos arquivos para confirmação | |
git add -f datasets # Força a adição dos arquivos modificados | |
git commit -m "Add datasets from metadata generator" || echo "No changes to commit" | |
git log -1 # Verifica o último commit para depuração | |
# Step 10: Push do novo branch (com debug) | |
- name: Push changes | |
run: | | |
cd pr-repo | |
git push origin metadata-update-branch || (git pull --rebase origin metadata-update-branch && git push origin metadata-update-branch) | |
git branch -r # Lista os branches remotos para debug | |
# Step 11: Criar um pull request | |
- name: Create pull request | |
uses: peter-evans/create-pull-request@v5 | |
with: | |
token: ${{ secrets.MY_PERSONAL_TOKEN }} | |
commit-message: "Add datasets from metadata generator" | |
branch: metadata-update-branch | |
base: main | |
title: "Metadata update from Python script" | |
body: "This PR contains the datasets folder generated by the metadata-generator script." |