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

dashboard: small enhancements #20

Merged
merged 1 commit into from
Nov 22, 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: 9 additions & 1 deletion .github/workflows/deploy.yml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some context on the changes in this file:

This allows for us to have a staging instance by hosting in another repo without constantly modifying the code

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

env:
NEXT_PUBLIC_BASE_PATH: ${{ vars.NEXT_PUBLIC_BASE_PATH }}
afinn12 marked this conversation as resolved.
Show resolved Hide resolved

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
Expand Down Expand Up @@ -76,9 +79,14 @@ jobs:
- name: Install dependencies
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}

- name: Build with Next.js
- name: Build with Next.js (No base path)
if: ${{ env.NEXT_PUBLIC_BASE_PATH == '' }}
run: ${{ steps.detect-package-manager.outputs.runner }} next build

- name: Build with Next.js (With base path)
if: ${{ env.NEXT_PUBLIC_BASE_PATH != '' }}
run: NEXT_PUBLIC_BASE_PATH=${{ env.NEXT_PUBLIC_BASE_PATH }} ${{ steps.detect-package-manager.outputs.runner }} next build
Comment on lines +82 to +88
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need a condition here. I'll fix this in another PR.


- name: Add .nojekyll to out directory
run: touch out/.nojekyll

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/fetch-ci-nightly-data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Update dashboard data
env:
TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Use bash to fail fast:
# https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsshell
shell: bash
Expand Down
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local
# env files
.env*

# vercel
.vercel
Expand All @@ -36,4 +36,5 @@ yarn-error.log*
*.tsbuildinfo
next-env.d.ts

/job_stats.json
# local dev data
/localData/
29 changes: 20 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,21 @@ Follow these steps to set up the development environment for the Kata Containers

3. **Run the development server**:
Start the Next.js development server with hot-reloading enabled.

To run the script to fetch the data, a .env file must be created with an access token. This is required to authenticate our calls and increase the rate limit. To get the token, click [here](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens)

Create the .env file:
```bash
node scripts/fetch-ci-nightly-data.js > job_stats.json
npm run dev
NODE_ENV=development
TOKEN=<GITHUB_PAT_OR_OTHER_VALID_TOKEN>
```

Create the folder /localData. Then, run:

```bash
node scripts/fetch-ci-nightly-data.js > localData/job_stats.json
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do this in another PR.

Suggested change
node scripts/fetch-ci-nightly-data.js > localData/job_stats.json
node --require dotenv/config scripts/fetch-ci-nightly-data.js > localData/job_stats.json

npm run dev # On Windows, run `npm run win-dev` instead.
```
The app will be available at [http://localhost:3000](http://localhost:3000).

### Production
Expand All @@ -92,10 +102,11 @@ Follow these steps to set up the development environment for the Kata Containers
npm start
```

### Scripts

- **Fetch CI Nightly Data**:
The `fetch-ci-nightly-data.js` script can be executed manually to pull the latest CI test data from the Kata Containers repository:
```bash
node scripts/fetch-ci-nightly-data.js > job_stats.json
```
### Notes
In deploy.yml:
```bash
env:
NEXT_PUBLIC_BASE_PATH: ${{ vars.NEXT_PUBLIC_BASE_PATH }}
```
If the variable is undefined, it will use "" for the basePath and assume the site is being served at root.
This makes it easier for people to fork the repo and deploy with GitHub pages such that they can have a preview for their PR.
13 changes: 3 additions & 10 deletions components/weatherTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,28 @@ const icons = [

export const getWeatherIndex = (stat) => {
let fail_rate = 0;
fail_rate = (stat["fails"] + stat["skips"]) / stat["runs"];
fail_rate = (stat["fails"]) / stat["runs"];
// e.g. failing 3/9 runs is .33, or idx=1
var idx = Math.floor((fail_rate * 10) / 2);
if (idx == icons.length) {
// edge case: if 100% failures, then we go past the end of icons[]
// back the idx down by 1
console.assert(fail_rate == 1.0);
idx -= 1;
}

// This error checks if there are zero runs.
// Currently, will display stormy weather.
if (isNaN(idx)) {
if (isNaN(idx) || idx > icons.length) {
idx = 4;
}
return idx;
};

const getWeatherIcon = (stat) => {
const idx = getWeatherIndex(stat);
return icons[idx];
};

export const weatherTemplate = (data) => {
const icon = getWeatherIcon(data);
return (
<div>
<Image
src={`${basePath}/${icon}`}
src={`${basePath}/${icons[getWeatherIndex(data)]}`}
alt="weather"
width={32}
height={32}
Expand Down
2 changes: 1 addition & 1 deletion next.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
reactStrictMode: true,
output: 'export',
basePath: "",
basePath: process.env.NEXT_PUBLIC_BASE_PATH || "",
images: {
unoptimized: true,
},
Expand Down
Loading
Loading