Code Monkey home page Code Monkey logo

shared-config's Introduction

Shared Config (by The Guild)

This repository is a collection of configurations, tools and examples, that demonstrate how The Guild is using their libs.

We use the files stored here in our other repositories, to have a single point of truth for all configurations/pipelines needed.

Step 1: changesets

To setup automated release flow for your package, using changesets:

  1. Create a monorepo, either by using yarn (v1) or pnpm.
  2. Install and initialize the Changesets config by following these instructions: https://github.com/changesets/changesets/blob/main/docs/intro-to-using-changesets.md (also make sure to install @changesets/changelog-github)

Make sure to adjust you Changesets config file, based on your repo setup:

{
  "$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
  "changelog": [
    "@changesets/changelog-github", // this will make nice output for changesets, with "thank you..." notes, and links to the commits + references in PRs!
    { "repo": "guild-member/project-repo" } // Set the repo name here
  ],
  "commit": false,
  "linked": [],
  "access": "public",
  "baseBranch": "master", // change if needed
  "updateInternalDependencies": "patch",
  "ignore": ["website"] // change if needed
}
  1. Configure your monorepo packages correctly, you should make sure to have the following in your package.json:
{
  "publishConfig": {
    "directory": "dist",
    "access": "public"
  }
}

If you are not using a bundler/build flow, make sure to change the directory value if needed.

  1. Configure Changesets scripts for the release/PR flows. You should have a script called release, that basically prepares the package for publishing, and then call changesets CLI to do the actual publishing:
{
  "scripts": {
    "release": "yarn build && changeset publish"
  }
}
  1. Install Changesets Bot on your repo: https://github.com/apps/changeset-bot
Step 2: Repository Settings

Configure GitHub Actions permissions: Go to repo Settings > Actions > General and make sure to configure the following:

  • Actions permissions should be set to Allow all actions and reusable workflows
  • Workflow permissions should be set to Read and write permissions, and make sure the Allow GitHub Actions to create and approve pull requests option is active.
Step 3: Unified secrets

You can create an NPM publishing token by using npm token create.

After creating your token, make sure to add it as part of your GitHub Actions Secrets (under repo Settings). Name it NPM_TOKEN.

In addition, the shared pipelines are going to use GITHUB_TOKEN provided by GitHub Actions runtime. You can customize it by creating a custom PAT token for the user you wish to use.

Step 4: Automatic Stable Release

Create a GitHub Actions that refers to the workflow defined in this repo, along with your settings:

name: release
on:
  push:
    branches:
      - master # change to main if needed

jobs:
  stable:
    uses: the-guild-org/shared-config/.github/workflows/release-stable.yml@main
    with:
      releaseScript: release # script to run as part of publish command
      nodeVersion: 18 # you can change if needed
    secrets:
      githubToken: ${{ secrets.GITHUB_TOKEN }}
      npmToken: ${{ secrets.NPM_TOKEN }}

By default, we use aggregated release mode.

Step 5: Snapshot release for Pull Requests

To setup automated release flow for your package, using changesets, based on PR changes, use the following setup:

Start by updating your changesets config.json to use the following:

{
  // ... other stuff
  "snapshot": {
    "useCalculatedVersion": true,
    "prereleaseTemplate": "{tag}-{datetime}-{commit}"
  }
}

You can customize the canary release template, see: https://github.com/changesets/changesets/blob/main/docs/config-file-options.md#prereleasetemplate-optional-string

Create a GitHub workflow (you can call it pr.yaml):

name: pr
on:
  pull_request:
    branches:
      - master # change if needed

jobs:
  release:
    uses: the-guild-org/shared-config/.github/workflows/release-snapshot.yml@main
    with:
      npmTag: alpha
      buildScript: build
      nodeVersion: 18
    secrets:
      githubToken: ${{ secrets.GITHUB_TOKEN }}
      npmToken: ${{ secrets.NPM_TOKEN }}

You can choose the NPM tag of the release. We prefer using alpha or canary for PR-based releases.

