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

Updated CI/CD Tests #405

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
78 changes: 59 additions & 19 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,68 @@
name: Deployment

on:
# Uncomment once we are ready to deploy
#push:
# branches:
# - main
workflow_dispatch:
# Uncomment once we are ready to deploy
push:
branches:
- main
pull_request:
Copy link
Contributor

Choose a reason for hiding this comment

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

What would be the motivation for running this on every pull request rather than on pushes to main?
Wouldn't this just be testing the configuration of the main branch and not the changes being introduced?
If we want to keep it as being triggered by pull requests can we only trigger it when files in src/website and .devcontainer are modified?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From my understanding, running this on every PR would ensure that changes in the PR would not break the deployment before they are merged into the main branch, which would also provide another layer of testing to catch issues early. What do you think?

Also, good point. If we do want to keep it as being triggered by PR's, then it should only trigger when files in src/website and .devcontainer are modified. I will fix that

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah sounds like a great idea to test out how changes deploy before actually deploying to the real site.

The main branch will be checked out on the VM, and not the development branch
I'm sorry that's totally wrong ^

Would the VM that this workflow deploys to be like a pre-production environment and not the actual web host?

If so, then I think keeping it as triggered by PRs makes sense, and maybe we can keep the push trigger as well and deploy to either the pre-production VM or the actual website host VM depending on the trigger event.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Your idea sounds great, since the VM that the workflow deploys will not be the actual web host.

branches:
- main
paths:
- 'src/website/**'
- '.devcontainer/**'

jobs:
deploy-web:
runs-on: ubuntu-latest
steps:
- name: Checkout workspace
uses: actions/checkout@v4
- name: Update docker image
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
script: |
[ ! -d "sailbot_workspace" ] && git clone https://github.com/UBCSailbot/sailbot_workspace.git
cd sailbot_workspace
git pull
touch src/website/.env.local # Adds a local environment file to VM to override env vars in .env.production
echo NEXT_PUBLIC_SERVER_HOST=http://${{ secrets.SSH_HOST }} >> src/website/.env.local
docker compose -f .devcontainer/docker-compose.yml -f .devcontainer/website/docker-compose.website.prod.yml up --force-recreate -d --build --remove-orphans
- name: Checkout workspace
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_TOKEN }}

- name: Debug - List directory structure
run: |
ls -R

- name: Install dependencies and run lint checks
run: |
cd src/website
npm ci
npm run lint

- name: Build website
run: |
cd src/website
npm run build

- name: Update docker image for pre-production
if: github.event_name == 'pull_request'
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
script: |
[ ! -d "sailbot_workspace" ] && git clone https://github.com/UBCSailbot/sailbot_workspace.git
cd sailbot_workspace
git pull
touch src/website/.env.local # Adds a local environment file to VM to override env vars in .env.production
echo NEXT_PUBLIC_SERVER_HOST=http://${{ secrets.SSH_HOST }} >> src/website/.env.local
docker compose -f .devcontainer/docker-compose.yml -f .devcontainer/website/docker-compose.website.prod.yml up --force-recreate -d --build --remove-orphans

- name: Update docker image for production
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
script: |
[ ! -d "sailbot_workspace" ] && git clone https://github.com/UBCSailbot/sailbot_workspace.git
cd sailbot_workspace
git pull
touch src/website/.env.local # Adds a local environment file to VM to override env vars in .env.production
echo NEXT_PUBLIC_SERVER_HOST=http://${{ secrets.SSH_HOST }} >> src/website/.env.local
docker compose -f .devcontainer/docker-compose.yml -f .devcontainer/website/docker-compose.website.prod.yml up --force-recreate -d --build --remove-orphans
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see a verification that docker is installed on the VM prior to deploying to it. Which is fine, just wanted to clarify as you mentioned it resolved that issue

2 changes: 1 addition & 1 deletion src/website/lib/dotenv.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ module.exports = () => {
};
};

export {}
export {};
2 changes: 1 addition & 1 deletion src/website/lib/redux/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ const middleware: Redux.Middleware[] = [
},
predicate: () => typeof window !== 'undefined',
}),
]
];

export { middleware };
2 changes: 1 addition & 1 deletion src/website/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CircularProgress, Modal } from '@mui/material';
import Header from '@/views/components/Header/Header';
import styles from './style.module.css';
import PolarisContainer from '@/views/components/Polaris/PolarisContainer';
import { clearLogsPeriodically } from '@/lib/redux/logUtils'
import { clearLogsPeriodically } from '@/lib/redux/logUtils';

const MapsContainer = dynamic(() => import('@/views/MapsContainer'), {
loading: () => <CircularProgress className={styles.loadingSpinner} />,
Expand Down
7 changes: 5 additions & 2 deletions src/website/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
"hooks/useSessionState.js"
, "lib/dotenv.js", "models/helper/parser.js", "utils/DownloadData.js" ],
"hooks/useSessionState.js",
"lib/dotenv.js",
"models/helper/parser.js",
"utils/DownloadData.js"
],
"exclude": ["node_modules"]
}
10 changes: 7 additions & 3 deletions src/website/views/DashboardContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { connect } from 'react-redux';
import UPlotLineChartComponent from './components/LineChart/UPlotLineChart';
import { GPS, GPSState } from '@/stores/GPS/GPSTypes';
import { Batteries, BatteriesState } from '@/stores/Batteries/BatteriesTypes';
import { WindSensor, WindSensors, WindSensorsState } from '@/stores/WindSensors/WindSensorsTypes';
import {
WindSensor,
WindSensors,
WindSensorsState,
} from '@/stores/WindSensors/WindSensorsTypes';
import { DataFilterState } from '@/stores/DataFilter/DataFilterTypes';
import UPlotMultiLineChartComponent from './components/LineChart/UPlotMultiLineChart';

