@sharadox/git-hub-action-library
v0.2.2
Published
Reusable GitHub Actions for the Sharadox branch flow (index, development, <feature>.development): branch-name checks, verification with pnpm and Turborepo, branch domains on Vercel and npm publishing.
Readme
@sharadox/git-hub-action-library
Reusable GitHub Actions for one branch flow, used by every Sharadox repository and open to anyone:
<feature>.development ──squash──▶ development ──merge──▶ index (production)indexis production,developmentintegrates finished features, and each piece of work has its own<feature>.developmentbranch.- Branch names are subdomains. A repository with a base domain serves
indexon<domain>,developmentondevelopment.<domain>and<feature>.developmenton<feature>.development.<domain>. - The production and integration names are inputs, so other teams can use
mainandstaging.
| Action | What it does |
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| branch-flow | Fails when a branch name is outside the flow, or a pull request merges the wrong way. |
| verify | Checks out, checks that package.json engines.node names the current Node.js LTS (.node-version is lts/*), installs with pnpm (with private packages, using a read-only npm token) and runs Turborepo tasks. It can install Playwright's Chromium (on its own when Ubuntu's package mirrors are unreachable, as the runner image already has its libraries) and keep the test results on failure. |
| branch-domain | On branch create/delete, adds or removes <feature>.development.<base-domain> on a Vercel project. Deployments are kept; Vercel expires them. |
| publish | On a v<version> tag on production: checks the tag, runs the checks, publishes to npm (provenance for public packages, Trusted Publishing when no token is given) and attaches the package to a GitHub release. |
| prerelease | On a push to development or <feature>.development: builds and publishes the package as a prerelease (0.52.0-hero.3) under the branch's dist-tag (development, or the feature's name), so a site's own feature branch can preview exactly that feature (pnpm add @scope/package@hero). No GitHub release. |
| prerelease-cleanup | When a <feature>.development branch is deleted: removes its dist-tag (npm keeps the versions) with Trusted Publishing when no token is given. development's tag stays. |
Feature names become npm tags, so they start with a letter and are never latest. The check names stay Branch flow and Verify, because the actions are steps inside your own jobs, so rulesets requiring those checks keep working.
Use
# .github/workflows/continuous-integration.yml
name: Continuous integration
on:
push:
pull_request:
branches: [index, development]
jobs:
branch-flow:
name: Branch flow
runs-on: ubuntu-latest
steps:
- uses: Sharadox/git-hub-action-library/[email protected]
verify:
name: Verify
if: github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: Sharadox/git-hub-action-library/[email protected]
with:
tasks: format:check lint type-check test:unit build test:end-to-end
browser: "true"
npm-install-token: ${{ secrets.NPM_INSTALL_TOKEN }}
turborepo-token: ${{ secrets.TURBOREPO_TOKEN }}
turborepo-team: ${{ vars.TURBOREPO_TEAM }}
turborepo-remote-cache-signature-key: ${{ secrets.TURBOREPO_REMOTE_CACHE_SIGNATURE_KEY }}# .github/workflows/branch-domain.yml
name: Branch domain
on: [create, delete]
jobs:
domain:
name: Branch domain
if: github.event.ref_type == 'branch'
runs-on: ubuntu-latest
steps:
- uses: Sharadox/git-hub-action-library/[email protected]
with:
base-domain: ${{ vars.BASE_DOMAIN }}
vercel-project-id: ${{ vars.VERCEL_PROJECT_ID }}
vercel-team-id: ${{ vars.VERCEL_TEAM_ID }}
vercel-token: ${{ secrets.VERCEL_TOKEN }}# .github/workflows/publish.yml
name: Publish
on:
push:
tags: ["v*"]
permissions:
contents: write
id-token: write
jobs:
publish:
name: Publish
runs-on: ubuntu-latest
steps:
- uses: Sharadox/git-hub-action-library/[email protected]All inputs, with defaults, are in each action's action.yml. Every secret and variable belongs to the calling repository; none is shared between repositories.
The code behind the actions
The decisions are plain TypeScript functions in source/, published to npm as @sharadox/git-hub-action-library. Use them in your own tools:
| Import | Exports |
| ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| @sharadox/git-hub-action-library/branch | parseBranch(branch, names?) → production, integration, feature (with its name), dependabot or invalid; DEFAULT_BRANCH_NAMES |
| …/branch-flow | checkBranchFlow({ branch, target?, names? }) → list of problems |
| …/branch-domain | branchDomain(branch, baseDomain, names?) → the branch's address, or undefined |
| …/release-tag | checkReleaseTag({ tag, version, isPrivate, onProduction }) → list of problems |
| …/vercel-domain | updateBranchDomain({ event, domain, branch, project, team, token, fetch? }) |
| …/action-output | reportErrors(errors, write) → exit code; reportNotice(message, write) |
| …/run-branch-flow, …/run-branch-domain, …/run-release-check | the actions' entry logic, reading environment variables |
import { branchDomain } from "@sharadox/git-hub-action-library/branch-domain";
branchDomain("login.development", "platform.sharadox.com"); // "login.development.platform.sharadox.com"The actions run the TypeScript directly with the current Node LTS (--conditions=sharadox-source), so there's no build step between a change and a tag. Every function has unit tests at 100% coverage (pnpm test:unit).
Also exported
Smaller parts, mostly building blocks of the main exports:
…/run-prerelease: runPrerelease(environment, write, files?) and runDistTag(environment, write, files?): the prerelease and prerelease-cleanup actions' steps
Develop
pnpm verify runs formatting, lint, type-check, tests with coverage and the build. This repository checks itself with its own actions (uses: ./verify). Releases are v<version> tags on index.
License
Licença Sharadox de Código Aberto, versão 0.1.0. See português (the binding text) and the English translation.