Step 6: Renovate
  1. Install Renovate Bot on your repo: https://github.com/marketplace/renovate
  2. Wait for Renovate to create the first setup PR and merge it.
  3. Create renovate.json config file in the repo, with the following:
{
  "extends": ["github>the-guild-org/shared-config:renovate"]
}
Step 7: Automatic changesets for dependencies updates

To get automatic changesets created for Renovate PRs (and manual dependencies changes), add the following GitHub Action workflow to your repo:

Note: you can also add this to the existing pr.yaml if you are using the snapshot release.

name: pr
on:
  pull_request:
    branches:
      - master # change if needed

jobs:
  dependencies:
    uses: the-guild-org/shared-config/.github/workflows/changesets-dependencies.yaml@main
    secrets:
      githubToken: ${{ secrets.GITHUB_TOKEN }}
Step 9: ESLint/Prettier config

If you wish to use the unified config for eslint or prettier, following these instructions:

Step 10: ESLint pipeline

If you wish to have a lint using ESLint and report the results back to GitHub, do the following:

  1. Make sure your project has eslint installed and configured
  2. Add ci:lint script with the following flags: eslint --output-file eslint_report.json --format json on top of your regular ESLint CLI flags.
  3. Add a CI pipelines with the following:
name: test
on:
  pull_request:
    branches:
      - master
  push:
    branches:
      - master

jobs:
  lint:
    uses: the-guild-org/shared-config/.github/workflows/lint.yml@main
    with:
      script: yarn ci:lint
    secrets:
      githubToken: ${{ secrets.GITHUB_TOKEN }}
Step 11: Shared pipelines

To get the most out of the shared pipelines, you can use the following to run scripts as part of your CI process:

name: build
on:
  pull_request:
    branches:
      - master
  push:
    branches:
      - master

jobs:
  build:
    uses: the-guild-org/shared-config/.github/workflows/ci.yml@main
    with:
      script: yarn build

If our script is more complex and requires NodeJS version matrix, you can use this:

name: build
on:
  pull_request:
    branches:
      - master
  push:
    branches:
      - master

jobs:
  build:
    uses: the-guild-org/shared-config/.github/workflows/ci-node-matrix.yml@main
    with:
      script: yarn build
      nodeVersions: '[14,16,18]'

If your script requires more stuff, and you just want to avoid configuring NodeJS + Yarn + Caches, you can just use the following to get started with your pipeline:

name: test
on:
  pull_request:
    branches:
      - master
  push:
    branches:
      - master

jobs:
  test:
    name: myScript
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - uses: the-guild-org/shared-config/setup@main
        name: setup env
        with:
          nodeVersion: 18
Step 12: `rc` relases

To ship rc releases from Upcoming Release Changes PRs, do the following first:

  1. Ensure GUILD_BOT_TOKEN is set on your repository (or, a PAT created from a bot/user account).
  2. Change the stable release pipeline, and configure it to use GUILD_BOT_TOKEN:
jobs:
  stable:
    uses: the-guild-org/shared-config/.github/workflows/release-stable.yml@main
    with:
      releaseScript: release
      nodeVersion: 18
    secrets:
      githubToken: ${{ secrets.GUILD_BOT_TOKEN }} # HERE
      npmToken: ${{ secrets.NPM_TOKEN }}
  1. Now, duplicate your snapshot release pipeline, add the conditions, and make sure to add the required configuration for that kind of pipelines:
jobs:
  alpha: # Assuming this is your exisisting alpha release pipeline from previous step
    uses: the-guild-org/shared-config/.github/workflows/release-snapshot.yml@main
    if: ${{ github.event.pull_request.title != 'Upcoming Release Changes' }} # ADD THIS
    with:
      npmTag: alpha
      buildScript: build
      nodeVersion: 18
    secrets:
      githubToken: ${{ secrets.GITHUB_TOKEN }}
      npmToken: ${{ secrets.NPM_TOKEN }}

  release-candidate: # This is a new one
    uses: the-guild-org/shared-config/.github/workflows/release-snapshot.yml@main
    if: ${{ github.event.pull_request.title == 'Upcoming Release Changes' }} # ADD THIS, note that the condition is different
    with:
      npmTag: rc # Here we are using a different tag
      restoreDeletedChangesets: true # Make sure to add this flag, in order to make changesets visible to the release pipeline!
      buildScript: build
      nodeVersion: 18
    secrets:
      githubToken: ${{ secrets.GITHUB_TOKEN }}
      npmToken: ${{ secrets.NPM_TOKEN }}
