-
Notifications
You must be signed in to change notification settings - Fork 8
139 lines (118 loc) · 4.3 KB
/
release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
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@v3
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8
- name: Setup Node.js
uses: actions/setup-node@v3
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 }}
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@v3
# 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@v3
with:
# Checkout the next branch, instead of the default main branch
ref: next
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8
- name: Setup Node.js
uses: actions/setup-node@v3
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 }}