Skip to content

Commit

Permalink
feat(repo): setup initial CI
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Dec 19, 2021
1 parent 6e9470d commit 747ab76
Show file tree
Hide file tree
Showing 13 changed files with 809 additions and 26 deletions.
26 changes: 26 additions & 0 deletions .commitlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"extends": ["@commitlint/config-conventional"],
"rules": {
"scope-enum": [
1,
"always",
[
"core",
"cli",
"jira",
"azure-devops",
"docs-site",
"ci",
"repo",
"misc"
]
],
"type-enum": [
1,
"always",
["test", "docs", "chore", "feat", "fix", "release"]
],
"body-max-line-length": [1, "always", 400],
"footer-max-line-length": [1, "always", 400]
}
}
139 changes: 139 additions & 0 deletions .github/workflows/combine-prs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
name: 'Combine PRs'

# Controls when the action will run - in this case triggered manually
on:
workflow_dispatch:
inputs:
branchPrefix:
description: 'Branch prefix to find combinable PRs based on'
required: true
default: 'dependabot'
mustBeGreen:
description: 'Only combine PRs that are green (status is success)'
required: true
default: true
combineBranchName:
description: 'Name of the branch to combine PRs into'
required: true
default: 'combine-prs-branch'
ignoreLabel:
description: 'Exclude PRs with this label'
required: true
default: 'nocombine'

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "combine-prs"
combine-prs:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: actions/github-script@v3
id: fetch-branch-names
name: Fetch branch names
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const pulls = await github.paginate('GET /repos/:owner/:repo/pulls', {
owner: context.repo.owner,
repo: context.repo.repo
});
branches = [];
prs = [];
base_branch = null;
for (const pull of pulls) {
const branch = pull['head']['ref'];
console.log('Pull for branch: ' + branch);
if (branch.startsWith('${{ github.event.inputs.branchPrefix }}')) {
console.log('Branch matched: ' + branch);
statusOK = true;
if(${{ github.event.inputs.mustBeGreen }}) {
console.log('Checking green status: ' + branch);
const statuses = await github.paginate('GET /repos/{owner}/{repo}/commits/{ref}/status', {
owner: context.repo.owner,
repo: context.repo.repo,
ref: branch
});
if(statuses.length > 0) {
const latest_status = statuses[0]['state'];
console.log('Validating status: ' + latest_status);
if(latest_status != 'success') {
console.log('Discarding ' + branch + ' with status ' + latest_status);
statusOK = false;
}
}
}
console.log('Checking labels: ' + branch);
const labels = pull['labels'];
for(const label of labels) {
const labelName = label['name'];
console.log('Checking label: ' + labelName);
if(labelName == '${{ github.event.inputs.ignoreLabel }}') {
console.log('Discarding ' + branch + ' with label ' + labelName);
statusOK = false;
}
}
if (statusOK) {
console.log('Adding branch to array: ' + branch);
branches.push(branch);
prs.push('#' + pull['number'] + ' ' + pull['title']);
base_branch = pull['base']['ref'];
}
}
}
if (branches.length == 0) {
core.setFailed('No PRs/branches matched criteria');
return;
}
core.setOutput('base-branch', base_branch);
core.setOutput('prs-string', prs.join('\n'));
combined = branches.join(' ')
console.log('Combined: ' + combined);
return combined
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2.3.3
with:
fetch-depth: 0
# Creates a branch with other PR branches merged together
- name: Created combined branch
env:
BASE_BRANCH: ${{ steps.fetch-branch-names.outputs.base-branch }}
BRANCHES_TO_COMBINE: ${{ steps.fetch-branch-names.outputs.result }}
COMBINE_BRANCH_NAME: ${{ github.event.inputs.combineBranchName }}
run: |
echo "$BRANCHES_TO_COMBINE"
sourcebranches="${BRANCHES_TO_COMBINE%\"}"
sourcebranches="${sourcebranches#\"}"
basebranch="${BASE_BRANCH%\"}"
basebranch="${basebranch#\"}"
git config pull.rebase false
git config user.name github-actions
git config user.email github-actions@github.com
git branch $COMBINE_BRANCH_NAME $basebranch
git checkout $COMBINE_BRANCH_NAME
git pull origin $sourcebranches --no-edit
git push origin $COMBINE_BRANCH_NAME
# Creates a PR with the new combined branch
- uses: actions/github-script@v3
name: Create Combined Pull Request
env:
PRS_STRING: ${{ steps.fetch-branch-names.outputs.prs-string }}
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const prString = process.env.PRS_STRING;
const body = 'This PR was created by the Combine PRs action by combining the following PRs:\n' + prString;
await github.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: 'chore(deps): Combined PR for dependabot updates',
head: '${{ github.event.inputs.combineBranchName }}',
base: '${{ steps.fetch-branch-names.outputs.base-branch }}',
body: body
});
55 changes: 55 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Run CI checks

on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [main, dev]

env:
NX_BRANCH: ${{ github.event.number }}
NX_RUN_GROUP: ${{ github.run_id }}

