Skip to content
This repository has been archived by the owner on Apr 1, 2024. It is now read-only.

Commit

Permalink
Add .github
Browse files Browse the repository at this point in the history
  • Loading branch information
fardjad committed May 26, 2023
1 parent 0d0e1b0 commit 0e23da6
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
open-pull-requests-limit: 10

- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "daily"
open-pull-requests-limit: 10
107 changes: 107 additions & 0 deletions .github/workflows/test-and-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: test-and-release

on:
push:
branches:
- master
paths-ignore:
- "examples/**"
- "media/**"
- "scripts/**"
- "LICENSE"
pull_request:
paths-ignore:
- "examples/**"
- "media/**"
- "scripts/**"
- "LICENSE"

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node: [18, 19, 20]
fail-fast: true
steps:
- uses: actions/checkout@main
- uses: actions/setup-node@main
with:
node-version: ${{ matrix.node }}
- name: Cache node modules
uses: actions/cache@main
env:
cache-name: cache-node-${{ matrix.node }}-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install
run: npm ci
- name: Tests
run: npm test
version-check:
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/master'
outputs:
changed: ${{ steps.check.outputs.changed }}
version: ${{ steps.check.outputs.version }}
steps:
- uses: actions/checkout@main
- id: check
uses: EndBug/version-check@v2
with:
diff-search: true
token: ${{ secrets.GITHUB_TOKEN }}
release:
runs-on: ubuntu-latest
needs: version-check
if: needs.version-check.outputs.changed == 'true'
steps:
- uses: actions/checkout@main
# https://github.com/rickstaa/action-create-tag/issues/10
- name: "Change perms on GITHUB_WORKSPACE"
run: |
sudo chown -R root:root $GITHUB_WORKSPACE
sudo chmod -R 0777 $GITHUB_WORKSPACE
- uses: rickstaa/action-create-tag@main
with:
tag: v${{ needs.version-check.outputs.version }}
message: v${{ needs.version-check.outputs.version }}
- uses: ncipollo/release-action@main
with:
name: v${{ needs.version-check.outputs.version }}
tag: v${{ needs.version-check.outputs.version }}
token: ${{ secrets.GITHUB_TOKEN }}
npm-publish:
runs-on: ubuntu-latest
needs: release
if: needs.version-check.outputs.changed == 'true'
steps:
- uses: actions/checkout@main
- uses: actions/setup-node@main
with:
node-version: 18
registry-url: "https://registry.npmjs.org"
- uses: actions/cache@main
env:
cache-name: cache-node-${{ matrix.node }}-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install
run: |
set -e
npm ci
- name: Publish
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
82 changes: 82 additions & 0 deletions .github/workflows/upgrade-dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: upgrade-dependencies

on:
workflow_dispatch: {}
schedule:
- cron: "0 0 * * *"

jobs:
upgrade-deps:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- uses: actions/setup-node@main
with:
node-version: 18
- name: Cache node modules
uses: actions/cache@main
env:
cache-name: cache-node-${{ matrix.node }}-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Setup Git
run: |
git config --local user.name "github-actions[bot]"
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local pull.rebase true
# work around "insufficient permission for adding an object to repository database .git/object" issue
sudo chmod -R ugo+rwX .git
- name: Check for updates
id: check-updates
run: |
set -ex
npm ci &> /dev/null
npx ncu
npm i &> /dev/null
npm audit fix --quiet --no-progress --no-fund || true
npm run fix &> /dev/null || true
git add -u
git update-index --refresh
if ! git diff-index --quiet HEAD --; then
echo "is-changed=1" >> $GITHUB_OUTPUT
fi
- name: Create a PR
if: steps.check-updates.outputs.is-changed
id: create-pr
run: |
npm version patch
PKG_VERSION="$(node -e 'process.stdout.write(require("./package.json").version)')"
REMOTE_REPO="https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
CURRENT_BRANCH="$(git branch --show-current)"
NEW_BRANCH="v${PKG_VERSION}"
if git ls-remote --exit-code --heads "${REMOTE_REPO}" "${NEW_BRANCH}" > /dev/null; then
# PR already exists
exit 0
fi
git commit -a -m "${PKG_VERSION}" --no-verify
git pull "${REMOTE_REPO}" "${CURRENT_BRANCH}"
git checkout -b "${NEW_BRANCH}"
git push "${REMOTE_REPO}" "HEAD:${NEW_BRANCH}"
PR_URL=$(gh pr create -B "${CURRENT_BRANCH}" -H "${NEW_BRANCH}" -f)
echo "pr-url=${PR_URL}" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Approve and merge the PR
if: steps.create-pr.outputs.pr-url
run: |
gh pr review --approve "${PR_URL}"
gh pr merge --auto --delete-branch --rebase "${PR_URL}"
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
PR_URL: ${{ steps.create-pr.outputs.pr-url }}

0 comments on commit 0e23da6

Please sign in to comment.