Refactor GtiHub actions into reuseable composite actions.

This commit is contained in:
Matthew Sevey 2022-03-31 11:40:20 -04:00
parent 18eb784f26
commit eee48729d7
No known key found for this signature in database
GPG Key ID: 9ADDD344F13057F6
16 changed files with 175 additions and 205 deletions

25
.github/actions/prettier/action.yml vendored Normal file
View File

@ -0,0 +1,25 @@
# Define action name, description, and inputs
name: "Prettier Lint"
description: "Lint code with Prettier"
inputs:
working-directory:
required: false
description: "Working directory"
default: "."
# Define action steps
runs:
using: "composite"
steps:
- uses: actions/setup-node@v2
with:
node-version: 16.x
- run: |
yarn
yarn prettier --check .
shell: bash
working-directory: ${{ inputs.working-directory }}
- if: inputs.working-directory == 'packages/dashboard-v2' || inputs.working-directory == 'packages/dashboard'
run: yarn lint
shell: bash
working-directory: ${{ inputs.working-directory }}

View File

@ -0,0 +1,17 @@
# Define action name, description, and inputs
name: "Python Black Lint"
description: "Lint python code with black"
# Define action steps
runs:
using: "composite"
steps:
- uses: actions/setup-python@v2
with:
python-version: "3.x"
architecture: x64
- run: |
pip install black
black --check .
shell: bash

View File

@ -0,0 +1,22 @@
# Define action name, description, and inputs
name: "Python Flake8 Lint"
description: "Lint python code with black"
# Define action steps
runs:
using: "composite"
steps:
- uses: actions/setup-python@v2
with:
python-version: "3.x"
architecture: x64
# E203: https://www.flake8rules.com/rules/E203.html - Whitespace before ':'
# E501: https://www.flake8rules.com/rules/E501.html - Line too long
# W503: https://www.flake8rules.com/rules/W503.html - Line break occurred before a binary operator
# W605: https://www.flake8rules.com/rules/W605.html - Invalid escape sequence
# E722: https://www.flake8rules.com/rules/E722.html - Do not use bare except, specify exception instead
- run: |
pip install flake8
flake8 --max-line-length 88 --ignore E203,E501,W503,W605,E722
shell: bash

View File

@ -1,27 +0,0 @@
name: Dockerfile Lint
on:
push:
branches:
- master
pull_request:
jobs:
hadolint:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
dockerfile:
- docker/nginx/Dockerfile
- docker/sia/Dockerfile
- packages/dashboard/Dockerfile
- packages/dnslink-api/Dockerfile
- packages/handshake-api/Dockerfile
- packages/health-check/Dockerfile
- packages/website/Dockerfile
steps:
- uses: actions/checkout@v3
- uses: hadolint/hadolint-action@v2.0.0
with:
dockerfile: ${{ matrix.dockerfile }}

View File

