Skip to content

Commit 5ae93d8

Browse files
committed
fix: ⚡ Ajustes no nome de script e atualizações de doc e versões
- Finalizado instruções no README para replicação do projeto - Atualização gitactions - refatoração de código
1 parent a311f67 commit 5ae93d8

File tree

10 files changed

+31
-23
lines changed

10 files changed

+31
-23
lines changed

.github/workflows/codacy-analysis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121

2222
# Execute Codacy Analysis CLI and generate a SARIF output with the security issues identified during the analysis
2323
- name: Run Codacy Analysis CLI
24-
uses: codacy/codacy-analysis-cli-action@3.0.0
24+
uses: codacy/codacy-analysis-cli-action@4.0.0
2525
with:
2626
# Check https://github.com/codacy/codacy-analysis-cli#project-token to get your project token from your Codacy repository
2727
# You can also omit the token and run the tools that support default configurations

.github/workflows/format-lint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
- uses: actions/checkout@v2
99
with:
1010
ref: ${{ github.head_ref }}
11-
- uses: actions/setup-node@v2.1.5
11+
- uses: actions/setup-node@v2.3.0
1212
with:
1313
node-version: '12.x'
1414
- name: Install dependencies

.github/workflows/release.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
name: Release
22
on:
33
push:
4-
branches:
5-
- master
4+
branches: [master, main]
65
jobs:
76
release:
87
name: Release
@@ -13,7 +12,7 @@ jobs:
1312
with:
1413
fetch-depth: 0
1514
- name: Setup Node.js
16-
uses: actions/setup-node@v2.1.5
15+
uses: actions/setup-node@v2.3.0
1716
with:
1817
node-version: 12
1918
- name: Install dependencies

.github/workflows/test.yml

