Skip to content

Commit

Permalink
add npm code linting dependencies, add github workflow files, add dep…
Browse files Browse the repository at this point in the history
…endabot config
  • Loading branch information
derekwolpert committed Sep 19, 2022
1 parent 0810586 commit 17d17f4
Show file tree
Hide file tree
Showing 15 changed files with 4,578 additions and 23 deletions.
31 changes: 31 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: 2

registries:
npm-github:
type: npm-registry
url: https://npm.pkg.github.com
token: ${{ secrets.PACKAGES_READ_TOKEN }}

updates:
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
interval: 'weekly'
day: 'monday'
time: '12:00'
labels:
- 'dependabot'
open-pull-requests-limit: 50

- package-ecosystem: 'npm'
directory: '/'
registries:
- npm-github
schedule:
interval: 'weekly'
day: 'monday'
time: '12:00'
labels:
- 'dependabot'
open-pull-requests-limit: 50
versioning-strategy: 'increase'
77 changes: 77 additions & 0 deletions .github/workflows/bump.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import child from 'child_process'
import { promisify } from 'util'
import packageJson from '../../package.json' assert { type: 'json' }

const exec = promisify(function (command, done) {
console.log(`Executing: '${command}'`)
child.exec(command, (error, stdout, stderr) => {
if (error) return done(error)
console.error(stderr)
console.log(stdout)
done(null, { stdout, stderr })
})
})

const getDistTags = async () => {
return Object.fromEntries(
(await exec(`npm dist-tag ${packageName}`))
.stdout
.split(/\r\n|\r|\n/)
.filter(Boolean)
.map(version => version.split(': '))
)
}

const packageName = packageJson.name
const githubRef = process.env.GITHUB_REF
if (!githubRef) throw new Error('Missing githubRef')

// matches format '1.2.3'
const latestMatch = /^refs\/tags\/v([0-9]+)\.([0-9]+)\.([0-9]+)$/
// matches format '1.2.3-4'
const nextMatch = /^refs\/tags\/v([0-9]+)\.([0-9]+)\.([0-9]+)\-([0-9]+)$/
// matches format '1.2.3-alpha.4'
const preMatch = /^refs\/tags\/v([0-9]+)\.([0-9]+)\.([0-9]+)\-[a-zA-Z0-9_]+\.([0-9]+)$/

let distTag = ''
if (latestMatch.test(githubRef)) {
distTag = 'latest'
} else if (nextMatch.test(githubRef)) {
distTag = 'next'
} else if (preMatch.test(githubRef)) {
// if version is '1.0.0-alpha.0', will assign distTag to 'alpha'
distTag = githubRef.replace(/(^refs\/tags\/v([0-9]+)\.([0-9]+)\.([0-9]+)\-|\.([0-9]+)$)/g, '')
}
// throw error if we cannot determine dist-tag
if (!distTag) throw new Error('Unable to determine dist-tag')

const versionNumber = githubRef?.replace(/^refs\/tags\/v/, '')
if (!versionNumber) throw new Error('Missing versionNumber')

console.log(`Releasing version 'v${versionNumber}' to '${distTag}' channel`)

// array of before dist-tags
const targetTags = await getDistTags()

// bump version, but do not create associated tag/commit
await exec(`npm --no-git-tag-version version ${versionNumber}`)

// publish version with parsed dist-tag
await exec(`npm publish --tag ${distTag}`)

// insert published version into target dist-tags object
targetTags[distTag] = versionNumber

const afterTags = await getDistTags()

// reassign distTags
for (const [tag, version] of Object.entries(targetTags)) {
if (afterTags[tag] !== version) {
await exec(`npm dist-tag add ${packageName}@${version} ${tag}`)
}
}

// remove erroneously assigned dist-tags
for (const tag in afterTags) {
if (!(tag in targetTags)) await exec(`npm dist-tag rm ${packageName} ${tag}`)
}
48 changes: 48 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Build and Publish Package

on:
release:
types: [published]

jobs:
publish:
name: Build and Publish
runs-on: ubuntu-latest

permissions:
contents: write
packages: write

timeout-minutes: 5
steps:
- name: Code Checkout
uses: actions/checkout@v3

- name: Install NodeJS
uses: actions/setup-node@v3
with:
node-version: 16
registry-url: 'https://npm.pkg.github.com'
scope: '@noop-inc'

- name: Cache NPM
id: cache-npm
uses: actions/cache@v3
with:
path: |
~/.npm
./node_modules
key: ${{ runner.os }}-npm-${{ hashFiles('package-lock.json') }}
restore-keys: ${{ runner.os }}-npm-

- name: Install Dependencies
if: steps.cache-npm.outputs.cache-hit != 'true'
run: npm ci
env:
NODE_AUTH_TOKEN: ${{ secrets.PACKAGES_READ_TOKEN }}

- name: Bump and Publish
run: node .github/workflows/bump.js
env:
GITHUB_REF: ${{ github.ref }}
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
84 changes: 84 additions & 0 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Code Quality

on:
pull_request:
types: [opened, reopened, synchronize]
push:
branches: [main]

jobs:
linting:
name: Linting
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Code Checkout
uses: actions/checkout@v3

- name: Install NodeJS
uses: actions/setup-node@v3
with:
node-version: 16
registry-url: 'https://npm.pkg.github.com'
scope: '@noop-inc'

- name: Cache NPM
id: cache-npm
uses: actions/cache@v3
with:
path: |
~/.npm
./node_modules
key: ${{ runner.os }}-npm-${{ hashFiles('package-lock.json') }}
restore-keys: ${{ runner.os }}-npm-

- name: Install Dependencies
run: npm ci
env:
NODE_AUTH_TOKEN: ${{ secrets.PACKAGES_READ_TOKEN }}

- name: Cache Lint
id: cache-lint
uses: actions/cache@v3
with:
path: |
./node_modules/.cache/prettier
./node_modules/.cache/.eslintcache
key: ${{ runner.os }}-lint-${{ github.sha }}
restore-keys: ${{ runner.os }}-lint-

- name: Code Linting
run: npm run lint

tests:
name: Tests
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Code Checkout
uses: actions/checkout@v3

- name: Install NodeJS
uses: actions/setup-node@v3
with:
node-version: 16
registry-url: 'https://npm.pkg.github.com'
scope: '@noop-inc'

- name: Cache NPM
id: cache-npm
uses: actions/cache@v3
with:
path: |
~/.npm
./node_modules
key: ${{ runner.os }}-npm-${{ hashFiles('package-lock.json') }}
restore-keys: ${{ runner.os }}-npm-

- name: Install Dependencies
run: npm ci
env:
NODE_AUTH_TOKEN: ${{ secrets.PACKAGES_READ_TOKEN }}

- name: Execute Tests
run: npm test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Noop Documentation

Central Repository of Noop Documentation

## What is Noop?
Expand Down
18 changes: 18 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export const pages = [
'Applications',
'Environments',
'Builds',
'Pipelines',
'Endpoints',
'Components',
'Resources',
'Routing',
'Deployments',
'Stacks',
'Logs',
'Security',
'Local',
'Manifests',
'Logic',
'Workflows'
]
Loading

0 comments on commit 17d17f4

Please sign in to comment.