Skip to content

Commit

Permalink
ci: github workflows (DeCenter-AI#16)
Browse files Browse the repository at this point in the history
* update: package.json

Took 3 minutes

* style: add prettier config

Took 4 minutes

* ci: add

Took 52 seconds

* test: jest

Took 11 seconds

* ci: import from decenterai.com

Took 4 minutes

* ignore: prettier

* update: pnpm lock

* scripts: postinstall

Took 12 seconds
  • Loading branch information
Hiro authored Oct 13, 2023
1 parent d909a3f commit 7a0ec37
Show file tree
Hide file tree
Showing 18 changed files with 604 additions and 115 deletions.
3 changes: 3 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# These are supported funding model platforms

github: [Nasfame]
33 changes: 33 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## Related Issue(s)

Fixes #
<br>
For #

## Proposed Changes

[//]: # '[List down the specific changes you have made in this pull request.]'

- [x]

## Checklist

- [x] I have followed the repository's contribution guidelines.
- [x] I have added necessary documentation or updated existing documentation.
- [x] My code follows the established code style and formatting of the project.
- [x] I have tested my changes and they function as expected.
- [ ] I have added suitable unit tests (if applicable).

## Screenshots

<!--[Please upload screenshots of the affected screens]-->

## To-Do

<!-- [If there are any pending tasks or follow-ups, list them here.] -->

- [ ]

## Additional Information

<!--[Include any additional information that may be relevant, such as screenshots, GIFs, or links to external resources.]-->
39 changes: 39 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Build

on:
push:
branches:
tags:
pull_request:
branches:

workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: pnpm/action-setup@v2
with:
version: 8.6.6

- name: Set up Node.js
uses: actions/setup-node@v3
with:
cache: 'pnpm'
node-version: 19.9.0 #last release of node v19
check-latest: false

- name: Install dependencies
run: pnpm install

- name: Build
run: |
npm run build
81 changes: 81 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: 'CodeQL'

on:
push:
branches: ['main']
pull_request:
# The branches below must be a subset of the branches above
branches: ['main']
schedule:
- cron: '25 10 * * 4'

jobs:
analyze:
name: Analyze
# Runner size impacts CodeQL analysis time. To learn more, please see:
# - https://gh.io/recommended-hardware-resources-for-running-codeql
# - https://gh.io/supported-runners-and-hardware-resources
# - https://gh.io/using-larger-runners
# Consider using larger runners for possible analysis time improvements.
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: ['javascript']
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ]
# Use only 'java' to analyze code written in Java, Kotlin or both
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: '/language:${{matrix.language}}'
58 changes: 58 additions & 0 deletions .github/workflows/cross.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Cross

on:
push:
branches:
- main
tags:

pull_request:
branches:

workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
MODE: test
NODE_ENV: testing

jobs:
build:
timeout-minutes: 10

strategy:
max-parallel: 2
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
node_version: [18, 19, 20]
architecture: [x64] #, arm64 ] # arm,

runs-on: ${{ matrix.os }}
name: Node ${{ matrix.node_version }} - ${{ matrix.architecture }} on ${{ matrix.os }}

steps:
- uses: actions/checkout@v3

- uses: pnpm/action-setup@v2
with:
version: 8.6.6

- uses: actions/setup-node@v3
with:
cache: 'pnpm'
node-version: ${{ matrix.node_version }}
architecture: ${{ matrix.architecture }}
check-latest: true

- name: Install dependencies
run: pnpm install

- name: Build
run: npm run build

- name: Run tests for ${{runner.os}}
run: npm run test
83 changes: 83 additions & 0 deletions .github/workflows/prettier.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Prettier

on:
# pull_request:
push:
branches:
- main

workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
actions: write
contents: write

jobs:
prettier:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 1
ref: ${{ github.head_ref }}
persist-credentials: true

# - name: Git config
# run: |
# git config --global user.name Hiro
# git config --global user.email [email protected]
# - name: Prettify code
# shell: bash
# run: |
# find . -type f -not -name "prettier.yaml"
# doesn't work as the prettier complains argument list is too long

- name: Create .prettierignore
shell: bash
run: |
cp .prettierignore .prettierignore.ci
echo ".github/workflows/${GITHUB_WORKFLOW}.yaml" >> .prettierignore.ci
# uses: "DamianReeves/write-file-action@master"
# with:
# path: .prettierignore
# write-mode: append
# contents: |
# .github/workflows/${ github.workflow}.yaml

- name: Prettify code
# continue-on-error: true
uses: creyD/[email protected]
env:
GITHUB_ACTOR: ${{github.actor}}
with:
dry: false
github_token: ${{ github.token }}
same_commit: false
commit_message: 'style: pretty code'
commit_description: 'automated via ci'
file_pattern: '*'
only_changed: false
prettier_options: '--write . --ignore-path .prettierignore.ci'
# ignore path not necessary
# commit_options: '-c user.email [email protected]'

# - name: Prettify code except yaml files [executed cuz the actions tries to update ${{github.workflow}}.yaml
# if: $(failure())
# uses: creyD/[email protected]
# env:
# GITHUB_ACTOR: ${{github.actor}}
# with:
# dry: false
# github_token: ${{ github.token }}
# same_commit: false
# commit_message: 'style: pretty code'
# commit_description: 'automated via ci'
# file_pattern: "**/*.{js,jsx,ts,tsx,css,scss,html,vue,json,md}`"
# only_changed: false
# prettier_options: '--write .'
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ yarn-error.log*
next-env.d.ts

.idea/
.env
.run/
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
.next/
12 changes: 12 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"printWidth": 90,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"trailingComma": "all",
"bracketSpacing": true,
"jsxBracketSameLine": true,
"arrowParens": "always",
"proseWrap": "always"
}
4 changes: 2 additions & 2 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { pathsToModuleNameMapper } from 'ts-jest'
import { compilerOptions } from './tsconfig.json'
import { compilerOptions } from './tsconfig.node.json'

const jestConfig = {
preset: 'ts-jest',
Expand All @@ -10,7 +10,7 @@ const jestConfig = {
collectCoverageFrom: ['**/*.(t|j)s'],
coverageDirectory: '../coverage',
testRegex: '.*\\.spec\\.ts$',
moduleFileExtensions: ['js', 'json', 'ts'],
moduleFileExtensions: ['js', 'json', 'ts','mjs'],
// automock: true,
verbose: true,
}
Expand Down
Loading

0 comments on commit 7a0ec37

Please sign in to comment.