Merge pull request #298 from gfscott/everything-config #86
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Prepare releases | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
paths: | |
- packages/** | |
concurrency: ${{ github.workflow }}-${{ github.ref }} | |
jobs: | |
changesets_release: | |
name: Release | |
runs-on: ubuntu-latest | |
# Only runs in the main repo, not in forks | |
if: github.repository == 'gfscott/eleventy-plugin-embed-everything' | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
- name: Install pnpm | |
uses: pnpm/action-setup@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
cache: 'pnpm' | |
- name: Install dependencies | |
run: pnpm install | |
# Even though the CI workflow runs tests, run them here | |
# so the release task errors out if there's a problem. | |
- name: Run unit tests | |
run: pnpm test | |
# The Changesets action either updates its "Version packages" PR | |
# OR publishes it to npm when that PR merges to main. | |
- name: Create Release Pull Request or publish | |
uses: changesets/action@v1 | |
with: | |
# Calls 'release' script in root package.json | |
# https://github.com/changesets/action#inputs | |
publish: pnpm release | |
commit: Version packages | |
title: Version packages | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
NPM_CONFIG_PROVENANCE: true | |
sync_next: | |
name: Sync next branch with main | |
runs-on: ubuntu-latest | |
needs: changesets_release | |
if: github.repository == 'gfscott/eleventy-plugin-embed-everything' | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
# Source: modified from a shopify/hydrogen workflow: | |
# https://github.com/Shopify/hydrogen/blob/main/.github/workflows/sync_main.yml | |
- name: Push to next branch | |
run: | | |
git show-ref | |
git push origin HEAD:next --force | |
changesets_prerelease: | |
name: Prerelease packages | |
runs-on: ubuntu-latest | |
needs: sync_next | |
if: github.repository == 'gfscott/eleventy-plugin-embed-everything' | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
with: | |
# Checkout the next branch, instead of the default main branch | |
ref: next | |
- name: Install pnpm | |
uses: pnpm/action-setup@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
cache: 'pnpm' | |
- name: Install dependencies | |
run: pnpm install | |
# By default, the changesets action creates an .npmrc file in each | |
# package directory before publishing so npm has the registry and | |
# token information it requires. Since this job requires entering | |
# prerelease mode and making a commit in the project root, | |
# the publish command fails because there is no .npmrc file and | |
# the root package.json file is marked as private. Therefore, | |
# this step creates that .npmrc file so the registry and token | |
# information is available when running `changeset publish` in | |
# the project's root directory context. | |
# | |
# As I discovered through trial and error, you can’t just put a | |
# static .npmrc file here because then it messes up other GitHub | |
# Actions workflows. | |
# | |
# https://github.com/changesets/action#with-publishing | |
- name: Creating .npmrc | |
run: | | |
cat << EOF > "$HOME/.npmrc" | |
//registry.npmjs.org/:_authToken=$NPM_TOKEN | |
EOF | |
env: | |
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
# Following Changesets snapshot release procedures: | |
# https://github.com/changesets/changesets/blob/main/docs/snapshot-releases.md | |
# | |
# - Config values come from ./changeset/config.json | |
# - Version will be X.x.x-unstable-{commit_hash} | |
# - Currently not pushing git tags to keep things moderately cleaner in the repo | |
# | |
- name: Enter snapshot mode and publish unstable versions to npm with changesets | |
run: | | |
pnpm changeset version --snapshot unstable | |
pnpm changeset publish --no-git-tag --tag unstable | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
NPM_CONFIG_PROVENANCE: true |