Skip to content

Commit

Permalink
feat: add devcontainer, format and lint (#9)
Browse files Browse the repository at this point in the history
Add a Node 22.5.1 devcontainer along with format and lint scripts.  These
will be used by workflows that run against all PRs.
  • Loading branch information
patheard authored Jul 31, 2024
1 parent c0c07cb commit 8eb088e
Show file tree
Hide file tree
Showing 13 changed files with 606 additions and 63 deletions.
23 changes: 23 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "Forms API",
"image": "mcr.microsoft.com/vscode/devcontainers/base:debian@sha256:f1ac6335fc8cdd253c673a76edf77d81b5aa4bf9746bc67ecce4337d6bbaeb20",
"containerEnv": {
"SHELL": "/bin/zsh"
},
"features": {
"aws-cli": {
"version": "latest"
},
"ghcr.io/devcontainers/features/node:1": {
"version": "22.5.1"
}
},
"customizations": {
"vscode": {
"extensions": ["github.copilot", "github.vscode-github-actions"]
}
},
"appPort": [3001],
"postCreateCommand": "yarn install",
"remoteUser": "vscode"
}
12 changes: 6 additions & 6 deletions .github/workflows/backstage-catalog-helper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ jobs:
uses: peter-evans/create-pull-request@v3
with:
token: ${{ steps.generate_token.outputs.token}}
commit-message: 'Add catalog-info.yaml'
branch: 'backstage/catalog-info'
title: 'Add catalog-info.yaml'
body: 'Adding a basic catalog-info.yaml to start populating the backstage catalog with your components.'
labels: 'backstage'
commit-message: "Add catalog-info.yaml"
branch: "backstage/catalog-info"
title: "Add catalog-info.yaml"
body: "Adding a basic catalog-info.yaml to start populating the backstage catalog with your components."
labels: "backstage"
add-paths: |
catalog-info.yaml
catalog-info.yaml
2 changes: 1 addition & 1 deletion .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ jobs:
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0

- name: Dependency review
uses: actions/dependency-review-action@a9c83d3af6b9031e20feba03b904645bb23d1dab # v1.0.2
uses: actions/dependency-review-action@a9c83d3af6b9031e20feba03b904645bb23d1dab # v1.0.2
2 changes: 1 addition & 1 deletion .github/workflows/labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ jobs:
steps:
- uses: cds-snc/labels@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
49 changes: 24 additions & 25 deletions .github/workflows/s3-backup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,31 @@ jobs:
s3-backup:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
fetch-depth: 0 # retrieve all history

- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
fetch-depth: 0 # retrieve all history
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
with:
aws-access-key-id: ${{ secrets.AWS_S3_BACKUP_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_S3_BACKUP_SECRET_ACCESS_KEY }}
aws-region: ca-central-1

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
with:
aws-access-key-id: ${{ secrets.AWS_S3_BACKUP_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_S3_BACKUP_SECRET_ACCESS_KEY }}
aws-region: ca-central-1
- name: Create ZIP bundle
run: |
ZIP_FILE=`basename ${{ github.repository }}`-`date '+%Y-%m-%d'`.zip
zip -rq "${ZIP_FILE}" .
mkdir -p ${{ github.repository }}
mv "${ZIP_FILE}" ${{ github.repository }}
- name: Create ZIP bundle
run: |
ZIP_FILE=`basename ${{ github.repository }}`-`date '+%Y-%m-%d'`.zip
zip -rq "${ZIP_FILE}" .
mkdir -p ${{ github.repository }}
mv "${ZIP_FILE}" ${{ github.repository }}
- name: Upload to S3 bucket
run: |
aws s3 sync . s3://${{ secrets.AWS_S3_BACKUP_BUCKET }} --exclude='*' --include='${{ github.repository }}/*'
- name: Upload to S3 bucket
run: |
aws s3 sync . s3://${{ secrets.AWS_S3_BACKUP_BUCKET }} --exclude='*' --include='${{ github.repository }}/*'
- name: Notify Slack channel if this job failed
if: ${{ failure() }}
run: |
json='{"text":"S3 backup failed in <https://github.com/${{ github.repository }}>!"}'
curl -X POST -H 'Content-type: application/json' --data "$json" ${{ secrets.SLACK_NOTIFY_WEBHOOK }}
- name: Notify Slack channel if this job failed
if: ${{ failure() }}
run: |
json='{"text":"S3 backup failed in <https://github.com/${{ github.repository }}>!"}'
curl -X POST -H 'Content-type: application/json' --data "$json" ${{ secrets.SLACK_NOTIFY_WEBHOOK }}
11 changes: 4 additions & 7 deletions .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ jobs:
shellcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2.7.0
- name: Shellcheck
run: |
.github/workflows/scripts/run-shellcheck.sh
- uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2.7.0
- name: Shellcheck
run: |
.github/workflows/scripts/run-shellcheck.sh
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ Machine-to-machine interface for downloading form submissions.

## To run locally

`yarn install & yarn start`
```sh
yarn install & yarn start
```

## With docker

`docker build -t forms-api .`

`docker run -p 3001:3001 forms-api`
```sh
docker build -t forms-api .
docker run -p 3001:3001 forms-api
```
11 changes: 6 additions & 5 deletions api/v1/routes/forms/{id}/submission/new.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
export default function () {
let operations = {
GET
GET,
};

function GET(req, res, next) {
function GET(req, res) {
const submission = {
id: req.params.id,
submission: "My form response",
}
};
res.status(200).json(submission);
}

GET.apiDoc = {
summary: "Retrieves the oldest submission with status ‘new’ and modifies status to ‘downloaded’",
summary:
"Retrieves the oldest submission with status ‘new’ and modifies status to ‘downloaded’",
parameters: [
{
name: "id",
Expand All @@ -38,4 +39,4 @@ export default function () {
};

return operations;
}
}
4 changes: 4 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import globals from "globals";
import pluginJs from "@eslint/js";

export default [{ languageOptions: { globals: globals.node } }, pluginJs.configs.recommended];
7 changes: 3 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import express from 'express';
import { initialize } from 'express-openapi';

import express from "express";
import { initialize } from "express-openapi";

const app = new express();
const port = process.env.PORT || 3001;
Expand All @@ -19,7 +18,7 @@ app.listen(port, () => {

app.get("/status", (request, response) => {
const status = {
"Status": "Running"
Status: "Running",
};

response.send(status);
Expand Down
15 changes: 12 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,25 @@
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
"start": "node index.js",
"lint": "eslint --fix .",
"lint:check": "eslint .",
"format": "prettier --write .",
"format:check": "prettier --check ."
},
"keywords": [],
"author": "CDS",
"author": "Canadian Digital Service",
"license": "MIT",
"dependencies": {
"express": "^4.19.2",
"express-openapi": "^12.1.3"
},
"devDependencies": {
"@eslint/js": "^9.8.0",
"eslint": "9.x",
"globals": "^15.8.0",
"prettier": "^3.3.3"
}
},
"main": "index.js",
"repository": "git@github.com:cds-snc/forms-api.git"
}
4 changes: 1 addition & 3 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"local>cds-snc/renovate-config"
]
"extends": ["local>cds-snc/renovate-config"]
}
Loading

0 comments on commit 8eb088e

Please sign in to comment.