forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
135 lines (122 loc) · 4.95 KB
/
crdb-api-client-npm-publish.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
# This workflow establishes two-step process of building and publishing `crdb-api-client` NPM package
# when the produced outputs are changed comparing to last published version.
# 1st step (first CI run) checks that built files contain changes comparing to previous version and
# if NPM package version incremented:
# - if yes, it publishes to NPM registry
# - if no, new PR created (with incremented version in package.json file) which should be merged and
# then second step is executed (runs workflow again) and publishes package.
name: Publish crdb-api-client package to NPM registry
on:
workflow_dispatch:
push:
branches:
- master
paths:
- 'pkg/ui/workspaces/crdb-api-client'
- 'pkg/**/*.proto'
jobs:
publish_crdb_api_client:
if: github.repository == 'cockroachdb/cockroach'
environment: ${{ github.ref_name == 'master' && 'master' || null }}
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ github.token }}
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Bazel Cache
uses: actions/cache@v3
with:
path: ~/.cache/bazel
key: ${{ runner.os }}-bazel-cache
- uses: pnpm/action-setup@v2
with:
version: "8.6.10"
- name: Setup NodeJS
uses: actions/setup-node@v3
with:
node-version: 16
registry-url: 'https://registry.npmjs.org'
always-auth: true
cache: 'pnpm'
cache-dependency-path: "${{ github.workspace }}/pkg/ui/pnpm-lock.yaml"
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Build crdb-api-client package
id: bazel-build
run: |
pnpm --dir pkg/ui install
bazel build //pkg/ui/workspaces/crdb-api-client:crdb-api-client
PACKAGE_PATH=$(bazel info execution_root)/$(bazel cquery //pkg/ui/workspaces/crdb-api-client:crdb-api-client --output=files)
echo "package_path=$PACKAGE_PATH" >> $GITHUB_OUTPUT
- name: Check for changes
id: check-changes
working-directory: ${{ steps.bazel-build.outputs.package_path }}
shell: bash
run: |
if [[ $(npm diff) ]]; then
echo "modified=true" >> $GITHUB_OUTPUT
else
echo "modified=false" >> $GITHUB_OUTPUT
fi
PUBLISHED_VERSION=$(npm view @cockroachlabs/crdb-api-client version);
PACKAGE_VERSION=$(cat ./package.json | jq -r ".version");
echo "package_version=$PACKAGE_VERSION" >> $GITHUB_OUTPUT;
if [[ $PUBLISHED_VERSION == $PACKAGE_VERSION ]]; then
echo "same_version=true" >> $GITHUB_OUTPUT
else
echo "same_version=false" >> $GITHUB_OUTPUT
fi
# Check if PR to increment package version already exists.
prs=$(gh pr list \
--repo "${{ github.repository }}" \
--head 'crdb-api-client-increment-version' \
--base 'master' \
--author 'cockroach-teamcity' \
--json title \
--jq 'length')
if ((prs > 0)); then
echo "has_pr=true" >> "$GITHUB_OUTPUT"
else
echo "has_pr=false" >> "$GITHUB_OUTPUT"
fi
- name: Increment version
if: |
steps.check-changes.outputs.modified == 'true' && \
steps.check-changes.outputs.same_version == 'true' && \
steps.check-changes.outputs.has_pr == 'false'
working-directory: pkg/ui/workspaces/crdb-api-client
run: npm version patch
- name: Create PR to increment package version
if: |
steps.check-changes.outputs.modified == 'true' && \
steps.check-changes.outputs.same_version == 'true' && \
steps.check-changes.outputs.has_pr == 'false'
uses: peter-evans/create-pull-request@v5
with:
base: master
token: ${{ secrets.GH_TOKEN_PR }}
push-to-fork: "cockroach-teamcity/cockroach"
add-paths: pkg/ui/workspaces/crdb-api-client/package.json
branch: "crdb-api-client-increment-version"
title: "ui: Increment @cockroachlabs/crdb-api-client version"
author: "CRL Release bot <[email protected]>"
reviewers: koorosh
body: |
Update pkg/ui/workspaces/crdb-api-client/package.json file with incremented patch version.
Epic: None
Release note: None
Release justification: non-production code changes
commit-message: |
ui: Increment crdb-api-client version to ${{ steps.check-changes.outputs.package_version }}
Update pkg/ui/workspaces/crdb-api-client/package.json
file with incremented patch version.
Epic: None
Release note: None
Release justification: non-production code changes
delete-branch: true
- name: Publish package
if: steps.check-changes.outputs.modified == 'true' && steps.check-changes.outputs.same_version == 'false'
working-directory: pkg/ui/workspaces/crdb-api-client
run: npm publish --access public --tag latest --ignore-scripts