@ -1,24 +0,0 @@
name: Lint - packages/dashboard-v2
on:
pull_request:
paths:
- packages/dashboard-v2/**
defaults:
run:
working-directory: packages/dashboard-v2
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16.x
- run: yarn
- run: yarn prettier --check
- run: yarn lint

View File

@ -1,24 +0,0 @@
name: Lint - packages/dashboard
on:
pull_request:
paths:
- packages/dashboard/**
defaults:
run:
working-directory: packages/dashboard
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16.x
- run: yarn
- run: yarn prettier --check .
- run: yarn next lint

View File

@ -1,23 +0,0 @@
name: Lint - packages/dnslink-api
on:
pull_request:
paths:
- packages/dnslink-api/**
defaults:
run:
working-directory: packages/dnslink-api
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16.x
- run: yarn
- run: yarn prettier --check .

View File

@ -1,23 +0,0 @@
name: Lint - packages/handshake-api
on:
pull_request:
paths:
- packages/handshake-api/**
defaults:
run:
working-directory: packages/handshake-api
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16.x
- run: yarn
- run: yarn prettier --check .

View File

@ -1,23 +0,0 @@
name: Lint - packages/health-check
on:
pull_request:
paths:
- packages/health-check/**
defaults:
run:
working-directory: packages/health-check
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16.x
- run: yarn
- run: yarn prettier --check .

View File

@ -1,23 +0,0 @@
name: Lint - packages/website
on:
pull_request:
paths:
- packages/website/**
defaults:
run:
working-directory: packages/website
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16.x
- run: yarn
- run: yarn prettier --check .

View File

@ -1,37 +0,0 @@
name: Lint - Python Scripts
on:
push:
paths:
- "**.py"
jobs:
black:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: "3.x"
architecture: x64
- run: pip install black
- run: black --check .
flake8:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: "3.x"
architecture: x64
- run: pip install flake8
# E203: https://www.flake8rules.com/rules/E203.html - Whitespace before ':'
# E501: https://www.flake8rules.com/rules/E501.html - Line too long
# W503: https://www.flake8rules.com/rules/W503.html - Line break occurred before a binary operator
# W605: https://www.flake8rules.com/rules/W605.html - Invalid escape sequence
# E722: https://www.flake8rules.com/rules/E722.html - Do not use bare except, specify exception instead
- run: flake8 --max-line-length 88 --ignore E203,E501,W503,W605,E722

106
.github/workflows/lint.yml vendored Normal file
View File

@ -0,0 +1,106 @@
name: Lint
on:
pull_request:
jobs:
# Determine what the prettier changes are
prettier-changes:
runs-on: ubuntu-latest
outputs:
packages: ${{ steps.filter.outputs.changes }}
steps:
# Use paths-filter to determine which paths have changes
# https://github.com/dorny/paths-filter
- uses: dorny/paths-filter@v2
id: filter
with:
# Format of key: value. When there is a change detected in value, the
# key will be returned in the output.
filters: |
packages/dashboard: packages/dashboard/**
packages/dnslink-api: packages/dnslink-api/**
packages/handshake-api: packages/handshake-api/**
packages/health-check: packages/health-check/**
packages/website: packages/website/**
# Determine what the dockerfile changes are
dockerfile-changes:
runs-on: ubuntu-latest
outputs:
packages: ${{ steps.filter.outputs.changes }}
steps:
# Use paths-filter to determine which paths have changes
# https://github.com/dorny/paths-filter
- uses: dorny/paths-filter@v2
id: filter
with:
# Format of key: value. When there is a change detected in value, the
# key will be returned in the output.
filters: |
docker/nginx/Dockerfile: docker/nginx/Dockerfile
docker/sia/Dockerfile: docker/sia/Dockerfile
packages/dashboard/Dockerfile: packages/dashboard/Dockerfile
packages/dnslink-api/Dockerfile: packages/dnslink-api/Dockerfile
packages/handshake-api/Dockerfile: packages/handshake-api/Dockerfile
packages/health-check/Dockerfile: packages/health-check/Dockerfile
packages/website/Dockerfile: packages/website/Dockerfile
# Run the prettier lint if there are changes to any of the prettier packages
prettier:
needs: prettier-changes
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
working-directory: ${{ fromJSON(needs.prettier-changes.outputs.packages) }}
steps:
- uses: actions/checkout@v2
- name: Run Prettier Action
uses: ./.github/actions/prettier
with:
working-directory: ${{ matrix.working-directory }}
# Run the hadolint dockefile lint if there are changes to any of the
# dockerfiles
hadolint:
needs: dockerfile-changes
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
dockerfile: ${{ fromJSON(needs.dockerfile-changes.outputs.packages) }}
steps:
- uses: actions/checkout@v3
- uses: hadolint/hadolint-action@v2.0.0
with:
dockerfile: ${{ matrix.dockerfile }}
# Determine if there are python changes
python-changes:
runs-on: ubuntu-latest
outputs:
# Check if the changed status of py is true
updates: steps.changes.outputs.py == 'true'
steps:
# Use paths-filter to determine which paths have changes
# https://github.com/dorny/paths-filter
- uses: dorny/paths-filter@v2
id: changes
with:
filters: |
py: "**.py"
# Run the hadolint dockefile lint if there are changes to any of the
# dockerfiles
python-lint:
needs: python-changes
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run Black python linter
if: ${{ needs.python-changes.outputs.updates }}
uses: ./.github/actions/python-black-lint
- name: Run Flake8 python linter
if: ${{ needs.python-changes.outputs.updates }}
uses: ./.github/actions/python-flake8-lint

View File

@ -12,5 +12,6 @@ FROM nebulouslabs/sia:1.5.6
COPY --from=sia-builder /go/bin/ /usr/bin/
# rename binaries to old siac siad naming
RUN if [ -f "/usr/bin/skyd" ]; then mv /usr/bin/skyd /usr/bin/siad; fi && \
if [ -f "/usr/bin/skyc" ]; then mv /usr/bin/skyc /usr/bin/siac; fi

View File

@ -1,3 +1,5 @@
# Dashboard
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
## Getting Started

View File

@ -195,6 +195,7 @@ async function blockerHealthCheck(done) {
done({ name: "blocker", time: calculateElapsedTime(time), ...data });
}
// genericAccessCheck
async function genericAccessCheck(name, url) {
const authCookie = await getAuthCookie();
const time = process.hrtime();

View File

@ -42,7 +42,7 @@ DISK_USAGE_DUMP_LOG = "../../devops/disk-monitor/disk-usage-dump.log"
setup()
# run_checks runs the health checks
async def run_checks():
print("Running Skynet portal health checks")
try: