Atualiza idade no README #371
This file contains hidden or 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: Atualiza idade no README | |
| permissions: | |
| contents: write | |
| on: | |
| schedule: | |
| - cron: '0 3 * * *' # Roda todo dia às 00:00 BRT (UTC-3) -> 03:00 UTC | |
| workflow_dispatch: | |
| jobs: | |
| update-readme: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checar código | |
| uses: actions/checkout@v4 | |
| - name: Atualizar idade no README.md | |
| id: update_age | |
| run: | | |
| set -e | |
| export TZ="America/Sao_Paulo" | |
| DATA_NASCIMENTO="2009-07-22" | |
| HOJE=$(date +'%Y-%m-%d') | |
| ano_nasc=${DATA_NASCIMENTO:0:4} | |
| mes_nasc=${DATA_NASCIMENTO:5:2} | |
| dia_nasc=${DATA_NASCIMENTO:8:2} | |
| ano_hoje=${HOJE:0:4} | |
| mes_hoje=${HOJE:5:2} | |
| dia_hoje=${HOJE:8:2} | |
| ANOS=$((ano_hoje - ano_nasc)) | |
| if [ "$mes_hoje" -lt "$mes_nasc" ] || { [ "$mes_hoje" -eq "$mes_nasc" ] && [ "$dia_hoje" -lt "$dia_nasc" ]; }; then | |
| ANOS=$((ANOS - 1)) | |
| fi | |
| echo "Hoje é $HOJE, aniversário em $dia_nasc/$mes_nasc, idade = $ANOS" | |
| if ! grep -q "<!--IDADE-->.*<!--/IDADE-->" README.md; then | |
| echo "ERRO: Marcador <!--IDADE--> não encontrado no README.md" | |
| exit 1 | |
| fi | |
| sed -i -E "s|(<!--IDADE-->)[^<]+(<!--/IDADE-->)|\1$ANOS\2|g" README.md | |
| echo "age=$ANOS" >> $GITHUB_OUTPUT | |
| - name: Mostrar trecho atualizado no README.md | |
| run: | | |
| grep -n "<!--IDADE-->.*<!--/IDADE-->" README.md | |
| - name: Verificar se houve mudanças no README.md | |
| id: check_changes | |
| run: | | |
| if git diff --exit-code README.md; then | |
| echo "changed=false" >> $GITHUB_OUTPUT | |
| echo "Nenhuma mudança detectada." | |
| else | |
| echo "changed=true" >> $GITHUB_OUTPUT | |
| echo "Mudança detectada." | |
| fi | |
| # Commit normal quando a idade muda | |
| - name: Commit da idade | |
| if: steps.check_changes.outputs.changed == 'true' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add README.md | |
| git commit -m "✨|Automatically updates age in the README to ${{ steps.update_age.outputs.age }} years" | |
| git push | |
| # Keep-alive: commit vazio no dia 1 de cada mês | |
| - name: Keep-alive mensal (commit vazio) | |
| if: steps.check_changes.outputs.changed == 'false' | |
| run: | | |
| DIA=$(date +'%d') | |
| if [ "$DIA" = "01" ]; then | |
| echo "Executando keep-alive mensal..." | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git commit --allow-empty -m "chore: keep workflows alive" | |
| git push | |
| else | |
| echo "Hoje não é dia 01 — keep-alive ignorado." | |
| fi |