Skip to content

Commit

Permalink
ci: add workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
janniks committed Sep 27, 2024
1 parent 0cd3cc9 commit 96453c3
Show file tree
Hide file tree
Showing 11 changed files with 10,268 additions and 8,324 deletions.
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 }}
13 changes: 0 additions & 13 deletions config/semantic-release.version.mjs

This file was deleted.

5 changes: 5 additions & 0 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"version": "independent",
"packages": ["."]
}
Loading

0 comments on commit 96453c3

Please sign in to comment.