forked from namehash/ensnode
-
Notifications
You must be signed in to change notification settings - Fork 0
197 lines (174 loc) · 7.16 KB
/
Copy pathrelease.yml
File metadata and controls
197 lines (174 loc) · 7.16 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
name: Release
on:
workflow_dispatch:
push:
branches:
- main
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
changesets:
name: Changesets
if: github.repository == 'namehash/ensnode'
runs-on: blacksmith-4vcpu-ubuntu-2204
permissions:
contents: write
pull-requests: write
outputs:
published: ${{ steps.changesets.outputs.published }}
publishedApps: ${{ steps.publishedApps.outputs.output }}
publishedPackages: ${{ steps.publishedPackages.outputs.output }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: Setup Node.js
uses: useblacksmith/setup-node@v5
with:
node-version-file: .nvmrc
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Create Release Pull Request or Publish to npm
uses: changesets/action@v1.4.10
id: changesets
with:
commit: "chore(release): version apps"
title: "Release New Version"
publish: pnpm changeset-publish
createGithubReleases: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Filter Published Packages For Apps
uses: cloudposse/github-action-jq@main
id: publishedApps
with:
compact: true
input: ${{ steps.changesets.outputs.publishedPackages }}
# filter publishedPackages for apps (projects whose artifact is a docker image)
script: |-
map(select(
.name == "ensindexer"
or .name == "ensadmin"
or .name == "ensapi"
or .name == "ensrainbow"
))
- name: Filter Published Packages For NPM Packages
uses: cloudposse/github-action-jq@main
id: publishedPackages
with:
compact: true
input: ${{ steps.changesets.outputs.publishedPackages }}
# filter publishedPackages for packages (projects whose artifact is an NPM package)
# 1. filter out publishedApps (see above)
# 2. filter out private packages that were not actually published to NPM
# a. @ensnode/shared-configs
# b. @docs/*
script: |-
map(select(
.name != "ensindexer"
and .name != "ensadmin"
and .name != "ensapi"
and .name != "ensrainbow"
and .name != "@ensnode/shared-configs"
and (.name | startswith("@docs") | not)
))
build-and-push-ensnode:
name: ${{ matrix.apps.name }} ${{ matrix.apps.version }}
# if changesets published our npm packages, also build docker images
needs: changesets
if: needs.changesets.outputs.published == 'true' && needs.changesets.outputs.publishedApps != '[]'
runs-on: blacksmith-4vcpu-ubuntu-2204
strategy:
fail-fast: false
matrix:
apps: ${{ fromJson(needs.changesets.outputs.publishedApps) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Build & Push
uses: ./.github/actions/build_docker_image
with:
image: ghcr.io/${{ github.repository }}/${{ matrix.apps.name }}
dockerfile: apps/${{ matrix.apps.name }}/Dockerfile
registry_user: ${{ github.actor }}
registry_token: ${{ secrets.GITHUB_TOKEN }}
# construct docker tag using the changesets-reported version
tags: |
type=semver,pattern={{version}},value=${{ matrix.apps.version }}
type=ref,event=branch
type=sha
create-github-release:
name: Create GitHub Release
runs-on: blacksmith-4vcpu-ubuntu-2204
# run only if (1) changesets published our npm packages AND
if: needs.changesets.outputs.published == 'true'
# (2) we built and pushed the docker images
needs: [changesets, build-and-push-ensnode]
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get PR information
id: get-pr
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Get the PR number from the commit message
# Note: it must be a release PR with a title "Release New Version"
PR_NUMBER=$(git log -1 --pretty=%B | grep -o 'Release New Version (#[0-9]\+)' | grep -o '[0-9]\+')
if [ -z "$PR_NUMBER" ]; then
echo "Could not find PR number in commit message"
exit 1
fi
# Get PR body using GitHub CLI
PR_BODY=$(gh pr view $PR_NUMBER --json body -q .body)
if [ -z "$PR_BODY" ]; then
echo "Could not fetch PR body"
exit 1
fi
# Extract version from PR body
VERSION=$(echo "$PR_BODY" | grep -o '@[^@]*@[0-9]\+\.[0-9]\+\.[0-9]\+' | head -1 | awk -F@ '{print $3}')
if [ -z "$VERSION" ]; then
echo "Could not extract version from PR body"
exit 1
fi
# Extract release notes (everything below # Releases)
RELEASE_NOTES=$(echo "$PR_BODY" | awk '/^# Releases/{p=1;next}p')
# Strip out @ensnode/shared-configs section (thank you claude-san)
RELEASE_NOTES=$(echo "$RELEASE_NOTES" | awk '
/^## @ensnode\/shared-configs@.*/ { skip=1; next } # Set skip flag and skip further processing for this line
/^## / { skip=0 } # On subsequent lines, clear skip flag if H2 is found
!skip # Print line only if skip flag is not set
')
# Add NPM package links
RELEASE_NOTES+=$'\n\n## :package: NPM packages\n'
RELEASE_NOTES+=$(echo '${{ needs.changesets.outputs.publishedPackages }}' | jq -r '.[] | "- [\(.name)@\(.version)](https://www.npmjs.com/package/\(.name)/v/\(.version))"')
# Add Docker image links
RELEASE_NOTES+=$'\n\n## :whale: Docker images\n'
RELEASE_NOTES+=$(echo '${{ needs.changesets.outputs.publishedApps }}' | jq -r '.[] | "- [\(.name):\(.version)](https://ghcr.io/namehash/ensnode/\(.name):\(.version))"')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "pr_body<<EOF" >> $GITHUB_OUTPUT
echo "$RELEASE_NOTES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "Extracted version: $VERSION"
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ steps.get-pr.outputs.version }}
name: v${{ steps.get-pr.outputs.version }}
body: ${{ steps.get-pr.outputs.pr_body }}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: ./.github/actions/send_slack_notification
with:
slack_webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
slack_title: "ENSNode new version released: v${{ steps.get-pr.outputs.version }}"
slack_message: "✅ Release ENSNode completed"