Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajout des pesonas #8

Merged
merged 18 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
root: true,
env: { node: true, commonjs: true, browser: true, es2020: true },
extends: "eslint:recommended",
ignorePatterns: ["dist", ".eslintrc.cjs"],
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
},
}
66 changes: 66 additions & 0 deletions .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Generates an artifact containing the result of the `yarn build` and `yarn test:personas` command.

name: Generate PR artifact

on:
pull_request:
types: [opened, synchronize]
push:
branches:
- "!master"

jobs:
build:
runs-on: ubuntu-latest
outputs:
test-personas-result: ${{ steps.test-personas.outputs.result }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
- uses: actions/setup-node@v3
with:
node-version: 18
cache: "yarn"
- run: yarn install --immutable
- run: git log | head && git status
- id: build
name: Build
run: yarn run build
- id: test-personas
name: Test the personas bilans against production
run: |
yarn test:personas --markdown > test-personas.res
body="$(cat test-personas.res | tail --lines=+3 | head --lines=-1)"
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo "::set-output name=result::${body}"

upload-artifact:
runs-on: ubuntu-22.04
needs: build
steps:
- name: Create artifact
run: |
mkdir -p artifacts
echo "
<h1 align="center">Report for the pull request #${{ github.event.pull_request.number }}</h2>

## :couple: Personas changes

### Test personas bilans against latest published version

<details open=true>
<summary>In details</summary>

${{ needs.build.outputs.test-personas-result }}

</details>

" > artifacts/result.md
- name: Upload artifact
uses: actions/upload-artifact@v1
with:
name: pr_message
path: artifacts
17 changes: 0 additions & 17 deletions .github/workflows/build.yaml

This file was deleted.

12 changes: 1 addition & 11 deletions .github/workflows/packaging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,10 @@ on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
check_if_version_upgraded:
name: Check if version upgrade
# When someone forks the repo and opens a PR we want to enables the tests to be run (the previous jobs)
# but obviously only us should be allowed to release.
# In the following check we make sure that we own the branch this CI workflow is running on before continuing.
# Without this check, trying to release would fail anyway because only us have the correct secret.NPM_TOKEN but
# it's cleaner to stop the execution instead of letting the CI crash.
if: |
github.event_name == 'push' ||
github.event.pull_request.head.repo.owner.login == github.event.pull_request.base.repo.owner.login
runs-on: ubuntu-latest
outputs:
from_version: ${{ steps.step1.outputs.from_version }}
Expand Down
74 changes: 74 additions & 0 deletions .github/workflows/pr-updater.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# This CI is triggered each time a workflow named "Generate PR artifact" is
# completed. It retrieves the artifact containing the result of the `yarn
# compile` command, and update/create a new comment on the corresponding PR.

name: Update PR comments

on:
workflow_run:
workflows: ['Generate PR artifact']
types: [completed]

jobs:
pr_comment:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/[email protected]

- name: Downloading Artifacts from Previous Workflow...
uses: synergy-au/download-workflow-artifacts-action@v1
with:
auth-token: ${{ secrets.GITHUB_TOKEN }}
workflow-run-id: ${{ github.event.workflow_run.id }}

- name: Updating the PR
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');

const {owner, repo} = context.repo;
const run_id = context.payload.workflow_run.id;
core.info('Triggered workflow run:', run_id);

const pull_requests = await github.rest.pulls.list(context.repo);
if (!pull_requests.data.length) {
return core.error("Currently, there is no open PR.");
}
core.info('Found ' + pull_requests.data.length + ' PR');

var triggered_pr;
for (const pr of pull_requests.data) {
if (pr.head.sha == context.payload.workflow_run.head_sha) {
triggered_pr = pr;
}
}
if (!triggered_pr) {
return core.error('The corresponding RP could not be found.');

}
core.info('Found the corresponding PR: #' + triggered_pr.number);

const marker = 'yarn-compile-result';

if (!fs.existsSync('result.md')) {
return core.info("Can not found 'result.md', skipping")
}
var body = '<!-- bot: ' + marker + ' -->\n' + fs.readFileSync('result.md', 'utf8');

const issue_number = triggered_pr.number;
const comments = await github.rest.issues.listComments({owner, repo, issue_number});
const existing = comments.data.filter((c) => c.body.includes(marker));
if (existing.length > 0) {
const last = existing[existing.length - 1];
core.info('Updating the comment ' + last.id);
await github.rest.issues.updateComment({
owner, repo,
body,
comment_id: last.id,
});
} else {
core.info('Creating a comment in the PR #' + issue_number);
await github.rest.issues.createComment({issue_number, body, owner, repo});
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
node_modules
.yarn
publicodes-evenements.model.json
publicodes-evenements.personas.json
index.d.ts
index.js
.DS_Store
39 changes: 29 additions & 10 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { writeFileSync } from "fs"
import { getModelFromSource } from "@publicodes/tools/compilation"
import Engine from "publicodes"
import getUI from "./scripts/compile-ui.js"
import getPersonas from "./scripts/compile-personas.js"

const srcFiles = "rules/**/*.publicodes"
const destPath = "publicodes-evenements.model.json"
const modelDestPath = "publicodes-evenements.model.json"
const personasDestPath = "publicodes-evenements.personas.json"

const model = getModelFromSource(srcFiles, { verbose: true })

Expand All @@ -16,20 +18,29 @@ try {
process.exit(-1)
}

const ui = getUI(model)
writeFileSync(modelDestPath, JSON.stringify(model, null, 2))
console.log(`✅ ${modelDestPath} generated`)

const personas = getPersonas(model)

writeFileSync(destPath, JSON.stringify(model, null, 2))
console.log(`✅ ${destPath} generated`)
writeFileSync(personasDestPath, JSON.stringify(personas, null, 2))
console.log(`✅ ${personasDestPath} generated`)

const ui = getUI(model)

writeFileSync(
"index.js",
`
import rules from "./${destPath}" assert { type: "json" };
import rules from "./${modelDestPath}" assert { type: "json" };

import personas from "./${personasDestPath}" assert { type: "json" };

export const ui = ${JSON.stringify(ui, null, 2)};

export { personas };

export default rules;
`,
`
)
console.log(`✅ index.js generated`)

Expand All @@ -39,17 +50,25 @@ let indexDTypes = Object.keys(model).reduce(
import { Rule } from "publicodes";

export type DottedName =
`,
`
)

indexDTypes += `

declare let personas: {
[key: string]: {
titre: string;
description: string;
situation: Situation;
}
}

declare let ui: {
categories: Record<RuleName, {index: number, sub: RuleName[]}>;
questions: Record<RuleName, RuleName[][]>;
categories: Record<RuleName, {index: number, sub: RuleName[]}>;
questions: Record<RuleName, RuleName[][]>;
}

export { ui }
export { ui, personas }

declare let rules: Record<DottedName, Rule>

Expand Down
50 changes: 50 additions & 0 deletions emptySituation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
alimentation . repas . proposition . mixte végé viande . proportion végétarien:
alimentation . repas . proposition . choix viande:
alimentation . repas . proposition:
alimentation . petits déjeuners présent:
alimentation . ecocups présent:
alimentation . ecocups . réutilisation:
alimentation . déchets . recyclage:
alimentation . déchets . gobelets . type:
alimentation . déchets . couverts . type:
alimentation . déchets . assiettes . type:
alimentation . boissons . froide . soft . quantité par jour et par personne:
alimentation . boissons . froide . eau en bouteille bénévoles présent:
alimentation . boissons . froide . alcool . quantité par jour et par personne:
alimentation . boissons . chaude . thé . quantité par jour et par personne:
alimentation . boissons . chaude . café . quantité par jour et par personne:
alimentation . artistes . repas . type:
alimentation . artistes . eau en bouteille présent:
communication . textile bénévoles . type:
communication . textile bénévoles . réutilisation:
communication . merchandising . panier moyen par jour et par personne:
hébergement . public présent:
hébergement . public . part:
hébergement . bénévoles . type:
hébergement . artistes présent:
informations . nombre de jours:
informations . nombre de festivaliers:
informations . nombre de bénévoles:
informations . nombre artistes en voiture:
informations . nombre artistes en train:
informations . nombre artistes en tour bus:
informations . nombre artistes en avion:
infrastructures . scénographie . matériel . dépenses:
infrastructures . scénographie . nombre petites scènes:
infrastructures . scénographie . nombre grandes scènes:
transport . public . voiture . part:
transport . public . train . part:
transport . public . distance AR:
transport . public . commun . part:
transport . public . avion . part:
transport . public . accessible en transports en commun:
transport . artistes . voiture . distance:
transport . artistes . train . distance:
transport . artistes . tour bus . distance:
transport . artistes . avion . distance:
énergie . électricité . consommation:
énergie . groupes électrogènes présent:
énergie . groupes électrogènes . nombre:
énergie . autre présent:
énergie . autre . gaz . consommation:
énergie . autre . fioul . consommation:
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "publicodes-evenements",
"version": "0.5.4",
"version": "0.6.0",
"repository": {
"type": "git",
"url": "git+ssh://[email protected]/Ecofest/publicodes-evenements.git"
Expand All @@ -11,8 +11,12 @@
"@incubateur-ademe/nosgestesclimat": "^2.0.0",
"@incubateur-ademe/publicodes-commun": "^1.1.1",
"@publicodes/tools": "^1.0.6",
"ansi-colors": "^4.1.3",
"eslint": "^8.57.0",
"publicodes": "^1.1.1",
"yaml": "^2.4.1"
"publicodes-evenements": "^0.6.0-rc.2",
"yaml": "^2.4.1",
"yargs": "^17.7.2"
},
"authors": [
"Clément Auger <[email protected]>",
Expand All @@ -24,6 +28,7 @@
"description": "",
"files": [
"publicodes-evenements.model.json",
"publicodes-evenements.personas.json",
"index.js",
"index.d.ts"
],
Expand All @@ -32,6 +37,7 @@
"scripts": {
"clean": "rm -r publicodes-evenements.model.json index.d.ts index.js",
"build": "node build.js",
"test:personas": "node tests/testPersonas.js",
"build:watch": "nodemon -e \"publicodes\" --watch rules/ build.js & nodemon --watch publicodes-evenements.model.json copy.js",
"doc:start": "node build && cp publicodes-evenements.model.json doc/src && cd doc && yarn run start",
"doc:build": "node build && cp publicodes-evenements.model.json doc/src && cd doc && yarn run build"
Expand Down
Loading
Loading