Skip to content

Commit

Permalink
Merge pull request #5 from corva-ai/chore-test
Browse files Browse the repository at this point in the history
feat: add package-version output [CINF-3582]
  • Loading branch information
yafanasiev authored Oct 28, 2024
2 parents 36ccf28 + 483402b commit 24f400f
Show file tree
Hide file tree
Showing 16 changed files with 1,966 additions and 125,311 deletions.
33 changes: 33 additions & 0 deletions .github/actions/setup-environment/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: "Setup Environment"

description: "Setup build environment and NodeJS"

inputs:
build:
description: "Whether to execute build step."
required: false
default: "true"

runs:
using: "composite"
steps:
- name: Setup Node environment
uses: actions/setup-node@v4.0.3
with:
node-version-file: '.nvmrc'
- name: Cache NodeJS dependencies
uses: actions/cache@v4.0.2
id: nodejs-cache
with:
path: node_modules
key: ${{ runner.os }}-${{ runner.arch }}-npm-${{ hashFiles('./yarn.lock') }}
- name: Install NodeJS dependencies
shell: bash
if: ${{ steps.nodejs-cache.outputs.cache-hit != 'true' }}
run: npm ci
- name: Build project
if: ${{ inputs.build == 'true' }}
shell: bash
run: |
npm run build
npm run package
64 changes: 41 additions & 23 deletions .github/workflows/check-dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ name: Check dist/
on:
push:
branches:
- main
- develop
paths-ignore:
- '**.md'
pull_request:
Expand All @@ -18,36 +18,54 @@ on:

jobs:
check-dist:
runs-on: ubuntu-latest

name: Check dist/
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v2

- name: Set Node.js 20.x
uses: actions/setup-node@v4
- name: Load secrets from 1Password
uses: 1password/load-secrets-action@v2.0.0
id: secrets
with:
node-version: 20.x

- name: Install dependencies
run: npm ci

- name: Rebuild the dist/ directory
run: |
npm run build
npm run package
export-env: false
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN_RO }}
#
APP_ID: 'op://GitHub.Actions/GitHub/corva-bot/APP_ID'
PRIVATE_KEY: 'op://GitHub.Actions/GitHub/corva-bot/PRIVATE_KEY'
- name: Checkout sources
uses: actions/checkout@v4.1.7
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
- name: Setup Environment
uses: ./.github/actions/setup-environment
- name: Compare the expected and actual dist/ directories
id: diff
run: |
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then
echo "Detected uncommitted changes after build. See status below:"
git diff
exit 1
fi
id: diff

# If index.js was different than expected, upload the expected version as an artifact
- uses: actions/upload-artifact@v2
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
# If index.js was different then expected, upload the expected version as an artifact
- name: Upload build artifact
uses: actions/upload-artifact@v4.3.6
if: ${{ failure() && steps.diff.outcome == 'failure' }}
id: artifact
with:
name: dist
path: dist/
path: ./dist/
- name: Generate GitHub token
uses: actions/create-github-app-token@v1.10.4
if: ${{ success() || failure() }}
id: token
with:
app-id: ${{ steps.secrets.outputs.APP_ID }}
private-key: ${{ steps.secrets.outputs.PRIVATE_KEY }}
- name: Add PR status check
uses: ouzi-dev/commit-status-updater@v2.0.2
if: ${{ success() || failure() }}
with:
token: ${{ steps.token.outputs.token }}
name: 'Check dist'
status: ${{ job.status }}
url: ${{ steps.diff.outcome == 'failure' && steps.artifact.outputs.artifact-url || format('https://github.com/{0}/actions/runs/{1}', github.repository, github.run_id) }}
description: ${{ job.status == 'success' && 'dist/ is up-to-date' || 'dist/ needs to be updated. Click on "Details" to download updated package' }}
151 changes: 151 additions & 0 deletions .github/workflows/code-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
name: 'Code Analysis'

on:
pull_request:
types:
- opened
- synchronize
push:
branches:
- develop

permissions:
id-token: write
contents: read
actions: read
checks: write
statuses: write

