forked from microsoft/FluidFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
105 lines (91 loc) · 4.89 KB
/
pr-check-changeset.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
name: "pr-check-changeset"
# This workflow checks PRs for the presence of a new changeset file. When a PR is opened, it will be checked for a
# changeset. The results of the check are uploaded as a pipeline artifact. After this workflow is completed it triggers
# the changeset-reporter workflow, which adds a comment to the PR depending on the results of the check.
#
# The workflows are separated for security reasons. This workflow does not require write access to the repo, but the
# changeset-reporter workflow does.
on:
pull_request:
types: [labeled, unlabeled, opened, synchronize, reopened]
permissions:
pull-requests: read
jobs:
# When a PR has the changeset-required label, check if it has a changeset.
changeset-required:
name: Changeset required
runs-on: ubuntu-latest
if: contains(github.event.pull_request.labels.*.name, 'changeset-required')
steps:
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # ratchet:actions/checkout@v3
with:
fetch-depth: "0" # all history
persist-credentials: false
ref: ${{ github.event.pull_request.head.sha }} # Check out the head commit, not the merge commit
# install and configure node, pnpm and the changeset tools
- uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # ratchet:pnpm/action-setup@v4
- uses: actions/setup-node@1a4442cacd436585916779262731d5b162bc6ec7 # ratchet:actions/setup-node@v3
with:
node-version-file: .nvmrc
cache: "pnpm"
cache-dependency-path: pnpm-lock.yaml
- name: Install tools
run: |
# We only need to install the root dependencies
pnpm install -w --frozen-lockfile
# Add the remote in forked repos so we can more easily test in forks
- run: git remote add upstream https://github.com/microsoft/FluidFramework
if: github.repository_owner != 'microsoft'
- run: git fetch upstream
if: github.repository_owner != 'microsoft'
- run: git log -1
if: github.repository_owner != 'microsoft'
# Check whether a changeset was added. This step will have the outcome '1' if there is no changeset.
- name: Changeset metadata
run: |
# JSON output is piped through jq to compact it to a single line
pnpm exec flub check changeset --branch=${{ github.base_ref }} --json | jq -c > changeset-metadata.json
# We save the PR number because downstream pipelines are triggered by workflow_run, and the PR number is not easily
# retrievable in such workflows
- name: Add PR number to metadata
run: |
echo $(jq -c '. += { pr: "${{ github.event.number }}" }' changeset-metadata.json) > changeset-metadata.json
# Sets required = true/false based on the changeset-required label on the PR
- name: Changeset required
if: contains(github.event.pull_request.labels.*.name, 'changeset-required')
run: |
echo $(jq -c '. += {required: true}' changeset-metadata.json) > changeset-metadata.json
- name: Changeset not required
if: ${{ !contains(github.event.pull_request.labels.*.name, 'changeset-required') }}
run: |
echo $(jq -c '. += {required: false}' changeset-metadata.json) > changeset-metadata.json
- name: Upload changeset metadata
# release notes: https://github.com/actions/upload-artifact/releases/tag/v4.4.3
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # ratchet:actions/upload-artifact@v4
with:
name: changeset-metadata
path: ./changeset-metadata.json
retention-days: 3
# Any PR without the changeset-required label will be ignored.
changeset-not-required:
name: Changeset not required
runs-on: ubuntu-latest
if: ${{ !contains(github.event.pull_request.labels.*.name, 'changeset-required') }}
steps:
# Always output changesetFound = true and required = false to signal that changesets aren't needed. changesetFound
# must be set because it's not nullable.
- name: Changeset metadata
run: |
echo "{\"branch\": \"${{ github.base_ref }}\", \"required\": false, \"changesetFound\": true}" > ./changeset-metadata.json
# We save the PR number because downstream pipelines are triggered by workflow_run, and the PR number is not easily
# retrievable in such workflows
- name: Add PR number to metadata
run: |
echo $(jq -c '. += { pr: "${{ github.event.number }}" }' changeset-metadata.json) > changeset-metadata.json
- name: Upload changeset metadata
# release notes: https://github.com/actions/upload-artifact/releases/tag/v4.4.3
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # ratchet:actions/upload-artifact@v4
with:
name: changeset-metadata
path: ./changeset-metadata.json
retention-days: 3