Skip to content

Commit

Permalink
ci: config github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
jzhangdev committed Jan 11, 2024
1 parent 80846a8 commit 4d3d81b
Show file tree
Hide file tree
Showing 5 changed files with 265 additions and 0 deletions.
92 changes: 92 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
install:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v4
with:
node-version-file: .node-version
cache: pnpm
- run: pnpm install

test:
needs: install
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v4
with:
node-version-file: .node-version
cache: pnpm
- run: pnpm install

- name: Lint
run: pnpm run lint

check-workflow-files:
needs: install
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker://rhysd/actionlint:1.6.26
with:
args: -color

build:
needs: [test, check-workflow-files]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v4
with:
node-version-file: .node-version
cache: pnpm
- run: pnpm install
- run: pnpm run build

publish:
if: ${{ always() && !failure() && !cancelled() }}
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v4
with:
node-version-file: .node-version
cache: pnpm
- run: pnpm install

- name: Publish (development)
if: github.event.pull_request.head.repo.full_name == 'RightCapitalHQ/verdaccio-package-diff' && github.base_ref == github.event.repository.default_branch
env:
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
HEAD_REF: ${{ github.head_ref }}
run: |
npm config set //registry.npmjs.org/:_authToken "${NPM_TOKEN}"
preid="${HEAD_REF//\//-}".${{ github.run_number }}.${{ github.run_attempt }}
pnpm exec npm --no-git-tag-version version prerelease --preid="${preid}"
pnpm publish --no-git-checks --access public --tag development
- name: Publish (main)
if: github.repository == 'RightCapitalHQ/verdaccio-package-diff' && github.event_name == 'push' && github.ref_name == github.event.repository.default_branch
env:
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
run: |
npm config set //registry.npmjs.org/:_authToken "${NPM_TOKEN}"
git config --local user.email "[email protected]"
git config --local user.name "GitHub Actions[bot]"
git remote set-url origin "https://${{ secrets.REPO_AUTOMATION_TOKEN }}@github.com/${{ github.repository }}.git"
pnpm beachball publish --yes -m 'chore(release): applying package updates'
10 changes: 10 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
extends: default

rules:
comments:
require-starting-space: false
min-spaces-from-content: 1
document-start:
present: false
line-length: false
48 changes: 48 additions & 0 deletions beachball.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import type { BeachballConfig } from 'beachball';

const config: BeachballConfig = {
access: 'public',
registry: 'https://registry.npmjs.org',
ignorePatterns: [
'.*ignore',
'.yamllint',
'.eslintrc.cjs',
'.pnpm-store/**',
'.vscode/**',
'prettier.config.cjs',
'pnpm-lock.yaml',
],
changelog: {
customRenderers: {
// eslint-disable-next-line @typescript-eslint/require-await
async renderChangeTypeHeader(changeType, renderInfo) {
const changelogDate = renderInfo.newVersionChangelog.date
.toLocaleDateString('zh-CN')
.replace(/\//g, '-');
const heading =
changeType === 'major' || changeType === 'minor' ? '##' : '###';
return `${heading} [${
renderInfo.newVersionChangelog.version
}](https://github.com/RightCapitalHQ/verdaccio-package-diff/tree/${encodeURIComponent(
renderInfo.newVersionChangelog.tag,
)}) (${changelogDate})`;
},
// Original template: https://github.com/microsoft/beachball/blob/aefbc1ac37ee85961cc787133c827f1fd3925550/src/changelog/renderPackageChangelog.ts#L93
// eslint-disable-next-line @typescript-eslint/require-await
async renderEntry(entry) {
if (entry.author === 'beachball') {
return `- ${entry.comment}`;
}
// Imitate GitHub's commit format https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/autolinked-references-and-urls#commit-shas
return `- ${entry.comment} ([${entry.commit.substring(
0,
7,
)}](https://github.com/RightCapitalHQ/verdaccio-package-diff/commit/${
entry.commit
}))`;
},
},
},
};

export default config;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"@types/express": "4.17.21",
"@types/node": "20",
"@verdaccio/types": "10.8.0",
"beachball": "2.39.0",
"commitizen": "4.3.0",
"eslint": "8.56.0",
"husky": "8.0.3",
Expand Down
114 changes: 114 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4d3d81b

Please sign in to comment.