Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: continue repo setup #1

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*.{js,ts,json}]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
1 change: 1 addition & 0 deletions .github/.husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx @commitlint/cli --extends @commitlint/config-conventional --edit $1
16 changes: 16 additions & 0 deletions .github/workflows/add-issues-to-project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Add new issues to DevTools project

on:
issues:
types:
- opened

jobs:
add-to-project:
name: Add issue to project
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
project-url: https://github.com/orgs/hirosystems/projects/15
github-token: ${{ secrets.GH_TOKEN }}
28 changes: 28 additions & 0 deletions .github/workflows/pre-run.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: pre-run
on:
workflow_call:
outputs:
is-not-fork:
description: "Is the repository the original project"
value: ${{ jobs.check-fork.outputs.is_not_fork }}

workflow_dispatch:

jobs:
cancel-previous:
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@ad6cb1b847ffb509a69b745b6ee2f1d14dfe14b8
with:
access_token: ${{ github.token }}

check-fork:
runs-on: ubuntu-latest
outputs:
is_not_fork: ${{ steps.check.outputs.is_not_fork }}
steps:
- id: check
run: echo "::set-output name=is_not_fork::${{ env.NPM_TOKEN != '' }}"
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
57 changes: 57 additions & 0 deletions .github/workflows/publish-beta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: publish-beta

on:
push:
branches:
- main
tags-ignore:
- '**'
paths-ignore:
- '**.md'

workflow_dispatch:

jobs:
pre-run:
uses: ./.github/workflows/pre-run.yml
secrets: inherit

publish-beta:
runs-on: ubuntu-latest
needs: pre-run
if: "needs.pre-run.outputs.is-not-fork == 'true' && !contains(github.event.head_commit.message, 'chore: version packages')"
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

# pulls all tags (needed for lerna to correctly version)
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*

- uses: actions/setup-node@v3
with:
node-version: 18
cache: npm

- run: npm install -g npm@latest
- run: npm ci

- run: git config --local user.email '[email protected]'
- run: git config --local user.name 'GitHub Action'

- run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Version & Publish
run: |
LATEST=$(git describe --tags --abbrev=0)
npx lerna version $LATEST --force-publish --no-changelog --no-push --no-git-tag-version --yes
git commit -a -m 'DONT PUSH: fast-forward to latest npm release' --allow-empty --no-verify
npx lerna version --force-publish --no-changelog --conventional-commits --conventional-prerelease --preid beta --no-push --no-git-tag-version --yes
git commit -a -m 'DONT PUSH: version beta release' --allow-empty --no-verify
RELEASE=$(cat lerna.json | jq -r '.version')
npx lerna publish from-package --no-verify-access --pre-dist-tag beta --yes
git reset HEAD~2 --hard
git tag v$RELEASE
git push origin v$RELEASE
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: publish

on:
push:
branches:
- main
tags-ignore:
- '**'
paths-ignore:
- '**.md'

workflow_dispatch:

jobs:
pre-run:
uses: ./.github/workflows/pre-run.yml
secrets: inherit

publish:
runs-on: ubuntu-latest
needs: pre-run
if: "needs.pre-run.outputs.is-not-fork == 'true' && (github.event_name == 'workflow_dispatch' || contains(github.event.head_commit.message, 'chore: version packages'))"
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: 18
cache: npm

- run: npm install -g npm@latest
- run: npm ci
- run: npm run build

- run: git config --local user.email '[email protected]'
- run: git config --local user.name 'GitHub Action'

- run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish
run: |
npx lerna publish from-package --no-verify-access --yes
RELEASE=$(cat package.json | jq -r '.version')
git tag -a v$RELEASE -m v$RELEASE
git push origin v$RELEASE
71 changes: 71 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: pull-request
on:
pull_request:
paths-ignore:
- '**.md'

workflow_dispatch:

jobs:
pre-run:
uses: ./.github/workflows/pre-run.yml
secrets: inherit

commitlint:
runs-on: ubuntu-latest
needs: pre-run
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: wagoid/commitlint-github-action@v5

tests:
needs: pre-run
uses: ./.github/workflows/tests.yml
secrets: inherit

publish-pr:
runs-on: ubuntu-latest
needs: [pre-run, tests]
if: needs.pre-run.outputs.is-not-fork == 'true'
steps:
- uses: actions/checkout@v3
if: github.event_name == 'pull_request'
with:
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
- uses: actions/checkout@v3
if: github.event_name == 'workflow_dispatch'
with:
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: 18
cache: npm
- run: npm install -g npm@latest
- run: npm ci
- id: git-commit
run: echo "::set-output name=sha::$(git rev-parse --short HEAD)"
- run: echo $SHA
env:
SHA: ${{ steps.git-commit.outputs.sha }}
- run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- run: npx lerna publish --canary --force-publish --preid pr.$SHA --dist-tag pr --no-verify-access --no-push --no-git-tag-version --yes
env:
SHA: ${{ steps.git-commit.outputs.sha }}
SKIP_TESTS: true
- id: published-version
run: echo "::set-output name=version::$(cat lerna.json | jq -r '.version')"
- uses: janniks/[email protected]
with:
header: "> This PR was published to npm with the version `${{ steps.published-version.outputs.version }}`\n> e.g. `npm install @stacks/common@${{ steps.published-version.outputs.version }} --save-exact`"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: |
git reset --hard
npx lerna publish --canary --force-publish --preid $BRANCH --dist-tag $BRANCH --no-verify-access --no-push --no-git-tag-version --yes
if: ${{ (github.head_ref || github.ref_name) == 'nakamoto' || (github.head_ref || github.ref_name) == 'next' }}
env:
BRANCH: ${{ github.head_ref || github.ref_name }}
37 changes: 37 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: tests
on:
push:
branches:
- main
tags-ignore:
- '**'

workflow_call:
workflow_dispatch:

jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
cache: npm

- run: npm install -g npm@latest
- run: npm ci

- name: Run lint
run: npm run lint

- name: Run typecheck
run: npm run typecheck

- name: Run tests
run: npm run test

- name: Upload test coverage
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
57 changes: 57 additions & 0 deletions .github/workflows/version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: version

on:
push:
branches:
- main
tags-ignore:
- '**'
paths-ignore:
- '**.md'

workflow_dispatch:

env:
COMMIT_USER: Hiro DevOps
COMMIT_EMAIL: [email protected]

jobs:
pre-run:
uses: ./.github/workflows/pre-run.yml
secrets: inherit

version:
runs-on: ubuntu-latest
needs: pre-run
if: "needs.pre-run.outputs.is-not-fork == 'true' && !contains(github.event.head_commit.message, 'chore: version packages')"
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: main

- uses: actions/setup-node@v3
with:
node-version: 18
cache: npm

- run: npm install -g npm@latest
- run: npm ci

# workaround for changesets/action to allow not using changesets
# todo: add `force` option on fork to allow removing this workaround
- run: |
npx changeset init
npx changeset --empty
echo '.changeset/' >> .git/info/exclude

- run: git tag -d $(git tag | grep 'beta')

- name: Create Release Pull Request
uses: janniks/changesets-action@main
with:
title: 'chore: version packages'
commit: 'chore: version packages'
version: 'npm run ci:version'
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }}
Loading
Loading