Skip to content

Teste release automático #12

Teste release automático

Teste release automático #12

Workflow file for this run

name: Auto Release on Commit
permissions:
contents: write # Permissões para acessar e modificar conteúdo do repositório
actions: read # Permissões para executar ações
on:
push:
branches:
- main
paths:
- 'lambda_functions/**' # Só dispara se houver mudanças nessa pasta
jobs:
create-release:
name: Create Release
runs-on: ubuntu-latest
steps:
# Checkout do código do repositório
- name: Checkout repository
uses: actions/checkout@v2
# Verifica se houve mudanças dentro de lambda_functions
- name: Check changes in lambda_functions
id: changes
run: |
if git diff --name-only HEAD~1 HEAD | grep '^lambda_functions/'; then
echo "has_changes=true" >> $GITHUB_ENV
else
echo "has_changes=false" >> $GITHUB_ENV
fi
# Condicional: Segue o fluxo apenas se houver mudanças na pasta
- name: Exit if no changes in lambda_functions
if: ${{ env.has_changes == 'false' }}
run: exit 0
# Instala as dependências da pasta lambda_functions
- name: Install dependencies
working-directory: ./lambda_functions
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt -t .
# Identifica a última tag
- name: Get the latest tag
id: last_tag
run: echo "tag=$(git describe --tags $(git rev-list --tags --max-count=1) || echo 'lambda_functions_v0.1')" >> $GITHUB_ENV
# Define a versão para o release
- name: Set release version
id: get_version
run: |
latest_tag=$(git describe --tags $(git rev-list --tags --max-count=1) || echo 'lambda_functions_v0.1')
version=$(echo $latest_tag | sed 's/lambda_functions_v//')
IFS='.' read -r major minor patch <<< "$version"
minor=$((minor + 1))
new_version="lambda_functions_v${major}.${minor}"
echo "New version is $new_version"
echo "version=$new_version" >> $GITHUB_ENV
# Cria um arquivo ZIP da pasta lambda_functions (se houver mudanças)
- name: Zip lambda_functions folder
if: ${{ env.has_changes == 'true' }}
run: zip -r lambda_functions_${{ env.version }}.zip lambda_functions
# Verifica se a tag já existe
- name: Check if tag exists
run: |
if git rev-parse "refs/tags/${{ env.tag }}" >/dev/null 2>&1; then
echo "Tag exists"
echo "exists=true" >> $GITHUB_ENV
else
echo "Tag does not exist"
echo "exists=false" >> $GITHUB_ENV
fi
# Cria o release no GitHub (se não existir uma com mesmo nome)
- name: Create Release
id: create_release
if: env.exists == 'false'
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.version }}
release_name: ${{ env.version }}
body_path: ./release_notes.md
draft: false
prerelease: false
# Sobe o pacote de artefatos no release (se houver mudanças)
- name: Upload Release Asset
if: ${{ env.has_changes == 'true' }}
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: lambda_functions_${{ env.version }}.zip
asset_name: lambda_functions_${{ env.version }}.zip
asset_content_type: application/zip
# Remove o arquivo .zip local após o release (se for criado)
- name: Clean up
if: ${{ env.has_changes == 'true' }}
run: rm lambda_functions_${{ env.version }}.zip