Expand Down Expand Up @@ -219,10 +223,10 @@ class DashboardContainer extends React.PureComponent<DashboardContainerProps> {

if (
timestampISO >=
// @ts-ignore
// @ts-ignore
this._parseISOString(this.props.dataFilter.timestamps.startDate) &&
timestampISO <=
// @ts-ignore
// @ts-ignore
this._parseISOString(this.props.dataFilter.timestamps.endDate)
) {
return true;
Expand Down
6 changes: 3 additions & 3 deletions src/website/views/MapsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ class MapsContainer extends React.PureComponent<MapsContainerProps> {

if (
timestampISO >=
// @ts-ignore
// @ts-ignore
this._parseISOString(this.props.dataFilter.timestamps.startDate) &&
timestampISO <=
// @ts-ignore
// @ts-ignore
this._parseISOString(this.props.dataFilter.timestamps.endDate)
) {
return true;
Expand Down Expand Up @@ -125,7 +125,7 @@ class MapsContainer extends React.PureComponent<MapsContainerProps> {
longitude: 999,
speed: 999,
heading: 999,
timestamp: new Date().toISOString()
timestamp: new Date().toISOString(),
};
}
return gpsdata.at(-1);
Expand Down
7 changes: 6 additions & 1 deletion src/website/views/components/DropDown/DropdownMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ interface SortableGraphProps {
setOrder: any;
}

const SortableGraph = ({ id, children, order, setOrder }: SortableGraphProps) => {
const SortableGraph = ({
id,
children,
order,
setOrder,
}: SortableGraphProps) => {
const { attributes, listeners, setNodeRef, transform, transition } =
useSortable({
id,
Expand Down
14 changes: 12 additions & 2 deletions src/website/views/components/LineChart/UPlotLineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ export default class UPlotLineChartComponent extends React.Component<
show: true,
spanGaps: false,
label: 'Time',
value: (self: any, rawValue: any, xValuesIndex: any, currentVal: any) => {
value: (
self: any,
rawValue: any,
xValuesIndex: any,
currentVal: any,
) => {
if (currentVal == null) {
let xValues = self.data[xValuesIndex];
let xValue = fmtDate(tzDate(xValues[xValues.length - 1]));
Expand All @@ -52,7 +57,12 @@ export default class UPlotLineChartComponent extends React.Component<
show: true,
spanGaps: false,
label: this.props.label,
value: (self: any, rawValue: any, yValuesIndex: any, currentVal: any) => {
value: (
self: any,
rawValue: any,
yValuesIndex: any,
currentVal: any,
) => {
if (currentVal == null) {
let yValues = self.data[yValuesIndex];
let yValue = yValues[yValues.length - 1]?.toFixed(2);
Expand Down
21 changes: 18 additions & 3 deletions src/website/views/components/LineChart/UPlotMultiLineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ export default class UPlotMultiLineChartComponent extends React.Component<
show: true,
spanGaps: false,
label: 'Time',
value: (self: any, rawValue: any, xValuesIndex: any, currentVal: any) => {
value: (
self: any,
rawValue: any,
xValuesIndex: any,
currentVal: any,
) => {
if (currentVal == null) {
let xValues = self.data[xValuesIndex];
let xValue = fmtDate(tzDate(xValues[xValues.length - 1]));
Expand All @@ -53,7 +58,12 @@ export default class UPlotMultiLineChartComponent extends React.Component<
show: true,
spanGaps: false,
label: this.props.labelOne,
value: (self: any, rawValue: any, yValuesIndex: any, currentVal: any) => {
value: (
self: any,
rawValue: any,
yValuesIndex: any,
currentVal: any,
) => {
if (currentVal == null) {
let yValues = self.data[yValuesIndex];
let yValue = yValues[yValues.length - 1]?.toFixed(2);
Expand All @@ -69,7 +79,12 @@ export default class UPlotMultiLineChartComponent extends React.Component<
show: true,
spanGaps: false,
label: this.props.labelTwo,
value: (self: any, rawValue: any, yValuesIndex: any, currentVal: any) => {
value: (
self: any,
rawValue: any,
yValuesIndex: any,
currentVal: any,
) => {
if (currentVal == null) {
let yValues = self.data[yValuesIndex];
let yValue = yValues[yValues.length - 1]?.toFixed(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ const TimestampBtn = ({ gps, dataFilter }: TimestampFilterBtnProps) => {
} to ${
dataFilter.timestamps.endDate
? fmtDate(tzDate(parseISOString(dataFilter.timestamps.endDate)))
// @ts-ignore
: fmtDate(tzDate(parseISOString(gps.data.at(-1).timestamp)))
: // @ts-ignore
fmtDate(tzDate(parseISOString(gps.data.at(-1).timestamp)))
}`}
</div>
<div
Expand Down