Skip to content

Commit 808ad8a

Browse files
committed
Initial commit
0 parents  commit 808ad8a

22 files changed

+9772
-0
lines changed

.eslintrc.cjs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module.exports = {
2+
parser: "@typescript-eslint/parser",
3+
extends: ["plugin:unicorn/recommended", "xo", "prettier"],
4+
ignorePatterns: ["dist", "coverage"],
5+
rules: {},
6+
overrides: [
7+
{
8+
files: ["*.ts", "*.cts", "*.mts", "*.d.ts"],
9+
extends: [
10+
"plugin:unicorn/recommended",
11+
"xo",
12+
"xo-typescript",
13+
"prettier",
14+
],
15+
plugins: ["@typescript-eslint"],
16+
rules: {},
17+
},
18+
],
19+
};

.github/dependabot.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
open-pull-requests-limit: 10
8+
9+
- package-ecosystem: "npm"
10+
directory: "/"
11+
schedule:
12+
interval: "daily"
13+
open-pull-requests-limit: 10
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: test-and-release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths-ignore:
8+
- "media/**"
9+
- "LICENSE"
10+
pull_request:
11+
paths-ignore:
12+
- "media/**"
13+
- "LICENSE"
14+
15+
jobs:
16+
test:
17+
runs-on: ubuntu-latest
18+
strategy:
19+
matrix:
20+
node: ["18", "19", "20"]
21+
fail-fast: true
22+
steps:
23+
- uses: actions/checkout@main
24+
- uses: actions/setup-node@main
25+
with:
26+
node-version: ${{ matrix.node }}
27+
- name: Cache node modules
28+
uses: actions/cache@main
29+
env:
30+
cache-name: cache-node-${{ matrix.node }}-modules
31+
with:
32+
path: ~/.npm
33+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
34+
restore-keys: |
35+
${{ runner.os }}-build-${{ env.cache-name }}-
36+
${{ runner.os }}-build-
37+
${{ runner.os }}-
38+
- name: Install
39+
run: npm ci
40+
- name: Tests
41+
run: npm test
42+
version-check:
43+
runs-on: ubuntu-latest
44+
needs: test
45+
if: github.ref == 'refs/heads/main'
46+
outputs:
47+
changed: ${{ steps.check.outputs.changed }}
48+
version: ${{ steps.check.outputs.version }}
49+
steps:
50+
- uses: actions/checkout@main
51+
- id: check
52+
uses: EndBug/version-check@v2
53+
with:
54+
diff-search: true
55+
token: ${{ secrets.GITHUB_TOKEN }}
56+
release:
57+
runs-on: ubuntu-latest
58+
needs: version-check
59+
if: needs.version-check.outputs.changed == 'true'
60+
steps:
61+
- uses: actions/checkout@main
62+
- name: "Add $GITHUB_WORKSPACE to git safe directories"
63+
run: |
64+
git config --global --add safe.directory $GITHUB_WORKSPACE || exit 1
65+
- uses: rickstaa/action-create-tag@main
66+
with:
67+
tag: v${{ needs.version-check.outputs.version }}
68+
message: v${{ needs.version-check.outputs.version }}
69+
- uses: ncipollo/release-action@main
70+
with:
71+
name: v${{ needs.version-check.outputs.version }}
72+
tag: v${{ needs.version-check.outputs.version }}
73+
token: ${{ secrets.GITHUB_TOKEN }}
74+
npm-publish:
75+
runs-on: ubuntu-latest
76+
needs: release
77+
if: needs.version-check.outputs.changed == 'true'
78+
steps:
79+
- uses: actions/checkout@main
80+
- uses: actions/setup-node@main
81+
with:
82+
node-version: 18
83+
registry-url: "https://registry.npmjs.org"
84+
- uses: actions/cache@main
85+
env:
86+
cache-name: cache-node-${{ matrix.node }}-modules
87+
with:
88+
path: ~/.npm
89+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
90+
restore-keys: |
91+
${{ runner.os }}-build-${{ env.cache-name }}-
92+
${{ runner.os }}-build-
93+
${{ runner.os }}-
94+
- name: Install
95+
run: |
96+
set -e
97+
npm ci
98+
- name: Publish
99+
run: npm publish
100+
env:
101+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: upgrade-dependencies
2+
3+
on:
4+
workflow_dispatch: {}
5+
schedule:
6+
- cron: "0 0 * * *"
7+
8+
jobs:
9+
upgrade-deps:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@main
13+
- uses: actions/setup-node@main
14+
with:
15+
node-version: 18
16+
- name: Cache node modules
17+
uses: actions/cache@main
18+
env:
19+
cache-name: cache-node-${{ matrix.node }}-modules
20+
with:
21+
path: ~/.npm
22+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
23+
restore-keys: |
24+
${{ runner.os }}-build-${{ env.cache-name }}-
25+
${{ runner.os }}-build-
26+
${{ runner.os }}-
27+
- name: Setup Git
28+
run: |
29+
git config --local user.name "github-actions[bot]"
30+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
31+
git config --local pull.rebase true
32+
33+
# work around "insufficient permission for adding an object to repository database .git/object" issue
34+
sudo chmod -R ugo+rwX .git
35+
- name: Check for updates
36+
id: check-updates
37+
run: |
38+
set -ex
39+
npm ci &> /dev/null
40+
npx ncu
41+
npm i &> /dev/null
42+
npm audit fix --quiet --no-progress --no-fund || true
43+
npm run fix &> /dev/null || true
44+
45+
git add -u
46+
git update-index --refresh
47+
if ! git diff-index --quiet HEAD --; then
48+
echo "is-changed=1" >> $GITHUB_OUTPUT
49+
fi
50+
- name: Create a PR
51+
if: steps.check-updates.outputs.is-changed
52+
id: create-pr
53+
run: |
54+
npm version patch
55+
PKG_VERSION="$(node -e 'process.stdout.write(require("./package.json").version)')"
56+
57+
REMOTE_REPO="https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
58+
CURRENT_BRANCH="$(git branch --show-current)"
59+
NEW_BRANCH="v${PKG_VERSION}"
60+
61+
if git ls-remote --exit-code --heads "${REMOTE_REPO}" "${NEW_BRANCH}" > /dev/null; then
62+
# PR already exists
63+
exit 0
64+
fi
65+
66+
git commit -a -m "${PKG_VERSION}" --no-verify
67+
git pull "${REMOTE_REPO}" "${CURRENT_BRANCH}"
68+
git checkout -b "${NEW_BRANCH}"
69+
git push "${REMOTE_REPO}" "HEAD:${NEW_BRANCH}"
70+
71+
PR_URL=$(gh pr create -B "${CURRENT_BRANCH}" -H "${NEW_BRANCH}" -f)
72+
echo "pr-url=${PR_URL}" >> $GITHUB_OUTPUT
73+
env:
74+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
75+
- name: Approve and merge the PR
76+
if: steps.create-pr.outputs.pr-url
77+
run: |
78+
gh pr review --approve "${PR_URL}"
79+
gh pr merge --auto --delete-branch --rebase "${PR_URL}"
80+
env:
81+
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
82+
PR_URL: ${{ steps.create-pr.outputs.pr-url }}

0 commit comments

Comments
 (0)