thefrontside / actions

Collection of GitHub Actions created by Frontside
5 stars 1 forks source link

Summary and Ideas for Covector #64

Closed minkimcello closed 2 years ago

minkimcello commented 3 years ago

The purpose of this issue is to take inventory of all of our github actions so we can incorporate them into covector. Under each section I've written a brief summary and for some of the more complex actions I jot down all of its steps.

Yarn

This action was created to replace running yarn install directly inside a Github Actions workflow so that it can exit if there are any warnings:

warnCount="$(echo $yarnoutput | grep -c -i "warn")"

if [ $warnCount != "0" ]; then
  echo -e "ERROR: Halting workflow because a warning was detected while installing..."
  exit 1
fi;

Synchronize NPM Tags

This action was created to clean up some of the tags on the NPM registry. It's supposed to trigger whenever a git branch is deleted. It would cross reference all of the branch names on Github with all of the tags on NPM and delete the ones that do not match. It had an optional "preserve" argument to keep some of the tags that may or may not have corresponding branches such as dev, beta, and alpha.

I don't know why I didn't have it just delete the corresponding tag of the deleted branch. But anyway, it looks like this action is being used in effection and microstates. We probably should've been using this for bigtest as well seeing as how we have a huge number of stale tags on NPM for bigtest packages.

Synchronize With NPM

This action is what we run in our release workflows. Basically it runs the npm publish command if the version of each package in the repository does not exist on the registry yet. Because we've been using changesets with this action, all the PR merges to the main branch do not get published since we rely on changesets to bump the versions and create its Version Packages PR.

git_setup()
find_packages()
  create a list of all the directories that contain package.json
  remove from the list the default ignore directories and any that are configured in the github workflow
  remove if package is private
  remove if package@version already exists on registry
publish()
  set npm token and unsafe-perm=true in .npmrc (token received as argument from github workflow) *
  run yarn or npm install depending on whether or not `yarn.lock` is present
  run custom command if specified in workflow
    this is for running any prepack or other necessary build commands
  for each directory in the list from the `find_packages()` function
    cd into that directory
    publish package
    git tag package_name-v$version
    git push origin package_name-v$version
      this tag format is to capture all the packages in the monorepo: @bigtest/webdriver-v1.0.0
    cd back to root for next loop
deprecate()
  get all package.json
  loop over list and if deprecate property is set in package.json
    npm run deprecate package_name deprecate_description

* I remember there was a lot of struggle around where to put npmrc and how multiple npmrc files conflict with one another. The context and conclusion to this issue is explained in #47.

Publish PR Preview

check_prerequisites()
  confirm the action is being run in a pull request
  confirm the action is not being run from a forked repository *
  confirm the action is not being run from a branch called 'latest' because it will conflict with npm's tags
json_locater()
  git diff between base and head ref
  remove file names and return an array of only the directories from git diff
  for each directory
    if there is no package.json
      root ? add root to array : go up one directory and run loop again
    if there is package.json
      add directory to array
remove_packages_to_skip()
  remove directories from array from json_locater() from default list and workflow argument
publish()
  npm_tag = branch name (format by replacing _ with __ and / with _)
  create published.json to record all the packages and its tags (for generating pr comment)
  yarn.lock ? yarn install : npm install
  set npm token in .npmrc
  run custom command if specified in workflow (for prepack/build)
    bigtest has this configured as yarn prepack:all
  for each directory
    cd directory
    if more than one package.json exists in directory and subdirectories (excluding node_modules)
      skip this directory
    if package is set to private
      skip
    npm publish --tag npm_tag
      bigtest has this configured as yarn publish
    append to the published.json created earlier with the package name and version
    cd to root for next loop
  if published.json lists 0 packages
    cat "we did not publish any packages" >> dangerfile.js
  if published.json has 1 package
    cat "we published {package}@{version-sha}" (simple version) >> dangerfile.js
  if published.json has > 1 packages
    cat "we published the following packages {dropdown with the details}" >> dangerfile.js
run_danger()
  install danger and set path
  run danger

* On a call with Charles, he mentioned that perhaps we could explore options around how a user in a forked repository could generate a preview package. He also mentioned that we do not need to generate preview packages for every pull request and that using labels to trigger the build might be a good idea.

cowboyd commented 3 years ago

Synchronize NPM Tags -> Note that with opt-in preview packages per PR, we will only need to do this for branches we are actively publishing

minkimcello commented 2 years ago

This issue was created to summarize our collection of actions but the actions described here are outdated as they reference the ones written in bash (in branch v1). Please refer to the following PRs to see the overview of the new actions of v2:

Name PR
publish-pr-preview #65, #69, #70, #71
synchronize-npm-tags #66
synchronize-with-npm #67