jobs:
build:
runs-on: ubuntu-latest
name: Building affected apps
steps:
- uses: actions/checkout@v1
- uses: bahmutov/npm-install@v1.4.5
- run: yarn nx affected --target=build --base=origin/main~1 --parallel
- uses: actions/upload-artifact@v2
with:
name: dist
path: dist

test:
runs-on: ubuntu-latest
name: Testing affected apps
steps:
- uses: actions/checkout@v1
- uses: bahmutov/npm-install@v1.4.5
- run: yarn nx affected --target=test --base=origin/main~1 --parallel

lint:
runs-on: ubuntu-latest
name: Linting affected apps
steps:
- uses: actions/checkout@v1
- uses: bahmutov/npm-install@v1.4.5
- run: yarn nx affected --target=lint --base=origin/main~1 --parallel

e2e:
runs-on: ubuntu-latest
name: E2E testing affected apps
needs: [build]
steps:
- uses: actions/checkout@v1
- uses: bahmutov/npm-install@v1.4.5
- name: Download a single artifact
continue-on-error: true
uses: actions/download-artifact@v2
with:
name: dist
path: dist
- run: yarn nx affected -- --target=e2e --base=origin/main~1 --parallel
- run: git reset --hard
60 changes: 60 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Run PR checks

on: pull_request


env:
NX_BRANCH: ${{ github.event.number }}
NX_RUN_GROUP: ${{ github.run_id }}

jobs:
build:
runs-on: ubuntu-latest
name: Building affected apps
steps:
- uses: actions/checkout@v1
- uses: bahmutov/npm-install@v1.4.5
- run: yarn nx affected -- --target=build --base=origin/main --parallel
- uses: actions/upload-artifact@v2
with:
name: dist
path: dist

test:
runs-on: ubuntu-latest
name: Testing affected apps
steps:
- uses: actions/checkout@v1
- uses: bahmutov/npm-install@v1.4.5
- run: yarn nx affected -- --target=test --base=origin/main --parallel

lint:
runs-on: ubuntu-latest
name: Linting affected apps
steps:
- uses: actions/checkout@v1
- uses: bahmutov/npm-install@v1.4.5
- run: yarn nx affected -- --target=lint --base=origin/main --parallel

commitlint:
runs-on: ubuntu-latest
name: Check commit message for consistency
steps:
- uses: actions/checkout@v1
- uses: bahmutov/npm-install@v1.4.5
- run: yarn commitlint --from ${{ github.event.pull_request.base.sha }} --to HEAD --verbose

e2e:
runs-on: ubuntu-latest
name: E2E testing affected apps
needs: [build]
steps:
- uses: actions/checkout@v1
- uses: bahmutov/npm-install@v1.4.5
- name: Download a single artifact
continue-on-error: true
uses: actions/download-artifact@v2
with:
name: dist
path: dist
- run: yarn nx affected -- --target=e2e --base=origin/main --parallel
34 changes: 34 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Run CI checks

on: workflow_dispatch

env:
NX_BRANCH: ${{ github.event.number }}
NX_RUN_GROUP: ${{ github.run_id }}

jobs:

semantic-release:
runs-on: ubuntu-latest
name: Publish packages via semantic release
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
registry-url: 'https://registry.npmjs.org'
always-auth: true,
node-version: 14
- uses: bahmutov/npm-install@v1.4.5
- name: Git Config
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
- name: Setup NPM Auth
run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
npm whoami
- name: Release
run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn commitlint --edit "$1"
70 changes: 70 additions & 0 deletions .releaserc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
module.exports = {
branches: ['main', { name: 'dev', prerelease: true }],
plugins: [
[
'@semantic-release/commit-analyzer',
{
preset: 'angular',
releaseRules: [
{ type: 'docs', release: false },
{ type: 'test', release: false },
{ scope: 'ci', release: false },
{ scope: 'repo', release: false },
{ type: 'release', release: false },
],
},
],
[
'@semantic-release/release-notes-generator',
{
presetConfig: {
types: [
{ type: 'feat', hidden: false },
{ type: 'fix', hidden: false },
{ type: 'chore', hidden: true },
{ type: 'docs', hidden: true },
{ type: 'style', hidden: true },
{ type: 'refactor', hidden: true },
{ type: 'test', hidden: true },
{ type: 'release', hidden: true },
{ scope: 'repo', hidden: true },
],
},
},
],
'@semantic-release/changelog',
[
'@semantic-release/exec',
{
prepareCmd:
'npx ts-node tools/scripts/patch-package-versions ${nextRelease.version}',
publishCmd: [
'npx ts-node tools/scripts/publish-all ${nextRelease.version} ${nextRelease.channel}',
'nx deploy docs-site',
].join(' && '),
successCmd: 'nx deploy docs-site',
},
],
[
'@semantic-release/git',
{
assets: [
'CHANGELOG.md',
'package.json',
'packages/*/package.json',
'apps/docs-site/**/*.md',
],
message:
"release: <%= nextRelease.version %> [skip ci]\n\n<%= nextRelease.notes %> \n\n<%= new Date().toLocaleDateString('en-US', {year: 'numeric', month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric' }) %>",
},
],
[
'@semantic-release/github',
{
failComment: false,
releasedLabels: false,
addReleases: 'top',
},
],
],
};

0 comments on commit 747ab76

Please sign in to comment.