Step 13: Trackback

Trackback is a in-house tool for The Guild repositories, that allows up to easily test rc releases.

To use that, following these instructions:

  1. Ensure you have GUILD_BOT_TOKEN set.
  2. Find the workflows in your repositories that might be effected by changes. Usually build / typecheck and test are relevant here. Also more complicated workflows, such as integration tests. Add this at the end of the workflow (or, after the importand command):
- uses: the-guild-org/shared-config/release-trackback@main
  if: ${{ always() }}} # Important!
  with:
    token: ${{ secrets.GUILD_BOT_TOKEN }} # Make sure to use the Guild bot token here
    relevantPackages:
      | # Here you can specify a list of explicit dependencies, or using "*" matcher.
      @theguild/*
      @whatwg-node/*
  1. To make sure your repository accepts Renovate configuration for alpha release, use the following snippet in your renovate.json config file:
{
  "groupName": "whatwg-node",
  "matchPackageNames": ["@whatwg-node/*"],
  "prPriority": 21,
  "ignoreUnstable": false,
  "respectLatest": false,
  "allowedVersions": "/^([0-9]+).([0-9]+)(?:.([0-9]+))?(-rc-.+)?$/"
}
  1. Now, if a Renovate PR with rc release, for a depenendecies declared under relevantPackages will fail your workflow, you'll get a comment on Upcoming Release Changes PR in the source repository!
Step 13: (Optional) Setup Algolia search

We recommend setup Algolia to any The Guild project that provides documentation with Nextra.


  1. Install @theguild/algolia
yarn add -D @theguild/algolia
  1. Configure Prettier

If Prettier or other tools are used, ensure to exclude the website/algolia-lockfile.json file.

  1. Add Algolia credentials to repo secrets

Configure the following GitHub Actions secrets from your Algolia dashboard:

  • ALGOLIA_ADMIN_API_KEY
  1. Add the GitHub Actions workflows

PR workflow example

name: pr
on:
  pull_request:
    branches:
      - master

jobs:
  algolia:
    uses: the-guild-org/shared-config/.github/workflows/algolia-integrity.yml@main
    with:
      domain: https://www.the-guild.dev/graphql/codegen/
    secrets:
      githubToken: ${{ secrets.GITHUB_TOKEN }}

main branch workflow example

name: release
on:
  push:
    branches:
      - master

jobs:
  algolia:
    uses: the-guild-org/shared-config/.github/workflows/algolia-publish.yml@main
    secrets:
      githubToken: ${{ secrets.GITHUB_TOKEN }}
      algoliaAdminApiKey: ${{ secrets.ALGOLIA_ADMIN_API_KEY }}
    with:
      domain: https://www.the-guild.dev/graphql/codegen/

For the complete list of available options (with: ...), please refer to the workflow declaration.

If your project runs a node version different version of 18 or uses a package manager different from yarn, please use the following options under the with block:

  • packageManager: "pnpm"
  • nodeVersion: 16

shared-config's People

Contributors

ardatan avatar charlypoly avatar dimamachina avatar dotansimha avatar eddeee888 avatar emrysmyrddin avatar enisdenjo avatar gilgardosh avatar github-actions[bot] avatar kamilkisiela avatar n1ru4l avatar renovate[bot] avatar saihaj avatar theguild-bot avatar yassineldeeb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

shared-config's Issues

Allow for passing version number for package manger

Instead of doing based on packageManager for version we should have a new input that can be used to pin a version number.

In graph-tooling it uses pnpm as main package manager but some of integration tests use yarn and if yarn install is run in the CI where we pin with packageManager that makes it very cryptic to debug. Instead I force the version number using engines in package.json then being able to just define as an input to CI job would be sufficient

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Warning

These dependencies are deprecated:

Datasource Name Replacement PR?
npm @types/marked Unavailable

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/algolia-integrity.yml
  • actions/checkout v4
  • marocchino/sticky-pull-request-comment v2
  • ubuntu 22.04
.github/workflows/algolia-publish.yml
  • actions/checkout v4
  • EndBug/add-and-commit v9
  • ubuntu 22.04
.github/workflows/changesets-dependencies.yaml
  • actions/checkout v4
  • ubuntu 22.04
.github/workflows/ci-node-matrix.yml
  • actions/checkout v4
  • ubuntu 22.04
  • ubuntu 22.04
.github/workflows/ci.yml
  • actions/checkout v4
  • ubuntu 22.04
.github/workflows/lint.yml
  • actions/checkout v4
  • ataylorme/eslint-annotate-action v2
  • ubuntu 22.04
.github/workflows/release-snapshot.yml
  • the-guild-org/changesets-snapshot-action v0.0.1
  • ubuntu 22.04
.github/workflows/release-stable.yml
  • actions/checkout v4
  • dotansimha/changesets-action v1.5.2
  • ubuntu 22.04
setup/action.yml
  • styfle/cancel-workflow-action 0.12.1
  • pnpm/action-setup v4.0.0
  • actions/setup-node v4
website-cf/action.yml
  • cloudflare/pages-action v1.5.0
  • peter-evans/find-comment v3
  • peter-evans/create-or-update-comment v4
npm
package.json
  • @changesets/changelog-github 0.5.0
  • @changesets/cli 2.27.7
  • @shopify/eslint-plugin 45.0.0
  • @types/eslint 8.56.10
  • @types/node 20.14.10
  • cspell 8.10.4
  • eslint 8.57.0
  • eslint-remote-tester 3.0.1
  • prettier 3.3.3
  • ts-node 10.9.2
  • typescript 5.5.3
  • node >=21.6
  • pnpm >=9.0.6
  • pnpm 9.5.0
packages/eslint-config/package.json
  • @rushstack/eslint-patch ^1.6.1
  • @typescript-eslint/eslint-plugin ^7.0.0
  • @typescript-eslint/parser ^7.0.0
  • eslint-config-prettier ^9.1.0
  • eslint-import-resolver-typescript ^3.6.1
  • eslint-plugin-import ^2.29.1
  • eslint-plugin-jsonc ^2.11.1
  • eslint-plugin-jsx-a11y ^6.8.0
  • eslint-plugin-mdx ^3.0.0
  • eslint-plugin-n ^17.0.0
  • eslint-plugin-promise ^6.1.1
  • eslint-plugin-react ^7.33.2
  • eslint-plugin-react-hooks ^4.6.0
  • eslint-plugin-sonarjs ^1.0.0
  • eslint-plugin-unicorn ^54.0.0
  • eslint-plugin-yml ^1.11.0
  • eslint ^8
  • typescript ^5
packages/prettier-config/package.json
  • @ianvs/prettier-plugin-sort-imports 4.3.1
  • prettier-plugin-pkg ^0.18.0
  • prettier-plugin-sh ^0.14.0
  • prettier ^3
packages/tailwind-config/package.json
  • autoprefixer ^10.4.19
  • cssnano ^7.0.0
  • postcss ^8.4.38
  • postcss-import ^16.1.0
  • tailwindcss ^3.4.3
  • postcss-load-config 6.0.1
  • tsup ^8.0.2
release-trackback/package.json
  • @actions/core 1.10.1
  • @actions/github 6.0.0
  • marked 12.0.2
  • semver 7.6.2
  • @types/marked 6.0.0
  • @types/node 20.14.10
  • @types/semver 7.5.8
  • @vercel/ncc 0.38.1
  • typescript 5.5.3

  • Check this box to trigger a request for Renovate to run again on this repository

Bot/Comment for releasing community PR as canary

Today we cannot easily publish contributor PRs as canaries because the workflows don't have access to our GitHub secrets (which is fine).

Instead we should have a way of pinging a bot that will import the branch into our repository and then release canary from there, and then comment on the original PR.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.