jobs:
lint:
name: Lint
runs-on: ubuntu-24.04
steps:
- name: Load secrets from 1Password
uses: 1password/load-secrets-action@v2.0.0
id: secrets
with:
export-env: false
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN_RO }}
#
APP_ID: 'op://GitHub.Actions/GitHub/corva-bot/APP_ID'
PRIVATE_KEY: 'op://GitHub.Actions/GitHub/corva-bot/PRIVATE_KEY'
- name: Checkout sources
uses: actions/checkout@v4.1.7
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
- name: Setup Environment
uses: ./.github/actions/setup-environment
with:
build: "false"
- name: Cache ESLint
uses: actions/cache@v4.0.2
with:
path: .eslintcache
key: ${{ runner.os }}-eslint-${{ hashFiles('./yarn.lock') }}-${{ hashFiles('./.eslint*') }}
- name: Lint
run: npm run lint
- name: Generate GitHub token
uses: actions/create-github-app-token@v1.10.4
if: ${{ success() || failure() }}
id: token
with:
app-id: ${{ steps.secrets.outputs.APP_ID }}
private-key: ${{ steps.secrets.outputs.PRIVATE_KEY }}
- name: Add PR status check
uses: ouzi-dev/commit-status-updater@v2.0.2
if: ${{ success() || failure() }}
with:
token: ${{ steps.token.outputs.token }}
name: 'Lint'
status: ${{ job.status }}
url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
description: ${{ job.status == 'success' && 'Linted successfully' || 'Linted with errors. Check PR annotations' }}

format:
name: Format
runs-on: ubuntu-24.04
steps:
- name: Load secrets from 1Password
uses: 1password/load-secrets-action@v2.0.0
id: secrets
with:
export-env: false
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN_RO }}
#
APP_ID: 'op://GitHub.Actions/GitHub/corva-bot/APP_ID'
PRIVATE_KEY: 'op://GitHub.Actions/GitHub/corva-bot/PRIVATE_KEY'
- name: Checkout sources
uses: actions/checkout@v4.1.7
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
- name: Setup Environment
uses: ./.github/actions/setup-environment
with:
build: "false"
- name: Format
run: npm run format-check
- name: Generate GitHub token
uses: actions/create-github-app-token@v1.10.4
if: ${{ success() || failure() }}
id: token
with:
app-id: ${{ steps.secrets.outputs.APP_ID }}
private-key: ${{ steps.secrets.outputs.PRIVATE_KEY }}
- name: Add PR status check
uses: ouzi-dev/commit-status-updater@v2.0.2
if: ${{ success() || failure() }}
with:
token: ${{ steps.token.outputs.token }}
name: 'Format'
status: ${{ job.status }}
url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
description: ${{ job.status == 'success' && 'Code is properly formatted' || 'Code is not properly formatted. Check PR annotations' }}

test:
name: Unit Test
runs-on: ubuntu-24.04
steps:
- name: Load secrets from 1Password
uses: 1password/load-secrets-action@v2.0.0
id: secrets
with:
export-env: false
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN_RO }}
#
APP_ID: 'op://GitHub.Actions/GitHub/corva-bot/APP_ID'
PRIVATE_KEY: 'op://GitHub.Actions/GitHub/corva-bot/PRIVATE_KEY'
- name: Checkout sources
uses: actions/checkout@v4.1.7
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
- name: Setup Environment
uses: ./.github/actions/setup-environment
with:
build: "false"
- name: Cache Jest
uses: actions/cache@v4.0.2
with:
path: ./node_modules/.cache/jest
key: ${{ runner.os }}-jest-${{ hashFiles('./yarn.lock') }}
- name: Test
run: npm run test
- name: Generate GitHub token
uses: actions/create-github-app-token@v1.10.4
if: ${{ success() || failure() }}
id: token
with:
app-id: ${{ steps.secrets.outputs.APP_ID }}
private-key: ${{ steps.secrets.outputs.PRIVATE_KEY }}
- name: Add PR status check
uses: ouzi-dev/commit-status-updater@v2.0.2
if: ${{ success() || failure() }}
with:
token: ${{ steps.token.outputs.token }}
name: 'Unit Test'
status: ${{ job.status }}
url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
description: ${{ job.status == 'success' && 'Unit tests ran successfully' || 'Unit tests ran with errors. Check PR annotations' }}
71 changes: 0 additions & 71 deletions .github/workflows/codeql-analysis.yml

This file was deleted.

26 changes: 0 additions & 26 deletions .github/workflows/test.yml

This file was deleted.

4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,6 @@ Thumbs.db

# Ignore built ts files
__tests__/runner/*
lib/**/*
lib/**/*

.idea
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ inputs:
description: 'Change status to published after package upload'
required: false
default: 'false'
label:
description: 'Label to set on the package when publishing'
required: false
outputs:
package-id:
description: 'Package ID that was deployed'
package-version:
description: 'Package version that was deployed'
package-status:
description: 'Final status of the deployed package (draft is a successful deploy)'
runs:
Expand Down
Loading

0 comments on commit 24f400f

Please sign in to comment.