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

Switch to API interop layer #1590

Merged
merged 9 commits into from
Oct 25, 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
23 changes: 23 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
root: true,
extends: ["airbnb-base", "prettier"],
ignorePatterns: ["tests/translations/**/*.js", "uswds*.js"],
rules: {
Expand Down Expand Up @@ -46,6 +47,28 @@ module.exports = {
"class-methods-use-this": 0,
},
},
{
files: [
"api-interop-layer/**/*.test.js",
"web/themes/new_weather_theme/tests/**/*.js",
],
extends: ["airbnb-base", "prettier"],
parserOptions: { ecmaVersion: 2024 },
rules: {
// This rule disallows using require() on files in devDependencies. But
// for test code, we'll rely on that heavily so we can disable the rule
// in here.
"import/no-extraneous-dependencies": [0],

// For imports in Node, file extensions are optional and discouraged as
// a matter of practice.
"import/extensions": ["error", "always"],

// chai provides "empty" expressions, such as `to.be.true`
"no-unused-expressions": "off",
},
env: { mocha: true },
},
{
files: [
"tests/**/*.js",
Expand Down
6 changes: 5 additions & 1 deletion .github/actions/javascript-lint/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ runs:
shell: bash
run: cd tests/api && npm ci

- name: install api-interop-layer dependencies
shell: bash
run: cd api-interop-layer && npm ci

- name: add problem matcher
shell: bash
run: echo "::add-matcher::${{ github.workspace }}/.github/workflows/problem-matcher-eslint.json"

- name: run eslint
shell: bash
run: npm run js-lint
run: npm run js-lint
8 changes: 8 additions & 0 deletions .github/actions/setup-site/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,11 @@ runs:
- name: clear the Drupal cache
shell: bash
run: make cc

# Restart the interop layer once the database is loaded. It immediately
# tries to run some queries, but if the database isn't ready, it'll crash
# and die.
- name: restart the interop layer
shell: bash
run: |
docker compose restart api-interop-layer
101 changes: 95 additions & 6 deletions .github/workflows/code-standards.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,42 @@ jobs:
if: needs.should-test.outputs.yes == 'true'
uses: ./.github/actions/style-lint

interop-layer-unit-tests:
name: interop layer unit tests
runs-on: ubuntu-latest
needs: [should-test]
defaults:
run:
working-directory: ./api-interop-layer/

steps:
- name: checkout
if: needs.should-test.outputs.yes == 'true'
uses: actions/checkout@v4
- name: setup node
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- name: install dependencies
run: npm ci
- name: test
run: npm test
- name: store coverage output
if: needs.should-test.outputs.yes == 'true'
uses: actions/upload-artifact@v4
with:
name: interop-coverage-report
path: ./api-interop-layer/coverage/clover.xml
retention-days: 1
- name: store coverage HTML
if: needs.should-test.outputs.yes == 'true'
uses: actions/upload-artifact@v4
with:
name: interop-coverage-html
path: ./api-interop-layer/coverage/
retention-days: 1

build-drupal-image:
name: build Drupal image
runs-on: ubuntu-latest
Expand Down Expand Up @@ -149,30 +185,83 @@ jobs:
if: needs.should-test.outputs.yes == 'true'
uses: actions/upload-artifact@v4
with:
name: coverage-report
name: drupal-coverage-report
path: .coverage/clover.xml
retention-days: 1

- name: store coverage HTML
if: needs.should-test.outputs.yes == 'true'
uses: actions/upload-artifact@v4
with:
name: drupal-coverage-html
# This is necessary because the action interprets this single entity
# starting with a dot as hidden. This is a bug in the action.
# https://github.com/actions/upload-artifact/issues/618
include-hidden-files: true
path: .coverage/
retention-days: 1

merge-code-coverage:
name: merge coverage
runs-on: ubuntu-latest
needs: [php-tests, interop-layer-unit-tests, should-test]

steps:
- name: get Drupal coverage output
if: needs.should-test.outputs.yes == 'true'
uses: actions/download-artifact@v4
with:
name: drupal-coverage-report
- name: rename
if: needs.should-test.outputs.yes == 'true'
run: mv clover.xml drupal.xml
- name: get interop layer coverage output
if: needs.should-test.outputs.yes == 'true'
uses: actions/download-artifact@v4
with:
name: interop-coverage-report
- name: rename
if: needs.should-test.outputs.yes == 'true'
run: mv clover.xml interop.xml
- name: setup PHP
if: needs.should-test.outputs.yes == 'true'
uses: shivammathur/setup-php@v2
with:
php-version: "8.2"
extensions: uopz
- name: install combine library
if: needs.should-test.outputs.yes == 'true'
run: composer require kavinsky/clover-merge
- name: combine reports
if: needs.should-test.outputs.yes == 'true'
run: ./vendor/bin/clover-merge merge -o combined.xml drupal.xml interop.xml
- name: store coverage output
if: needs.should-test.outputs.yes == 'true'
uses: actions/upload-artifact@v4
with:
name: combined-coverage-report
path: combined.xml
retention-days: 1

min-code-coverage:
name: "90% code coverage"
runs-on: ubuntu-latest
needs: [php-tests, should-test]
needs: [merge-code-coverage, should-test]

steps:
- name: get coverage output
id: download
- name: get combined coverage output
if: needs.should-test.outputs.yes == 'true'
uses: actions/download-artifact@v4
with:
name: coverage-report
name: combined-coverage-report

- name: 90% code coverage
if: needs.should-test.outputs.yes == 'true'
id: test-coverage
uses: johanvanhelden/gha-clover-test-coverage-check@v1
with:
percentage: 90
filename: clover.xml
filename: combined.xml
metric: statements

accessibility-tests:
Expand Down
12 changes: 11 additions & 1 deletion .github/workflows/deploy-sandbox.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,24 @@ jobs:
uses: ./.github/actions/set-library-versions
- name: bundle javascript
uses: ./.github/actions/javascript-bundle

- name: Deploy api interop layer in ${{ github.event.inputs.environment }} space
uses: cloud-gov/cg-cli-tools@main
with:
cf_username: ${{ secrets[env.CF_USERNAME] }}
cf_password: ${{ secrets[env.CF_PASSWORD] }}
cf_org: nws-weathergov
cf_space: ${{ github.event.inputs.environment }}
cf_command: "push api-weathergov-${{ github.event.inputs.environment }} -f manifests/manifest-${{ github.event.inputs.environment }}.yaml --var newrelic-license='${{ secrets.NEWRELIC_LICENSE }}' --strategy rolling"

- name: Deploy application in ${{ github.event.inputs.environment }} space
uses: cloud-gov/cg-cli-tools@main
with:
cf_username: ${{ secrets[env.CF_USERNAME] }}
cf_password: ${{ secrets[env.CF_PASSWORD] }}
cf_org: nws-weathergov
cf_space: ${{ github.event.inputs.environment }}
cf_command: "push -f manifests/manifest-${{ github.event.inputs.environment }}.yaml --var newrelic-license='${{ secrets.NEWRELIC_LICENSE }}' --var allowed-ips='${{secrets.ALLOWED_IP_ADDRESSES}}' --strategy rolling"
cf_command: "push weathergov-${{ github.event.inputs.environment }} -f manifests/manifest-${{ github.event.inputs.environment }}.yaml --var newrelic-license='${{ secrets.NEWRELIC_LICENSE }}' --strategy rolling"

- name: Run post-deploy steps in ${{ github.event.inputs.environment }} space
uses: cloud-gov/cg-cli-tools@main
Expand Down
59 changes: 36 additions & 23 deletions .github/workflows/deploy-staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,42 @@ jobs:
deploy-staging:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: set library versions
uses: ./.github/actions/set-library-versions
- name: bundle javascript
uses: ./.github/actions/javascript-bundle
- name: Deploy to cloud.gov weathergov-staging space
uses: cloud-gov/cg-cli-tools@main
env:
DEPLOY_NOW: thanks
with:
cf_username: ${{ secrets.CF_STAGING_USERNAME }}
cf_password: ${{ secrets.CF_STAGING_PASSWORD }}
cf_org: nws-weathergov
cf_space: staging
cf_command: "push -f manifests/manifest-staging.yaml --var newrelic-license=${{ secrets.NEWRELIC_LICENSE }} --strategy rolling"
- name: Run post deploy steps
uses: cloud-gov/cg-cli-tools@main
with:
cf_username: ${{ secrets.CF_STAGING_USERNAME }}
cf_password: ${{ secrets.CF_STAGING_PASSWORD }}
cf_org: nws-weathergov
cf_space: staging
cf_command: "run-task weathergov-staging --command './scripts/post-deploy.sh' --name 'weathergov-staging-deploy' -k '2G' -m '256M'"
- uses: actions/checkout@v4
- name: set library versions
uses: ./.github/actions/set-library-versions
- name: bundle javascript
uses: ./.github/actions/javascript-bundle

- name: Deploy api interop layer to cloud.gov weathergov-staging space
uses: cloud-gov/cg-cli-tools@main
env:
DEPLOY_NOW: thanks
with:
cf_username: ${{ secrets.CF_STAGING_USERNAME }}
cf_password: ${{ secrets.CF_STAGING_PASSWORD }}
cf_org: nws-weathergov
cf_space: staging
cf_command: "push api-weathergov-staging -f manifests/manifest-staging.yaml --var newrelic-license=${{ secrets.NEWRELIC_LICENSE }} --strategy rolling"

- name: Deploy application to cloud.gov weathergov-staging space
uses: cloud-gov/cg-cli-tools@main
env:
DEPLOY_NOW: thanks
with:
cf_username: ${{ secrets.CF_STAGING_USERNAME }}
cf_password: ${{ secrets.CF_STAGING_PASSWORD }}
cf_org: nws-weathergov
cf_space: staging
cf_command: "push weathergov-staging -f manifests/manifest-staging.yaml --var newrelic-license=${{ secrets.NEWRELIC_LICENSE }} --strategy rolling"

- name: Run post deploy steps
uses: cloud-gov/cg-cli-tools@main
with:
cf_username: ${{ secrets.CF_STAGING_USERNAME }}
cf_password: ${{ secrets.CF_STAGING_PASSWORD }}
cf_org: nws-weathergov
cf_space: staging
cf_command: "run-task weathergov-staging --command './scripts/post-deploy.sh' --name 'weathergov-staging-deploy' -k '2G' -m '256M'"

new-relic-record:
name: Record deployment to New Relic
Expand Down
6 changes: 6 additions & 0 deletions api-interop-layer/.c8rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"all": true,
"reporter": ["html"],
"exclude": ["node_modules/**", "coverage", "**/*.test.js"],
"require": ["mocha.js"]
}
2 changes: 2 additions & 0 deletions api-interop-layer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.nyc_output
coverage
11 changes: 11 additions & 0 deletions api-interop-layer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM node:20

RUN mkdir /app
WORKDIR /app

ADD ./package.json .
ADD ./package-lock.json .

RUN npm ci

CMD npm start
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Drupal\weather_blocks\Plugin\Block\Test\EndToEnd;

use Drupal\weather_blocks\Plugin\Block\HourlyForecastBlock;

/**
* Tests for hourly forecast data structure.
*/
final class HourlyForecastStructureTest extends EndToEndBase
{
/**
* @group e2e
*/
public function testHourlyWindGustNullIfCloseToSustained(): void
{
$this->onLocationRoute(33.521, -86.812);
$expected = null;

$data = $this->block->build();

$actual = $data["hours"][0]["windGust"];

$this->assertEquals($expected, $actual);
}
}
Loading
Loading