Skip to content

Commit 111a45d

Browse files
committed
Adicionando templates de CI para versão 3.14
related #454 related #453
1 parent c67c1f2 commit 111a45d

File tree

5 files changed

+98
-172
lines changed

5 files changed

+98
-172
lines changed

aulas/12.md

Lines changed: 45 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -57,52 +57,18 @@ Com o fluxograma em mente, nosso objetivo de aula é traduzir esses passos para
5757

5858
As configurações dos workflows no GitHub Actions são definidas em um arquivo [YAML](https://yaml.org/){:target="_blank"} localizado em um path especificado pelo github no repositório `.github/workflows/`. Dentro desse diretório podemos criar quantos workflows quisermos. Iniciaremos nossa configuração com um único arquivo que chamaremos de `pipeline.yaml`:
5959

60-
=== "Versão 3.11"
61-
```yaml title=".github/workflows/pipeline.yaml" linenums="1"
62-
name: Pipeline
63-
on: [push, pull_request]
64-
65-
jobs:
66-
test:
67-
runs-on: ubuntu-latest
68-
69-
steps:
70-
- name: Instalar o python
71-
uses: actions/setup-python@v6
72-
with:
73-
python-version: '3.11'
74-
```
75-
76-
=== "Versão 3.12"
77-
```yaml title=".github/workflows/pipeline.yaml" linenums="1"
78-
name: Pipeline
79-
on: [push, pull_request]
80-
81-
jobs:
82-
test:
83-
runs-on: ubuntu-latest
84-
85-
steps:
86-
- name: Instalar o python
87-
uses: actions/setup-python@v6
88-
with:
89-
python-version: '3.12'
90-
```
60+
=== "Versão 3.14"
61+
{%set short_version = 3.14 %}
62+
{% include "templates/ci_workflow.md" %}
9163
=== "Versão 3.13"
92-
```yaml title=".github/workflows/pipeline.yaml" linenums="1"
93-
name: Pipeline
94-
on: [push, pull_request]
95-
96-
jobs:
97-
test:
98-
runs-on: ubuntu-latest
99-
100-
steps:
101-
- name: Instalar o python
102-
uses: actions/setup-python@v6
103-
with:
104-
python-version: '3.13'
105-
```
64+
{%set short_version = 3.13 %}
65+
{% include "templates/ci_workflow.md" %}
66+
=== "Versão 3.12"
67+
{%set short_version = 3.12 %}
68+
{% include "templates/ci_workflow.md" %}
69+
=== "Versão 3.11"
70+
{%set short_version = 3.11 %}
71+
{% include "templates/ci_workflow.md" %}
10672

10773
Basicamente um arquivo de workflow precisa de três componentes essenciais para serem definidos:
10874

@@ -112,33 +78,20 @@ Basicamente um arquivo de workflow precisa de três componentes essenciais para
11278

11379
Nesse bloco de código definimos que toda vez em que um `push` ou um `pull_request` ocorrer no nosso repositório o `Pipeline` será executado. Esse workflow tem um job chamado `test` que roda na última versão do Ubuntu `runs-on: ubuntu-latest`. Nesse job chamado `test` temos uma lista de passos para serem executados, os `steps`.
11480

115-
O único step que definimos é a instalação do Python na versão "3.11":
81+
O único step que definimos é a instalação do Python:
11682

117-
=== "Versão 3.11"
118-
```yaml linenums="8"
119-
steps:
120-
- name: Instalar o python
121-
uses: actions/setup-python@v6
122-
with:
123-
python-version: '3.11'
124-
```
125-
126-
=== "Versão 3.12"
127-
```yaml linenums="8"
128-
steps:
129-
- name: Instalar o python
130-
uses: actions/setup-python@v6
131-
with:
132-
python-version: '3.12'
133-
```
83+
=== "Versão 3.14"
84+
{%set short_version = 3.14 %}
85+
{% include "templates/ci_setup_python.md" %}
13486
=== "Versão 3.13"
135-
```yaml linenums="8"
136-
steps:
137-
- name: Instalar o python
138-
uses: actions/setup-python@v6
139-
with:
140-
python-version: '3.13'
141-
```
87+
{%set short_version = 3.13 %}
88+
{% include "templates/ci_setup_python.md" %}
89+
=== "Versão 3.12"
90+
{%set short_version = 3.12 %}
91+
{% include "templates/ci_setup_python.md" %}
92+
=== "Versão 3.11"
93+
{%set short_version = 3.11 %}
94+
{% include "templates/ci_setup_python.md" %}
14295

14396
Nesse momento, se executarmos um commit do arquivo `.github/workflows/pipeline.yaml` e um push em nosso repositório, um workflow será iniciado.
14497

@@ -223,58 +176,18 @@ Cada um desses passos contribui para estabelecer um ambiente de CI robusto e con
223176

224177
Para isso, devemos criar um `step` para cada uma dessas ações no nosso job `test`. Desta:
225178

226-
=== "Versão 3.11"
227-
```yaml title=".github/workflows/pipeline.yaml" linenums="8"
228-
steps:
229-
- name: Instalar o python
230-
uses: actions/setup-python@v6
231-
with:
232-
python-version: '3.11'
233-
234-
- name: Instalar o poetry
235-
run: pipx install poetry
236-
237-
- name: Instalar dependências
238-
run: poetry install
239-
240-
- name: Executar testes
241-
run: poetry run task test
242-
```
243-
244-
=== "Versão 3.12"
245-
```yaml title=".github/workflows/pipeline.yaml" linenums="8"
246-
steps:
247-
- name: Instalar o python
248-
uses: actions/setup-python@v6
249-
with:
250-
python-version: '3.12'
251-
252-
- name: Instalar o poetry
253-
run: pipx install poetry
254-
255-
- name: Instalar dependências
256-
run: poetry install
257-
258-
- name: Executar testes
259-
run: poetry run task test
260-
```
179+
=== "Versão 3.14"
180+
{%set short_version = 3.14 %}
181+
{% include "templates/ci_steps.md" %}
261182
=== "Versão 3.13"
262-
```yaml title=".github/workflows/pipeline.yaml" linenums="8"
263-
steps:
264-
- name: Instalar o python
265-
uses: actions/setup-python@v6
266-
with:
267-
python-version: '3.13'
268-
269-
- name: Instalar o poetry
270-
run: pipx install poetry
271-
272-
- name: Instalar dependências
273-
run: poetry install
274-
275-
- name: Executar testes
276-
run: poetry run task test
277-
```
183+
{%set short_version = 3.13 %}
184+
{% include "templates/ci_steps.md" %}
185+
=== "Versão 3.12"
186+
{%set short_version = 3.12 %}
187+
{% include "templates/ci_steps.md" %}
188+
=== "Versão 3.11"
189+
{%set short_version = 3.11 %}
190+
{% include "templates/ci_steps.md" %}
278191

279192
Para testar essa implementação no Actions, temos que fazer um commit[^1], para executar o trigger do CI:
280193

@@ -294,58 +207,18 @@ Se analisarmos com calma o resultado, veremos que a execução do nosso workflow
294207

295208
Para solucionar esse problema, adicionaremos um passo antes da execução dos testes para copiar o código do nosso repositório para o ambiente do workflow. O GitHub Actions oferece uma ação específica para isso, chamada actions/checkout. Vamos incluí-la como o primeiro passo:
296209

297-
=== "Versão 3.11"
298-
```yaml title=".github/workflows/pipeline.yaml" linenums="4" hl_lines="6-7"
299-
jobs:
300-
test:
301-
runs-on: ubuntu-latest
302-
303-
steps:
304-
- name: Copia os arquivos do repositório
305-
uses: actions/checkout@v5
306-
307-
- name: Instalar o python
308-
uses: actions/setup-python@v6
309-
with:
310-
python-version: '3.11'
311-
312-
# continua com os passos anteriormente definidos
313-
```
314-
315-
=== "Versão 3.12"
316-
```yaml title=".github/workflows/pipeline.yaml" linenums="4" hl_lines="6-7"
317-
jobs:
318-
test:
319-
runs-on: ubuntu-latest
320-
321-
steps:
322-
- name: Copia os arquivos do repositório
323-
uses: actions/checkout@v5
324-
325-
- name: Instalar o python
326-
uses: actions/setup-python@v6
327-
with:
328-
python-version: '3.12'
329-
330-
# continua com os passos anteriormente definidos
331-
```
210+
=== "Versão 3.14"
211+
{%set short_version = 3.14 %}
212+
{% include "templates/ci_checkout.md" %}
332213
=== "Versão 3.13"
333-
```yaml title=".github/workflows/pipeline.yaml" linenums="4" hl_lines="6-7"
334-
jobs:
335-
test:
336-
runs-on: ubuntu-latest
337-
338-
steps:
339-
- name: Copia os arquivos do repositório
340-
uses: actions/checkout@v5
341-
342-
- name: Instalar o python
343-
uses: actions/setup-python@v6
344-
with:
345-
python-version: '3.13'
346-
347-
# continua com os passos anteriormente definidos
348-
```
214+
{%set short_version = 3.13 %}
215+
{% include "templates/ci_checkout.md" %}
216+
=== "Versão 3.12"
217+
{%set short_version = 3.12 %}
218+
{% include "templates/ci_checkout.md" %}
219+
=== "Versão 3.11"
220+
{%set short_version = 3.11 %}
221+
{% include "templates/ci_checkout.md" %}
349222

350223
Para testar a execução desse passo faremos um novo commit para triggar o Actions:
351224

aulas/templates/ci_checkout.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
```yaml title=".github/workflows/pipeline.yaml" linenums="4" hl_lines="6-7"
2+
jobs:
3+
test:
4+
runs-on: ubuntu-latest
5+
6+
steps:
7+
- name: Copia os arquivos do repositório
8+
uses: actions/checkout@v5
9+
10+
- name: Instalar o python
11+
uses: actions/setup-python@v6
12+
with:
13+
python-version: '{{short_version}}'
14+
15+
# continua com os passos anteriormente definidos
16+
```

aulas/templates/ci_setup_python.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```yaml linenums="8"
2+
steps:
3+
- name: Instalar o python
4+
uses: actions/setup-python@v6
5+
with:
6+
python-version: '{{short_version}}'
7+
```

aulas/templates/ci_steps.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
```yaml title=".github/workflows/pipeline.yaml" linenums="8"
2+
steps:
3+
- name: Instalar o python
4+
uses: actions/setup-python@v6
5+
with:
6+
python-version: '{{short_version}}'
7+
8+
- name: Instalar o poetry
9+
run: pipx install poetry
10+
11+
- name: Instalar dependências
12+
run: poetry install
13+
14+
- name: Executar testes
15+
run: poetry run task test
16+
```

aulas/templates/ci_workflow.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
```yaml title=".github/workflows/pipeline.yaml" linenums="1"
2+
name: Pipeline
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- name: Instalar o python
11+
uses: actions/setup-python@v6
12+
with:
13+
python-version: '{{short_version}}'
14+
```

0 commit comments

Comments
 (0)