-6
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ jobs:
1515
run: npm run test
1616
- name: Run coverage
1717
run: npm run coverage
18-
- name: Upload coverage to Codecov
19-
uses: codecov/codecov-action@v1
20-
with:
21-
token: ${{ secrets.CODECOV_TOKEN }}
22-
flags: unittests,integrationtest
23-
name: codecov-nyc
2418
- name: Upload coverage to Codacy
2519
run: export CODACY_PROJECT_TOKEN=${{ secrets.CODACY_PROJECT_TOKEN }} && bash <(curl -Ls https://coverage.codacy.com/get.sh) report -r coverage/*
2620
continue-on-error: true

README.md

+17-4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
{{Texto introdutorio}}
4040

41+
<!-- Remover essa parte a partir desse comentário -->
4142
Respositório template para CF utilizando
4243

4344
- Deploy com terraform de (Arquivos para GCS, Tabelas BQ e CF)
@@ -52,14 +53,21 @@ Respositório template para CF utilizando
5253
- Github pages com template do github.dp6.io
5354

5455
# Preparando o repositório
56+
Crie seu projeto baseado nesse repositório.
5557

56-
WIP
58+
<img src="https://raw.githubusercontent.com/DP6/templates-centro-de-inovacoes/main/public/images/create-new-reposotory-from-template.png"/>
5759

60+
(Passo a passo github)[https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-repository-on-github/creating-a-repository-from-a-template]
5861
## Variáveis de ambiente no github (secrets)
62+
Primeiro é necessário conectar o repositório do Github com o (coday.com)[https://app.codacy.com/organizations/gh/DP6/repositories] (referência para conexão)[https://docs.codacy.com/organizations/managing-repositories/#adding-a-repository].
5963

60-
WIP
64+
Necessário criar a screte CODACY_PROJECT_TOKEN nas configurações do seu repositório no Github em Settings > Secret > New repository Secret
6165

62-
## Renomeando arquivos
66+
<img src="https://raw.githubusercontent.com/DP6/templates-centro-de-inovacoes/main/public/images/step-input-secret.png"/>
67+
68+
<img src="https://raw.githubusercontent.com/DP6/templates-centro-de-inovacoes/main/public/images/step-creat-secret-CODACY.png"/>
69+
70+
## Renomeando os arquivos
6371

6472
- Substituir o nome `template-js-cloudfunction-with-terraform` pelo nome do novo repositório criado no arquivo package.json
6573
- Substituir a chave `{{nome_projeto}}` no arquivo `_config.yml` com o nome do projeto em linguagem natural, para ser usado como titulo da página no site.
@@ -68,7 +76,10 @@ WIP
6876

6977
## Entendendo o terraform
7078

71-
WIP
79+
É recomendo a leitura da documentação oficial do (terraform para Google)[https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/getting_started]
80+
81+
<!-- Remover a parte introdutoria até esse comentário -->
82+
7283

7384
## Entendendo os running do NPM
7485

@@ -102,6 +113,7 @@ WIP
102113
4. Variável [GOOGLE_APPLICATION_CREDENTIALS](https://cloud.google.com/docs/authentication/getting-started#setting_the_environment_variable)
103114
5. Instalar o [Terraform](https://www.terraform.io/downloads.html)
104115
6. Habilitar os produtos no GCP Cloud Function, BigQuery, Cloud Build API, Cloud Resource Manager API, BigQuery Data Transfer API e Cloud Storage, para uso do BigQuery é necessário ter um billing ativo
116+
7. *Importante* o usuário que executar o script do terraform precisa ter a permissão de owner no projeto do GCP.
105117

106118
_Observação:_ Utilizando o ambiente no [Google Cloud Shell](https://cloud.google.com/shell/docs) não é necessário fazer os **1**, **2**, **4** e **5**
107119

@@ -116,6 +128,7 @@ git clone https://github.com/DP6/{{repo}}.git
116128
Para fazer deploy no GCP usando o Terraform, o utilize o shell script terraform_deploy
117129

118130
```console
131+
cd {{repo}}
119132
sh terraform_deploy.sh
120133
```
121134

index.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const templateCf = async (req, res) => {
4242
);
4343

4444
trace('RESULT VALID', result);
45-
insertRowsAsStream(result);
45+
insertRowsAsStream(result, projectConfig.BQ_SCHEMA_RAWDATA, projectConfig.BQ_TABLE_ID_RAWDATA);
4646
res.status(200).send(debugging ? { debugging: debugging, result: result } : 'sucesso!');
4747
}
4848
};
@@ -81,11 +81,13 @@ function addTimestamp(data) {
8181
/**
8282
* Realiza a persistências dos dados por Stream no BigQuery
8383
* @param {Array} data Dados estruturados no padrão de persistência do BQ
84+
* @param {String} schema Schema da tabela do BQ
85+
* @param {String} tableId Nome da tabela do BQ
8486
*/
85-
async function insertRowsAsStream(data) {
87+
async function insertRowsAsStream(data, schema, tableId) {
8688
const bigquery = new BigQuery();
8789
const options = {
88-
schema: projectConfig.BQ_SCHEMA_RAWDATA,
90+
schema: schema,
8991
skipInvalidRows: true,
9092
ignoreUnknownValues: true,
9193
};
@@ -94,7 +96,7 @@ async function insertRowsAsStream(data) {
9496
// Insert data into a table
9597
await bigquery
9698
.dataset(projectConfig.BQ_DATASET_ID)
97-
.table(projectConfig.BQ_TABLE_ID_RAWDATA)
99+
.table(tableId)
98100
.insert(data, options, insertHandler);
99101

100102
console.log(`Inserted ${data.length} rows`);

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"lint-prettier": "npx prettier --check . || exit 0",
1515
"lint": "npm run lint-md && npm run lint-prettier",
1616
"unit-test": "mocha ./test/unit -timeout 8000",
17-
"integration-test": "mocha ./test/integration --timeout=16000 --exit",
17+
"integration-test": "mocha ./test/integration --timeout=20000 --exit",
1818
"all-test": "npm run integration-test && npm run unit-test",
1919
"test": "npm -- run all-test",
2020
"coverage": "nyc --reporter=lcov --reporter=cobertura npm run unit-test",

terraform/variables.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ variable "project_prefix" {
2626
type = string
2727
description = "Pré-fixo que será utilizado para nomear os produtos que serão utilizados e criados no GCP, exemplo para o cliente Brasil podemos usar o pré-fixo br"
2828
validation {
29-
condition = can(regex("[a-z0-9]", var.project_prefix)) && length(var.project_prefix) <= 4
30-
error_message = "The prefix value must be a [a-z0-9] and size <= 4, exemple \"br01\"."
29+
condition = can(regex("[a-z0-9]", var.project_prefix)) && length(var.project_prefix) <= 8
30+
error_message = "The prefix value must be a [a-z0-9] and size <= 4, exemple \"br012020\"."
3131
}
3232
}
3333

test/integration/request-http.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('Execução cloud function template', async () => {
1818
// exec's 'timeout' param won't kill children of "shim" /bin/sh process
1919
// Workaround: include "& sleep <TIMEOUT>; kill $!" in executed command
2020
ffProc = execPromise(
21-
`functions-framework --target=templateCf --signature-type=http --port ${PORT} & sleep 8; kill $!`,
21+
`functions-framework --target=templateCf --signature-type=http --port ${PORT} & sleep 12; kill $!`,
2222
{ shell: true, cwd }
2323
);
2424
});

0 commit comments

Comments
 (0)