-
-
Notifications
You must be signed in to change notification settings - Fork 0
153 lines (127 loc) · 5.29 KB
/
update-pnpm.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
name: Update Package Manager
on:
schedule:
# Run every Monday at 3:27 AM
- cron: "27 3 * * 1"
push:
branches:
- main
paths:
- .github/workflows/update-pnpm.yml
pull_request:
paths:
- .github/workflows/update-pnpm.yml
workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs:
check-for-new-version:
name: Check for new pnpm version
runs-on: ubuntu-latest
outputs:
new-version: ${{ steps.pnpm-info.outputs.version }}
branch-exists: ${{ steps.check-branch.outputs.branch-exists }}
steps:
- name: Generate token
id: generate-installation-token
uses: actions/create-github-app-token@5d869da34e18e7287c1daad50e0b8ea0f506ce69 # v1.11.0
with:
app-id: ${{ secrets.LANEYBOT_APP_ID }}
private-key: ${{ secrets.LANEYBOT_PRIVATE_KEY }}
- name: Get user info
id: get-user-info
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
env:
LANEYBOT_APP_SLUG:
${{ steps.generate-installation-token.outputs.app-slug }}
with:
github-token: ${{ steps.generate-installation-token.outputs.token }}
script: |
const appSlug = process.env.LANEYBOT_APP_SLUG;
const userSlug = `${appSlug}[bot]`;
const user = await github.rest.users.getByUsername({
username: userSlug
});
const internalID = user.data.id;
const app = await github.rest.apps.getBySlug({
app_slug: appSlug
});
const displayName = app.data.name;
const gitEmail =`${displayName} <${internalID}+${userSlug}@users.noreply.github.com>`;
console.log(`Calculated git email: '${gitEmail}'`);
core.setOutput('gitEmail', gitEmail);
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
token: ${{ steps.generate-installation-token.outputs.token }}
- name: Enable Corepack
run: |
corepack enable
- name: Setup Node.js
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
env:
COREPACK_ENABLE_STRICT: false
with:
cache-dependency-path: pnpm-lock.yaml
node-version-file: "package.json"
cache: "pnpm"
- name: Update Package Manager
run: |
corepack up
- name: Check for changes
id: git-check
run: |
git diff --exit-code package.json || echo "changes=true" >> "${GITHUB_OUTPUT}"
- name: Get new pnpm version and packageManager field
if: steps.git-check.outputs.changes == 'true'
id: pnpm-info
run: |
VERSION="$(pnpm --version)"
echo "version=${VERSION}" >> "${GITHUB_OUTPUT}"
echo "package-manager=$(jq -r .packageManager package.json)" >> "${GITHUB_OUTPUT}"
echo "update-branch=auto-merge/pnpm/${VERSION}" >> "${GITHUB_OUTPUT}"
- name: Check if update branch exists
if: steps.git-check.outputs.changes == 'true'
id: check-branch
env:
UPDATE_BRANCH: ${{ steps.pnpm-info.outputs.update-branch }}
run: |
if ! git ls-remote --quiet --exit-code --heads origin "${UPDATE_BRANCH}" >/dev/null; then
echo "branch-exists=false" >> "${GITHUB_OUTPUT}"
exit 0
fi
echo "The branch \`${UPDATE_BRANCH}\` exists, skipping PR creation."
echo "branch-exists=true" >> "${GITHUB_OUTPUT}"
- name: Create Pull Request
if: >
steps.git-check.outputs.changes == 'true' &&
steps.check-branch.outputs.branch-exists == 'false'
uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # v7.0.5
with:
author: ${{ steps.get-user-info.outputs.gitEmail }}
# If we change things in a PR for testing, we want the raised PR to
# include those changes.
base:
${{ github.head_ref == '' && github.ref_name || github.head_ref }}
body: |
Update pnpm to version `${{ steps.pnpm-info.outputs.version }}`.
Changes made:
- Updated the `packageManager` field to `pnpm@${{ steps.pnpm-info.outputs.package-manager }}`.
This update [was performed automatically][workflow-run] by [the "Update Package Manager" workflow][workflow].
[workflow]: ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}/.github/workflows/update-pnpm.yml
[workflow-run]: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
branch: ${{ steps.pnpm-info.outputs.update-branch }}
commit-message: >
chore: update packageManager field to pnpm@${{
steps.pnpm-info.outputs.version }}
committer: ${{ steps.get-user-info.outputs.gitEmail }}
draft: ${{ github.event_name == 'pull_request' }}
delete-branch: true
labels: |
dependencies
automated pr
title: >
chore: update packageManager field to pnpm@${{
steps.pnpm-info.outputs.version }}
token: ${{ steps.generate-installation-token.outputs.token }}