-
Notifications
You must be signed in to change notification settings - Fork 1
113 lines (100 loc) · 3.91 KB
/
release.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
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@v4
with:
fetch-depth: 5
# Verifica se houve mudanças dentro de lambda_functions
- name: Check changes in lambda_functions
id: changes
run: |
if [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ] && [ "$(git rev-list --count HEAD)" -gt 1 ]; then
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
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: echo "No changes detected, exiting pipeline" && 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 .
# 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//')
tag=$version
IFS='.' read -r major minor patch <<< "$version"
minor=$((minor + 1))
new_version="lambda_functions_v${major}.${minor}"
echo "New version is $new_version"
echo "new_version=$new_version" >> $GITHUB_ENV
# Cria um arquivo ZIP com os artefatos da pasta lambda_functions (se houver mudanças)
- name: Zip lambda_functions folder
if: ${{ env.has_changes == 'true' }}
run: |
cd lambda_functions
zip -r ../${{ env.new_version }}.zip .
# Verifica se a tag já existe
- name: Check if tag exists
id: tag_exists
run: |
if git rev-parse "refs/tags/${{ env.new_version }}" >/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.has_changes == 'true' && env.exists == 'false' }}
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.new_version }}
release_name: ${{ env.new_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
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ env.new_version }}.zip
asset_name: ${{ env.new_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 ${{ env.new_version }}.zip