Skip to content

Commit

Permalink
fix: ⚡ Ajustes no nome de script e atualizações de doc e versões
Browse files Browse the repository at this point in the history
- Finalizado instruções no README para replicação do projeto
- Atualização gitactions
- refatoração de código
  • Loading branch information
joaquimsn committed Jul 30, 2021
1 parent a311f67 commit 5ae93d8
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codacy-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

# Execute Codacy Analysis CLI and generate a SARIF output with the security issues identified during the analysis
- name: Run Codacy Analysis CLI
uses: codacy/codacy-analysis-cli-action@3.0.0
uses: codacy/codacy-analysis-cli-action@4.0.0
with:
# Check https://github.com/codacy/codacy-analysis-cli#project-token to get your project token from your Codacy repository
# You can also omit the token and run the tools that support default configurations
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/format-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
- uses: actions/setup-node@v2.1.5
- uses: actions/setup-node@v2.3.0
with:
node-version: '12.x'
- name: Install dependencies
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: Release
on:
push:
branches:
- master
branches: [master, main]
jobs:
release:
name: Release
Expand All @@ -13,7 +12,7 @@ jobs:
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v2.1.5
uses: actions/setup-node@v2.3.0
with:
node-version: 12
- name: Install dependencies
Expand Down
6 changes: 0 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ jobs:
run: npm run test
- name: Run coverage
run: npm run coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: unittests,integrationtest
name: codecov-nyc
- name: Upload coverage to Codacy
run: export CODACY_PROJECT_TOKEN=${{ secrets.CODACY_PROJECT_TOKEN }} && bash <(curl -Ls https://coverage.codacy.com/get.sh) report -r coverage/*
continue-on-error: true
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

{{Texto introdutorio}}

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

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

# Preparando o repositório
Crie seu projeto baseado nesse repositório.

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

(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]
## Variáveis de ambiente no github (secrets)
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].

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

## Renomeando arquivos
<img src="https://raw.githubusercontent.com/DP6/templates-centro-de-inovacoes/main/public/images/step-input-secret.png"/>

<img src="https://raw.githubusercontent.com/DP6/templates-centro-de-inovacoes/main/public/images/step-creat-secret-CODACY.png"/>

## Renomeando os arquivos

- Substituir o nome `template-js-cloudfunction-with-terraform` pelo nome do novo repositório criado no arquivo package.json
- 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.
Expand All @@ -68,7 +76,10 @@ WIP

## Entendendo o terraform

WIP
É recomendo a leitura da documentação oficial do (terraform para Google)[https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/getting_started]

<!-- Remover a parte introdutoria até esse comentário -->


## Entendendo os running do NPM

Expand Down Expand Up @@ -102,6 +113,7 @@ WIP
4. Variável [GOOGLE_APPLICATION_CREDENTIALS](https://cloud.google.com/docs/authentication/getting-started#setting_the_environment_variable)
5. Instalar o [Terraform](https://www.terraform.io/downloads.html)
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
7. *Importante* o usuário que executar o script do terraform precisa ter a permissão de owner no projeto do GCP.

_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**

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

```console
cd {{repo}}
sh terraform_deploy.sh
```

Expand Down
10 changes: 6 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const templateCf = async (req, res) => {
);

trace('RESULT VALID', result);
insertRowsAsStream(result);
insertRowsAsStream(result, projectConfig.BQ_SCHEMA_RAWDATA, projectConfig.BQ_TABLE_ID_RAWDATA);
res.status(200).send(debugging ? { debugging: debugging, result: result } : 'sucesso!');
}
};
Expand Down Expand Up @@ -81,11 +81,13 @@ function addTimestamp(data) {
/**
* Realiza a persistências dos dados por Stream no BigQuery
* @param {Array} data Dados estruturados no padrão de persistência do BQ
* @param {String} schema Schema da tabela do BQ
* @param {String} tableId Nome da tabela do BQ
*/
async function insertRowsAsStream(data) {
async function insertRowsAsStream(data, schema, tableId) {
const bigquery = new BigQuery();
const options = {
schema: projectConfig.BQ_SCHEMA_RAWDATA,
schema: schema,
skipInvalidRows: true,
ignoreUnknownValues: true,
};
Expand All @@ -94,7 +96,7 @@ async function insertRowsAsStream(data) {
// Insert data into a table
await bigquery
.dataset(projectConfig.BQ_DATASET_ID)
.table(projectConfig.BQ_TABLE_ID_RAWDATA)
.table(tableId)
.insert(data, options, insertHandler);

console.log(`Inserted ${data.length} rows`);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"lint-prettier": "npx prettier --check . || exit 0",
"lint": "npm run lint-md && npm run lint-prettier",
"unit-test": "mocha ./test/unit -timeout 8000",
"integration-test": "mocha ./test/integration --timeout=16000 --exit",
"integration-test": "mocha ./test/integration --timeout=20000 --exit",
"all-test": "npm run integration-test && npm run unit-test",
"test": "npm -- run all-test",
"coverage": "nyc --reporter=lcov --reporter=cobertura npm run unit-test",
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ variable "project_prefix" {
type = string
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"
validation {
condition = can(regex("[a-z0-9]", var.project_prefix)) && length(var.project_prefix) <= 4
error_message = "The prefix value must be a [a-z0-9] and size <= 4, exemple \"br01\"."
condition = can(regex("[a-z0-9]", var.project_prefix)) && length(var.project_prefix) <= 8
error_message = "The prefix value must be a [a-z0-9] and size <= 4, exemple \"br012020\"."
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/integration/request-http.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('Execução cloud function template', async () => {
// exec's 'timeout' param won't kill children of "shim" /bin/sh process
// Workaround: include "& sleep <TIMEOUT>; kill $!" in executed command
ffProc = execPromise(
`functions-framework --target=templateCf --signature-type=http --port ${PORT} & sleep 8; kill $!`,
`functions-framework --target=templateCf --signature-type=http --port ${PORT} & sleep 12; kill $!`,
{ shell: true, cwd }
);
});
Expand Down

0 comments on commit 5ae93d8

Please sign in to comment.