-
Notifications
You must be signed in to change notification settings - Fork 0
44 lines (40 loc) · 2.29 KB
/
changed-packages.yaml
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
name: 'Determine changed packages'
on:
workflow_call:
outputs:
package_changed:
description: 'Dry run of turbo to determine which packages have changed since the last release'
value: ${{ jobs.dry-run.outputs.package_changed }}
jobs:
dry-run:
runs-on: ubuntu-latest
env:
# The turbo filter here varies depending on if we're using this workflow in a PR or on a push to a branch
# For PRs, we want to use `github.event.pull_request.base.sha` to tell turbo to see which packages changed since that SHA
# For a branch push/merges, the above sha isn't available, so instead, we reference `github.event.before` to determine the previous `HEAD` of the branch we just pushed onto
# See SO answer for more info https://stackoverflow.com/a/61861763/2379922
TURBO_REF_FILTER: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || 'HEAD^' }}
outputs:
# Defining a job output for used by the next jobs:
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idoutputs
package_changed: ${{ steps.changeset.outputs.result }}
steps:
- uses: actions/checkout@v2
with:
# see `fetch-depth` in README: https://github.com/actions/checkout#checkout-v3,
# we set to `0` so the referenced commits are available for the command below
fetch-depth: 0
- name: Changeset
id: changeset
shell: bash
# 1. We need the 'output' of a turbo dry-run to get a json with all affected packages of these run.
# 2. The multi line json string is wrapped in EOF delimeters to make the GHA happy: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
# 3. We specify the .github/ folder as a dependency here. Just to be safe, if workflows changed, we use that to mean everything has changes pending... to force redeploys
run: |
echo 'result<<CHANGESET_DELIMITER' >> $GITHUB_OUTPUT
echo "$(npx -y turbo build --dry-run=json --filter=...[$TURBO_REF_FILTER])" >> $GITHUB_OUTPUT
echo 'CHANGESET_DELIMITER' >> $GITHUB_OUTPUT
- name: Echo info
shell: bash
run: |
echo "Changeset: ${{ steps.changeset.outputs.result }}"