Skip to content

Commit

Permalink
ci: refactor github actions (#588)
Browse files Browse the repository at this point in the history
build: refactor github actions
  • Loading branch information
holic authored Apr 11, 2023
1 parent cd224a5 commit 3eb8b70
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 150 deletions.
35 changes: 35 additions & 0 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Build
description: Common build steps used by our workflows
runs:
using: composite
steps:
- name: Build and install CLI
shell: bash
working-directory: packages/cli
run: yarn build && yarn link

- name: Run codegen
shell: bash
run: yarn codegen

- name: Outdated files detected, run `yarn codegen` and commit them
shell: bash
run: |
if [[ -n "$(git status --porcelain)" ]]; then
git status
git --no-pager diff
exit 1
fi
- name: Generate gas reports
shell: bash
run: yarn gas-report

- name: Outdated files detected, run `yarn gas-report` and commit them
shell: bash
run: |
if [[ -n "$(git status --porcelain)" ]]; then
git status
git --no-pager diff
exit 1
fi
20 changes: 20 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Setup
description: Common setup steps used by our workflows
runs:
using: composite
steps:
- name: Setup node
uses: actions/setup-node@v3
with:
node-version-file: .nvmrc
registry-url: https://registry.npmjs.org
cache: yarn

- name: Setup foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Install node dependencies
shell: bash
run: yarn install --network-concurrency 1
44 changes: 5 additions & 39 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Build

# Verifies build artifacts in pull requests.
# Note: this workflow does not trigger on pushes to main,
# because the npm workflow includes a build+verify step.
# because the release workflow includes a build+verify step.
on:
pull_request:

Expand All @@ -16,42 +16,8 @@ jobs:
with:
submodules: recursive

- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 18.x
cache: "yarn"

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Install dependencies
run: yarn install --network-concurrency 1

- name: Build and install CLI
working-directory: packages/cli
run: yarn build && yarn link

- name: Generate tables
run: yarn tablegen

- name: Outdated files detected, run `yarn tablegen` and commit them
run: |
if [[ -n "$(git status --porcelain)" ]]; then
git status
git --no-pager diff
exit 1
fi
- name: Generate gas reports
run: yarn gas-report
- name: Setup
uses: ./.github/actions/setup

- name: Outdated files detected, run `yarn gas-report` and commit them
run: |
if [[ -n "$(git status --porcelain)" ]]; then
git status
git --no-pager diff
exit 1
fi
- name: Build
uses: ./.github/actions/build
22 changes: 6 additions & 16 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ on:
branches:
- main
pull_request:
merge_group:

jobs:
docs:
runs-on: ubuntu-22.04
name: Generate docs
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Go
uses: actions/setup-go@v3
with:
Expand All @@ -20,20 +22,8 @@ jobs:
- name: Setup gomarkdoc
run: go install github.com/princjef/gomarkdoc/cmd/gomarkdoc@latest && export PATH=${PATH}:`go env GOPATH`/bin

- uses: actions/setup-node@v3
with:
node-version: 18.x

- name: git-checkout
uses: actions/checkout@v2

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Install dependencies
run: yarn install --network-concurrency 1
- name: Setup
uses: ./.github/actions/setup

- name: Prepare docs
run: yarn docs:prepare
Expand Down
77 changes: 0 additions & 77 deletions .github/workflows/npm.yml

This file was deleted.

67 changes: 67 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Release

# Releases a canary release when new commits merge to main
# Releases an official release when workflow dispactch is
# manually triggered
on:
workflow_dispatch:
push:
branches:
- main

jobs:
release:
name: Publish new release to npm
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch'
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
# The version number of a canary release comes from git describe, which counts the amount of commits from the last tag.
# Without fetch-depth: 0 only a single commit is fetched, for the ref/SHA that triggered the workflow, so the canary version is always 0.
# See https://github.com/actions/checkout
fetch-depth: 0

- name: Setup
uses: ./.github/actions/setup

- name: Build
uses: ./.github/actions/build

- name: Set deployment token
run: npm config set '//registry.npmjs.org/:_authToken' "${NPM_TOKEN}"
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Release
run: yarn release:ci

release-canary:
name: Publish canary release to npm
runs-on: ubuntu-latest
if: github.event_name != 'workflow_dispatch'
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
# The version number of a canary release comes from git describe, which counts the amount of commits from the last tag.
# Without fetch-depth: 0 only a single commit is fetched, for the ref/SHA that triggered the workflow, so the canary version is always 0.
# See https://github.com/actions/checkout
fetch-depth: 0

- name: Setup
uses: ./.github/actions/setup

- name: Build
uses: ./.github/actions/build

- name: Set deployment token
run: npm config set '//registry.npmjs.org/:_authToken' "${NPM_TOKEN}"
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Release
run: yarn release:canary --yes
21 changes: 5 additions & 16 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,18 @@ on:
push:
branches:
- main
- v2
pull_request:
merge_group:

jobs:
test:
runs-on: ubuntu-22.04
name: Run tests
runs-on: ubuntu-latest
steps:
- uses: actions/setup-node@v3
with:
node-version: 18.x
- name: Checkout
uses: actions/checkout@v3

- name: git-checkout
uses: actions/checkout@v2

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Install dependencies
run: yarn install --network-concurrency 1
- name: Setup
uses: ./.github/actions/setup

- name: Run tests
run: yarn test
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"prettier": "prettier --write 'packages/**/*.ts'",
"lint": "eslint . --ext .ts",
"release": "yarn && lerna publish --no-private --force-publish && yarn retype:updateversion",
"release:ci": "yarn && lerna publish --no-private --force-publish --yes --no-verify-access && yarn retype:updateversion",
"release:ci": "lerna publish --no-private --force-publish --yes",
"release:canary": "lerna publish premajor --canary --no-private --force-publish",
"release:manual": "node scripts/workspaceRun.mjs release",
"release:yalc": "(yarn entry:dist && yarn lerna exec npx yalc push); yarn entry:src",
Expand All @@ -84,7 +84,9 @@
"entry:dist": "yarn lerna run prepack",
"entry:src": "yarn lerna run postpack",
"gas-report": "yarn workspace @latticexyz/store run gas-report && yarn workspace @latticexyz/world run gas-report",
"tablegen": "yarn workspace @latticexyz/store run tablegen && yarn workspace @latticexyz/world run tablegen"
"codegen": "yarn codegen:tablegen && yarn codegen:worldgen",
"codegen:tablegen": "yarn workspace @latticexyz/store run tablegen && yarn workspace @latticexyz/world run tablegen",
"codegen:worldgen": "yarn workspace @latticexyz/world run worldgen"
},
"lint-staged": {
"*.ts": "eslint --cache --fix",
Expand Down

0 comments on commit 3eb8b70

Please sign in to comment.