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

Refactor: Typescript and Testing #1

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
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
62 changes: 62 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: CI

on:
push:
branches:
- main

pull_request:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set node
uses: actions/setup-node@v4
with:
node-version: lts/*

- name: Install
run: npm ci

- name: Lint
run: npm run lint

typecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set node
uses: actions/setup-node@v4
with:
node-version: lts/*

- name: Install
run: npm ci

- name: Typecheck
run: npm run typecheck

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set node
uses: actions/setup-node@v4
with:
node-version: lts/*

- name: Install
run: npm ci

- name: Build
run: npm run build

- name: Test
run: npm run test
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
.cache
.DS_Store
.idea
*.log
*.tgz
coverage
lib-cov
logs
node_modules
temp.json
temp
.pnpm-store
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore-workspace-root-check=true
shell-emulator=true
41 changes: 41 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
// Enable the ESlint flat config support
"eslint.useFlatConfig": true,

// Disable the default formatter, use eslint instead
"prettier.enable": false,
"editor.formatOnSave": false,

// Auto fix
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.organizeImports": "never"
},

// Silent the stylistic rules in you IDE, but still auto fix them
"eslint.rules.customizations": [
{ "rule": "style/*", "severity": "off" },
{ "rule": "*-indent", "severity": "off" },
{ "rule": "*-spacing", "severity": "off" },
{ "rule": "*-spaces", "severity": "off" },
{ "rule": "*-order", "severity": "off" },
{ "rule": "*-dangle", "severity": "off" },
{ "rule": "*-newline", "severity": "off" },
{ "rule": "*quotes", "severity": "off" },
{ "rule": "*semi", "severity": "off" }
],

// Enable eslint for all supported languages
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"vue",
"html",
"markdown",
"json",
"jsonc",
"yaml"
]
}
95 changes: 54 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

> Action in the illinois/autograding suite used for logging basic autograding run information.

`telemetry` is an action responsible for forwarding autograding run results to a remote server. `telemetry` provides basic information relating to run status, such as run time, workflow runner, points earned, and
`telemetry` is an action responsible for forwarding autograding run results to a remote server. `telemetry` provides basic information relating to run status, such as run time, workflow runner, points earned, and

## Usage:
## Usage

The following YAML snippet will grab the results from `illinois/autograding` and the send them via HTTP POST request to `http://arbitrary.remote.server:5000/` as JSON. Additionally, `telemetry` also generates an artifact logging all of the same information.

Expand All @@ -14,48 +14,61 @@ autograding:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout student repository
id: sr-checkout
uses: actions/checkout@v3
- name: Autograding
id: autograding
uses: illinois/autograding@v3
with:
path: mp1/
test_suite: autograding
step_summary: true
- name: Log telemetry data
if: ${{ always() }}
uses: illinois/telemetry@v1
with:
endpoint: "http://arbitrary.remote.server:5000/"
create_artifact: true
log_date: true
user: ${{ github.actor }}
autograding_status: ${{ steps.autograding.outcome }}
points: ${{ steps.autograding.outputs.Points }}
assignment: 'mp1-autograding'
- name: Checkout student repository
id: sr-checkout
uses: actions/checkout@v3
- name: Autograding
id: autograding
uses: illinois/autograding@v3
with:
path: mp1/
test_suite: autograding
step_summary: true
- name: Log telemetry data
if: ${{ always() }}
uses: illinois/telemetry@v1
with:
endpoint: 'http://arbitrary.remote.server:5000/'
create_artifact: true
log_date: true
assignment: mp1-autograding
upstream_repo: dsdiscovery/microprojects
```

Assuming `http://arbitrary.remote.server:5000/` is a route that allows POST requests, the server will receive the following JSON:
```js
Assuming `http://arbitrary.remote.server:5000/` is a route that allows POST requests, the server may receive the following JSON:

```json
{
date: "2023-04-21T15:23:47Z", // A UTC formatted timestamp
user: "jackskennel",
assignment: "mp1-autograding",
points: "40/40",
autograding_status: "success"
"assignment": "mp1-autograding",
"date": "2024-01-01T00:00:00.000Z",
"github_sha": "ffac537e6cbbf934b08745a378932722df287a53",
"meta": {},
"repo": "microprojects",
"token": "ghs_5oMEt0k3n",
"upstream_ref": "mp1-autograding",
"upstream_repo": "dsdiscovery/microprojects",
"username": "little_johnny",
"workflow_ref": "little_johnny/microprojects/.github/workflows/mp1-autograding-autograder-action.yml@refs/heads/my_branch",
"workflow_run_id": "1658821493"
}
```

## Parameters:

|Parameter|Required?|Description|Default|
|--------------------|--------|-----------|-------|
|`endpoint`|No|The URL to an HTTP endpoint to which this action will send telemetry data. Specifically, if `endpoint` is a valid endpoint, `telemetry` will send a POST request the endpoint containing JSON-formatted telemetry data in the request body. If this field is left blank, `create_artifact` must be set to `true`. Otherwise, this action will fail immediately.|`''`|
|`create_artifact`|No|Boolean describing if this workflow should produce an artifact containing telemetry data. The data will be saved as JSON, and will contain all the same data as what is sent to `endpoint`. The artifact will be named `telemetry`.|`false`|
|`log_date`|No|Boolean describing if `telemetry` should log the date and time of the workflow run.|`true`|
|`user`|No|Username of the user that triggered the workflow run. If this field is left empty, this information will not be logged.|`''`|
|`autograding_status`|No|`illinois/autograding`'s exit code. If this field is left blank, this information is not logged.|`''`|
|`points`|No|String containing the ratio of points earned to total points from the `autograding` action. If the `autograding` action has not been used in the same workflow as this action or if this action is used earlier than `autograding` in a workflow, this field should always be left to its default value.|`''`|
|`assignment`|No|The name of the assignment for which data is being logged. If empty, this field will not be entered.|`''`|
## Parameters

| Parameter | Required? | Description | Default |
| -------------------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- |
| `endpoint` | No | The URL to an HTTP endpoint to which this action will send telemetry data. Specifically, if `endpoint` is a valid endpoint, `telemetry` will send a POST request the endpoint containing JSON-formatted telemetry data in the request body. If this field is left blank, `create_artifact` must be set to `true`. Otherwise, this action will fail immediately. | `''` |
| `create_artifact` | No | Boolean describing if this workflow should produce an artifact containing telemetry data. The data will be saved as JSON, and will contain all the same data as what is sent to `endpoint`. The artifact will be named `telemetry`. | `false` |
| `token` | No | GitHub token used to check repository content and provide feedback. By default, this uses the repository token provided by GitHub Actions. You can customize this by replacing this token with a user token which has write-access to your repository. Note that the token will be accessible to all repository collaborators. | `${{ github.token }}` |
| `upstream_repo` | No | Upstream project repository name with owner. For example, dsdiscovery/microprojects. Fails the action if endpoint is specified but upstream_repo is not. | `false` |
| `upstream_ref` | No | The branch, tag or SHA of the upstream repo. Uses the default branch if unspecified, or the assignment name if it is specified. | `false` |
| `log_date` | No | Boolean describing if `telemetry` should log the date and time of the workflow run. | `true` |
| `autograding_status` | No | `illinois/autograding`'s exit code. If this field is left blank, this information is not logged. | `''` |
| `points` | No | String containing the ratio of points earned to total points from the `autograding` action. If the `autograding` action has not been used in the same workflow as this action or if this action is used earlier than `autograding` in a workflow, this field should always be left to its default value. | `''` |
| `assignment` | No | The name of the assignment for which data is being logged. If empty, this field will not be entered. | `''` |
| `meta` | No | Arbitrary metadata that gets passes directly to the telemetry endpoint, defaults to "{}". | `'{}'` |

## Acknowledgements

- 🏗 Built from [starter-ts](https://github.com/antfu/starter-ts) and [typescript-action](https://github.com/actions/typescript-action)
- ⚡️ Test using [Vitest](https://vitest.dev/)
57 changes: 23 additions & 34 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,39 @@
name: telemetry
description: "Save workflow run data to a remote endpoint or an artifact"
description: Save workflow run data to a remote endpoint or an artifact
inputs:
endpoint:
endpoint:
description: >
The URL to an HTTP endpoint to which this action will send telemetry data. Specifically,
if `endpoint` is a valid endpoint, `telemetry` will send a POST request the endpoint
containing JSON-formatted telemetry data in the request body. If this field is left blank,
`create_artifact` must be set to `true`. Otherwise, this action will fail immediately.
default: ''
required: false
create_artifact:
description: >
Boolean describing if this workflow should produce an artifact containing telemetry data.
The data will be saved as JSON, and will contain all the same data as what is sent to `endpoint`.
The artifact will be named `telemetry`.
default: false
required: false
log_date:
containing JSON-formatted telemetry data in the request body.
required: true
token:
description: >
Boolean describing if `telemetry` should log the date and time of the workflow run.
default: true
GitHub token used to check repository content and provide feedback. By default,
this uses the repository token provided by GitHub Actions. You can customize this
by replacing this token with a user token which has write-access to your repository.
Note that the token will be accessible to all repository collaborators.
default: ${{ github.token }}
required: false
user:
upstream_repo:
description: >
Username of the user that triggered the workflow run. If this field is left empty, this information
will not be logged.
default: ''
Upstream project repository name with owner. For example, dsdiscovery/microprojects.
Fails the action if endpoint is specified but upstream_repo is not.
required: false
autograding_status:
upstream_ref:
description: >
`autograding`'s exit code. If this field is left blank, this information is not logged.
default: null
required: false
points:
description: >
String containing the ratio of points earned to total points from the `autograding` action.
If the `autograding` action has not been used in the same workflow as this action or if this
action is used earlier than `autograding` in a workflow, this field should always be left
to its default value.
default: null
The branch, tag or SHA of the upstream repo. Uses the default branch if unspecified,
or the assignment name if it is specified.
required: false
assignment:
description: >
The name of the assignment for which data is being logged. If empty, this field will not be entered.
default: ''
required: false
meta:
description: >
Arbitrary metadata that gets passes directly to the telemetry endpoint, defaults to "{}".
default: '{}'
required: false
runs:
using: "node16"
main: "./dist/index.js"
using: node20
main: ./dist/index.js
Loading