From 31dcaae0d3b874669538c4baa5499e0697a41edc Mon Sep 17 00:00:00 2001 From: janniks Date: Tue, 14 Jun 2022 13:59:05 +0200 Subject: [PATCH] ci: add changeset version model --- .github/workflows/circular.dep.check.yml | 37 ------------ .github/workflows/lint.yml | 37 ------------ .github/workflows/publish.yml | 46 ++++++++++++++ .github/workflows/publish_beta.yml | 58 ++++++++++++++++++ .github/workflows/pull_request.yml | 77 ++++++++++++++++++++++++ .github/workflows/release.yml | 61 ------------------- .github/workflows/tests.yml | 43 ------------- .github/workflows/typecheck.yml | 37 ------------ .github/workflows/version.yml | 45 ++++++++++++++ 9 files changed, 226 insertions(+), 215 deletions(-) delete mode 100644 .github/workflows/circular.dep.check.yml delete mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/publish_beta.yml create mode 100644 .github/workflows/pull_request.yml delete mode 100644 .github/workflows/release.yml delete mode 100644 .github/workflows/tests.yml delete mode 100644 .github/workflows/typecheck.yml create mode 100644 .github/workflows/version.yml diff --git a/.github/workflows/circular.dep.check.yml b/.github/workflows/circular.dep.check.yml deleted file mode 100644 index 8541bdfe..00000000 --- a/.github/workflows/circular.dep.check.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: circular dependency checks - -on: - push: - branches: - - '**' - - pull_request: -jobs: - lint: - runs-on: ubuntu-latest - env: - NODE_OPTIONS: --max-old-space-size=4096 - steps: - - uses: actions/checkout@v2 - - - name: Set Node Version - uses: actions/setup-node@v2 - with: - node-version: 16 - - - name: Restore lerna cache - uses: actions/cache@v2 - with: - path: | - node_modules - packages/*/node_modules - key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json') }} - - - name: Install dependencies - run: npm i - - - name: Bootstrap - run: npm run bootstrap - - - name: List circular dependencies - run: npm run madge diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 0c4b649c..00000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: lint - -on: - push: - branches: - - '**' - - pull_request: -jobs: - lint: - runs-on: ubuntu-latest - env: - NODE_OPTIONS: --max-old-space-size=4096 - steps: - - uses: actions/checkout@v2 - - - name: Set Node Version - uses: actions/setup-node@v2 - with: - node-version: 16 - - - name: Restore lerna cache - uses: actions/cache@v2 - with: - path: | - node_modules - packages/*/node_modules - key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json') }} - - - name: Install dependencies - run: npm i - - - name: Bootstrap - run: npm run bootstrap - - - name: Lint - run: npm run lint diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..98b16b0b --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,46 @@ +name: publish + +on: + push: + branches: + - master + tags-ignore: + - "**" + + workflow_dispatch: + +jobs: + pre_run: + runs-on: ubuntu-latest + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@ad6cb1b847ffb509a69b745b6ee2f1d14dfe14b8 + with: + access_token: ${{ github.token }} + + publish_beta: + runs-on: ubuntu-latest + needs: pre_run + if: "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: 16 + cache: npm + + - run: npm ci + - run: npm run bootstrap + + - run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Publish + run: | + NODE_ENV=production npx lerna publish from-package --no-verify-access --yes + export RELEASE=$(cat lerna.json | jq -r '.version') + git tag -a v$RELEASE -m v$RELEASE + git push origin v$RELEASE diff --git a/.github/workflows/publish_beta.yml b/.github/workflows/publish_beta.yml new file mode 100644 index 00000000..d7b70bc6 --- /dev/null +++ b/.github/workflows/publish_beta.yml @@ -0,0 +1,58 @@ +name: publish-beta + +on: + push: + branches: + - master + tags-ignore: + - "**" + + workflow_dispatch: + +jobs: + pre_run: + runs-on: ubuntu-latest + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@ad6cb1b847ffb509a69b745b6ee2f1d14dfe14b8 + with: + access_token: ${{ github.token }} + + publish_beta: + runs-on: ubuntu-latest + needs: pre_run + if: "!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: 16 + cache: npm + + - run: npm ci + - run: npm run bootstrap + + - run: git config --local user.email 'action@github.com' + - 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: | + npx lerna-from-npm + git tag -d `git tag | grep -E 'beta'` + npx lerna version --conventional-commits --conventional-prerelease --preid beta --no-push --no-git-tag-version --yes + git commit -a -m 'DONT PUSH' + npx lerna publish from-package --no-verify-access --pre-dist-tag beta --yes + export RELEASE=$(cat lerna.json | jq -r '.version') + git reset HEAD~ --hard + git tag v$RELEASE + git push origin v$RELEASE diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml new file mode 100644 index 00000000..091cc691 --- /dev/null +++ b/.github/workflows/pull_request.yml @@ -0,0 +1,77 @@ +name: pull-request +on: [pull_request, workflow_dispatch] + +jobs: + pre_run: + runs-on: ubuntu-latest + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@ad6cb1b847ffb509a69b745b6ee2f1d14dfe14b8 + with: + access_token: ${{ github.token }} + + code_checks: + runs-on: ubuntu-latest + needs: pre_run + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 16 + cache: npm + - run: npm ci + - name: Bootstrap lerna + run: npm run bootstrap + - name: Check bootstrap + run: | + if [[ -n $(git status -s) ]]; then + git status + echo "Error: file tree is not clean; Likely needs bootstraping" + echo "Run `npm run bootstrap` and commit to resolve" + exit 1 + fi + - run: npm run lint + - run: npm run typecheck + - name: Check for circular dependencies + run: npm run madge + - run: npm run lerna run test --stream --parallel -- -- --coverage + - uses: codecov/codecov-action@v1 + + 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 }} + + publish_npm_pr: + runs-on: ubuntu-latest + needs: [pre_run, check_fork] + if: needs.check_fork.outputs.is_not_fork == 'true' + steps: + - uses: actions/checkout@v3 + if: github.event_name == 'pull_request' + with: + ref: ${{ github.event.pull_request.head.ref }} + - uses: actions/checkout@v3 + if: github.event_name == 'workflow_dispatch' + - uses: actions/setup-node@v3 + with: + node-version: 16 + cache: npm + - run: npm ci + - run: npm run bootstrap + - 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 prepatch --preid pr.$SHA --dist-tag pr --no-verify-access --no-push --no-git-tag-version --yes + env: + SHA: ${{ steps.git-commit.outputs.sha }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 526bedb2..00000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,61 +0,0 @@ -name: release beta - -on: - push: - branches: - - master - tags-ignore: - - "**" - paths-ignore: - - "**/CHANGELOG.md" - -jobs: - release: - name: Release Beta - runs-on: macos-latest - if: github.event_name == 'push' - steps: - - uses: actions/checkout@v2 - with: - # pulls all commits (needed for lerna / semantic release to correctly version) - fetch-depth: "0" - - # pulls all tags (needed for lerna / semantic release to correctly version) - - run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* - - - name: Set Node Version - uses: actions/setup-node@v2 - with: - node-version: 16 - - - name: Install dependencies - run: npm ci - - - name: Bootstrap - run: | - npx lerna bootstrap - if [[ -n $(git status -s) ]]; then - echo "Error: file tree is not clean" - git status - exit 1 - fi - - - name: Test - run: npm run test - - - name: Build - run: NODE_ENV=production npm run build - - - name: "Release" - run: | - npx lerna-from-npm - npx lerna version --conventional-commits --conventional-prerelease --preid beta --no-push --no-git-tag-version --yes - git commit -a -m 'DONT PUSH' - echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc - npx lerna publish from-package --no-verify-access --pre-dist-tag beta --yes - export RELEASE=$(cat lerna.json | jq -r '.version') - git reset HEAD~ --hard - git tag v$RELEASE - git push origin v$RELEASE - env: - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml deleted file mode 100644 index d12988b5..00000000 --- a/.github/workflows/tests.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: tests - -on: - push: - branches: - - '**' - - pull_request: -jobs: - tests: - runs-on: ubuntu-latest - env: - NODE_OPTIONS: --max-old-space-size=4096 - steps: - - uses: actions/checkout@v2 - - - name: Set Node Version - uses: actions/setup-node@v2 - with: - node-version: 16 - - - name: Restore lerna cache - uses: actions/cache@v2 - with: - path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - - name: Install dependencies - run: npm i - - - name: Bootstrap - run: npm run bootstrap - - - name: Build - run: npm run build - - - name: Tests - run: npm run lerna run test --stream --parallel -- -- --coverage - - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v1 diff --git a/.github/workflows/typecheck.yml b/.github/workflows/typecheck.yml deleted file mode 100644 index 0456c40c..00000000 --- a/.github/workflows/typecheck.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: typecheck - -on: - push: - branches: - - '**' - - pull_request: -jobs: - typecheck: - runs-on: ubuntu-latest - env: - NODE_OPTIONS: --max-old-space-size=4096 - steps: - - uses: actions/checkout@v2 - - - name: Set Node Version - uses: actions/setup-node@v2 - with: - node-version: 16 - - - name: Restore lerna cache - uses: actions/cache@v2 - with: - path: | - node_modules - packages/*/node_modules - key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json') }} - - - name: Install dependencies - run: npm i - - - name: Bootstrap - run: npm run bootstrap - - - name: Typecheck - run: npm run typecheck diff --git a/.github/workflows/version.yml b/.github/workflows/version.yml new file mode 100644 index 00000000..d76fc83e --- /dev/null +++ b/.github/workflows/version.yml @@ -0,0 +1,45 @@ +name: version + +on: + push: + branches: + - master + tags-ignore: + - "**" + + workflow_dispatch: + +jobs: + pre_run: + runs-on: ubuntu-latest + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@ad6cb1b847ffb509a69b745b6ee2f1d14dfe14b8 + with: + access_token: ${{ github.token }} + + publish_beta: + runs-on: ubuntu-latest + needs: pre_run + 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: 16 + cache: npm + + - run: npm ci + - run: npm run bootstrap + + - name: Create Release Pull Request + uses: changesets/action@v1 + with: + version: git tag -d `git tag | grep -E 'beta'` && npx lerna version --conventional-commits --no-push --no-git-tag-version --yes + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}