generated from Green-Software-Foundation/if-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 09e160d
Showing
25 changed files
with
8,788 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
insert_final_newline = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
build/ | ||
dist/ | ||
src/**/**.d.ts | ||
src/**/**.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "./node_modules/gts/", | ||
"rules": { | ||
"@typescript-eslint/no-explicit-any": [ | ||
"off" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
name: Bug report | ||
about: Create a report to help us improve | ||
labels: 'bug' | ||
--- | ||
<!--- Please provide us the following info --> | ||
|
||
## Description of the Error | ||
<!--- Tell us what happened --> | ||
|
||
## Expected Behaviour | ||
<!--- Tell us what should happen --> | ||
|
||
## Actual Behaviour | ||
<!--- Tell us what happens instead of the expected behavior --> | ||
|
||
## Steps to Reproduce | ||
<!--- A set of specific instructions to reproduce the bug. Include code, if relevant --> | ||
|
||
|
||
## Link to online environment | ||
<!--- Please provide a link to Stackblitz or similar tool that allows us to reproduce your error in a preconfigured online environment --> | ||
|
||
<!--- If you provided a link to Stackblitz or similar, you can ignore the remaining fields. | ||
Otherwise, please provide the following information --> | ||
|
||
## Manifest File That Generated the Error | ||
|
||
<!--- Provide the manifest file that you ran that generated the error--> | ||
|
||
## Links to Any Additional Code | ||
<!--- E.g. your plugin code, it must be available online --> | ||
|
||
## Runtime Info | ||
<!--- Such as OS, node version, package.json, IF version --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
name: Feedback | ||
about: Submitting feedback on plugin template | ||
title: 'Feedback - ' | ||
labels: '' | ||
assignees: '' | ||
|
||
--- | ||
|
||
## Scope | ||
|
||
What does your feedback relate to? | ||
|
||
- [] Project aims/objectives | ||
- [] Repository structure | ||
- [] Documentation | ||
- [] Tests | ||
- [] Other | ||
|
||
## Details | ||
|
||
Does your feedback relate to a specific problem that can be demonstrated and reproduced? If so, please provide details of how to repro below. | ||
Include your platform config and the version of IEF you are using (e.g. Ubuntu 20.04, running latest dev branch on XX date). | ||
|
||
## Expected Behaviour | ||
|
||
What do things look like if they are going right? | ||
e.g. "the github issue board is cleared out every X days" | ||
|
||
## Actual behaviour | ||
|
||
How are things actually working? | ||
e.g. "issues are sitting on the board for over X days" | ||
|
||
## Proposed actions | ||
|
||
What fixes do you propose? | ||
e.g. "please define a response time of X days for issues and publish in the project README" | ||
|
||
|
||
**Note: We will take all feedback seriously. Please be polite and constructive - aggressive or abusive feedback will simply be deleted.** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
### Types of changes | ||
<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply. --> | ||
- [ ] Enhancement (project structure, spelling, grammar, formatting) | ||
- [ ] Bug fix (non-breaking change which fixes an issue) | ||
- [ ] New feature (non-breaking change which adds functionality) | ||
- [ ] Breaking change (fix or feature that would cause existing functionality to change) | ||
- [ ] My code follows the code style of this project. | ||
- [ ] My change requires a change to the documentation. | ||
- [ ] I have updated the documentation accordingly. | ||
- [ ] I have added tests to cover my changes. | ||
- [ ] All new and existing tests passed. | ||
|
||
|
||
### A description of the changes proposed in the Pull Request | ||
<!--- Provide a small description of the changes. --> | ||
- | ||
- | ||
|
||
|
||
<!-- Make sure tests and lint pass on CI. --> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Node.js CI | ||
|
||
on: push | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
cache: 'npm' | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Run lint | ||
run: npm run lint | ||
|
||
- name: Run tests | ||
run: npm run test --silent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
src/**/*.js | ||
src/**/*.d.ts | ||
lib/**/*.js | ||
lib/**/*.d.ts | ||
node_modules | ||
.idea | ||
*.tsbuildinfo | ||
dist | ||
yarn-error.log | ||
build | ||
coverage | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
npm run lint | ||
npm test | ||
npm run fix:package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
# Exclude typescript source and config | ||
*.ts | ||
tsconfig.json | ||
|
||
# Include javascript files and typescript declarations | ||
!*.js | ||
!*.d.ts | ||
|
||
# Exclude jsii outdir | ||
dist | ||
|
||
# Include .jsii and .jsii.gz | ||
!.jsii | ||
!.jsii.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
...require('gts/.prettierrc.json') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Green Software Foundation | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# if-plugin-template | ||
|
||
`if-plugin-template` is an environmental impact calculator template which exposes an API for [IF](https://github.com/Green-Software-Foundation/if) to retrieve energy and embodied carbon estimates. | ||
|
||
## Implementation | ||
|
||
Here can be implementation details of the plugin. For example which API is used, transformations and etc. | ||
|
||
## Usage | ||
|
||
To run the `<YOUR-CUSTOM-PLUGIN>`, an instance of `PluginInterface` must be created. Then, the plugin's `execute()` method can be called, passing required arguments to it. | ||
|
||
This is how you could run the model in Typescript: | ||
|
||
```typescript | ||
async function runPlugin() { | ||
const newModel = await new MyCustomPlugin().configure(params); | ||
const usage = await newModel.calculate([ | ||
{ | ||
timestamp: '2021-01-01T00:00:00Z', | ||
duration: '15s', | ||
'cpu-util': 34, | ||
}, | ||
{ | ||
timestamp: '2021-01-01T00:00:15Z', | ||
duration: '15s', | ||
'cpu-util': 12, | ||
}, | ||
]); | ||
|
||
console.log(usage); | ||
} | ||
|
||
runPlugin(); | ||
``` | ||
|
||
## Testing model integration | ||
|
||
### Using local links | ||
|
||
For using locally developed model in `IF Framework` please follow these steps: | ||
|
||
1. On the root level of a locally developed model run `npm link`, which will create global package. It uses `package.json` file's `name` field as a package name. Additionally name can be checked by running `npm ls -g --depth=0 --link=true`. | ||
2. Use the linked model in impl by specifying `name`, `method`, `path` in initialize models section. | ||
|
||
```yaml | ||
name: plugin-demo-link | ||
description: loads plugin | ||
tags: null | ||
initialize: | ||
plugins: | ||
my-custom-plugin: | ||
method: MyCustomPlugin | ||
path: "<name-field-from-package.json>" | ||
global-config: | ||
... | ||
... | ||
``` | ||
|
||
### Using directly from Github | ||
|
||
You can simply push your model to the public Github repository and pass the path to it in your impl. | ||
For example, for a model saved in `github.com/my-repo/my-model` you can do the following: | ||
|
||
npm install your model: | ||
|
||
``` | ||
npm install -g https://github.com/my-repo/my-model | ||
``` | ||
|
||
Then, in your `impl`, provide the path in the model instantiation. You also need to specify which class the model instantiates. In this case you are using the `PluginInterface`, so you can specify `OutputModel`. | ||
|
||
```yaml | ||
name: plugin-demo-git | ||
description: loads plugin | ||
tags: null | ||
initialize: | ||
plugins: | ||
my-custom-plugin: | ||
method: MyCustomPlugin | ||
path: https://github.com/my-repo/my-model | ||
global-config: | ||
... | ||
... | ||
``` | ||
|
||
Now, when you run the `manifest` using the IF CLI, it will load the model automatically. Run using: | ||
|
||
```sh | ||
ie --manifest <path-to-your-impl> --output <path-to-save-output> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
transform: { | ||
'^.+\\.ts?$': [ | ||
'ts-jest', | ||
{ | ||
tsconfig: 'tsconfig.json', | ||
}, | ||
], | ||
}, | ||
modulePathIgnorePatterns: ['./build'], | ||
}; |
Oops, something went wrong.