-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
181 lines (159 loc) · 6.28 KB
/
action.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
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
# Note: This is a composite GitHub Actions, it should do all env setup, caching an so on, so other pipelines can just compose their own stuff on top of that.
# Docs: https://docs.github.com/en/actions/creating-actions/creating-a-composite-action
name: "Storm Software - Setup"
description: "A composite action configuration used across many Storm Software repos to setup: checkout, Node.js, a package manager, and npm registry configuration."
author: "sullivanpj"
branding:
icon: "package"
color: "gray-dark"
inputs:
working-directory:
description: "The working directory of your node package"
required: false
default: ./
package-manager:
description: Package manager
required: true
default: pnpm
package-manager-version:
description: Package manager version
required: true
default: 9.10.0
ignore-scripts:
description: Whether to ignore scripts during installation
required: true
default: N
storm-bot:
description: The github username of the Storm bot
required: true
default: Stormie-Bot
storm-bot-github-token:
description: The github token of the Storm bot
required: true
runs:
using: "composite"
steps:
- uses: actions/checkout@v4
name: Checkout [Pull Request]
if: ${{ github.event_name == 'pull_request' }}
with:
# By default, PRs will be checked-out based on the Merge Commit, but we want the actual branch HEAD.
ref: ${{ github.event.pull_request.head.sha }}
# We need to fetch all branches and commits so that Nx affected has a base to compare against.
fetch-depth: 0
token: ${{ inputs.storm-bot-github-token }}
- uses: actions/checkout@v4
name: Checkout [Default Branch]
if: ${{ github.event_name != 'pull_request' }}
with:
# We need to fetch all branches and commits so that Nx affected has a base to compare against.
fetch-depth: 0
token: ${{ inputs.storm-bot-github-token }}
- name: Check pnpm version
shell: bash
id: pnpm
if: inputs.package-manager == 'pnpm'
working-directory: ${{ inputs.working-directory }}
run: |
PNPM_VERSION=${PNPM_VERSION:-7.30.5}
PKG_JSON=$(cat package.json | jq -r '.packageManager' | awk -F@ '{print $2}')
if [ ! -z $PKG_JSON ]; then
PNPM_VERSION=$PKG_JSON
fi
if [ ! -z {{inputs.package-manager}} ]; then
PNPM_VERSION=${{ inputs.package-manager-version }}
fi
echo "Using PNPM version $PNPM_VERSION"
echo "version=$PNPM_VERSION" >> $GITHUB_OUTPUT
- name: Setup ${{ inputs.package-manager }}
id: pnpm_setup
if: inputs.package-manager == 'pnpm'
uses: pnpm/[email protected]
with:
version: ${{ steps.pnpm.outputs.version }}
run_install: false
package_json_file: ${{ inputs.working-directory }}/package.json
# - name: Install Nx-Cloud CLI
# shell: bash
# if: inputs.package-manager == 'pnpm'
# run: pnpm i nx-cloud -g
# working-directory: ${{ inputs.working-directory }}
# - name: Start Nx Cloud CI run
# shell: bash
# if: inputs.package-manager == 'pnpm'
# run: pnpm exec nx-cloud start-ci-run --distribute-on=".nx/workflows/dynamic-changesets.yaml"
# working-directory: ${{ inputs.working-directory }}
# - name: setup node
# uses: actions/setup-node@v4
# with:
# node-version: ${{ inputs.nodeVersion }}
# cache: ${{ inputs.package-manager }}
# cache-dependency-path: |
# **/pnpm-lock.yaml
# **/yarn.lock
# patches/**
- name: Restore cached npm dependencies
id: cache-dependencies-restore
uses: actions/cache/restore@v4
with:
path: |
node_modules
~/.cache/Cypress # needed for the Cypress binary
key: npm-dependencies-${{ hashFiles('pnpm-lock.yaml') }}
- name: Install yarn package manager
shell: bash
if: inputs.package-manager == 'yarn' && inputs.package-manager-version == ''
run: yarn install --ignore-engines --frozen-lockfile --immutable
working-directory: ${{ inputs.working-directory }}
- name: Install modern yarn package manager
shell: bash
if: inputs.package-manager == 'yarn' && inputs.package-manager-version == 'modern'
run: corepack enable && yarn
working-directory: ${{ inputs.working-directory }}
- name: Install pnpm package manager
shell: bash
if: inputs.package-manager == 'pnpm' && inputs.ignore-scripts != 'Y' && inputs.ignore-scripts != 'y'
run: pnpm install --no-frozen-lockfile
working-directory: ${{ inputs.working-directory }}
- name: Install pnpm package manager - Ignore scripts
shell: bash
if: inputs.package-manager == 'pnpm' && (inputs.ignore-scripts == 'Y' || inputs.ignore-scripts == 'y')
run: pnpm install --no-frozen-lockfile --ignore-scripts
working-directory: ${{ inputs.working-directory }}
- name: Get pnpm store directory
if: inputs.package-manager == 'pnpm'
shell: bash
id: pnpm-cache
run: |
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
- name: Set up npm registry
uses: actions/setup-node@v4
if: inputs.package-manager == 'pnpm'
with:
registry-url: https://registry.npmjs.org/
node-version-file: .github/.nvmrc
cache: pnpm
cache-dependency-path: pnpm-lock.yaml
- name: Setup pnpm config registry
if: inputs.package-manager == 'pnpm'
run: pnpm config set registry https://registry.npmjs.org
shell: bash
- name: Cache npm dependencies
id: cache-dependencies-save
uses: actions/cache/save@v4
with:
path: |
node_modules
~/.cache/Cypress # needed for the Cypress binary
key: ${{ steps.cache-dependencies-restore.outputs.cache-primary-key }}
- name: Configure git
run: |
git config user.name "${{ inputs.storm-bot }}"
git config user.email "[email protected]"
git config lfs.allowincompletepush true
git config --global init.defaultBranch main
npm config set //registry.npmjs.org/:_authToken=$NPM_TOKEN
shell: bash
# - name: Track the default branch
# run: git branch --track main origin/main
# shell: bash