-
-
Notifications
You must be signed in to change notification settings - Fork 78
216 lines (188 loc) · 8.19 KB
/
Copy pathtest-daff-config.yml
File metadata and controls
216 lines (188 loc) · 8.19 KB
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
name: Daffodil Daff Config
on:
pull_request:
branches:
- develop
workflow_call:
inputs:
ref:
required: false
type: string
node-version:
required: false
type: string
default: '22.21.x'
angular-version:
required: false
type: string
description: "Angular version constraint (e.g. '^20'). Defaults to the @angular/core version in package.json."
secrets:
NX_KEY:
required: true
AZURE_NX_CACHE_READONLY_CONNECTION_STRING:
required: true
env:
WORK_DIR: /tmp/daffodil-daff-cli-test
TEST_VERSION: 0.0.0-test.${{ github.run_id }}
REGISTRY_PORT: 4873
NX_KEY: ${{ secrets.NX_KEY }}
NPM_VERSION: 11
jobs:
test:
name: "daff.json (${{ matrix.driver }})"
runs-on: ubuntu-latest
services:
verdaccio:
image: verdaccio/verdaccio
ports:
- 4873:4873
options: >-
--health-cmd "node -e \"require('http').get('http://localhost:4873/-/ping',r=>process.exit(r.statusCode===200?0:1)).on('error',()=>process.exit(1))\""
--health-interval 5s
--health-timeout 3s
--health-retries 10
strategy:
fail-fast: false
matrix:
driver: [magento, demo]
magento-version: [2.4.6, 2.4.7, 2.4.8]
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 1
ref: ${{ inputs.ref && inputs.ref || github.sha }}
- name: Resolve Angular version
id: angular-version
env:
INPUT_VERSION: ${{ inputs.angular-version }}
run: |
if [ -n "$INPUT_VERSION" ]; then
VERSION="$INPUT_VERSION"
else
VERSION=$(jq -r '.dependencies["@angular/core"]' package.json | sed -E 's/\.[0-9]+\.[0-9]+//g')
fi
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
- uses: graycoreio/github-actions/setup-node@main
with:
node-version: ${{ inputs.node-version }}
use-stamp-cache: true
working-directory: ${{ github.workspace }}
npm-version: ${{ env.NPM_VERSION }}
- uses: graycoreio/daffodil/.github/actions/setup-nx-remote-cache@develop
with:
cache-mode: read-only
read-only-azure-connection-string: ${{ secrets.AZURE_NX_CACHE_READONLY_CONNECTION_STRING }}
event-name: 'manual-setup'
- name: Authenticate with Verdaccio
run: |
REGISTRY_URL="http://localhost:${{ env.REGISTRY_PORT }}"
TOKEN=$(curl -s -X PUT ${REGISTRY_URL}/-/user/org.couchdb.user:ci \
-H "Content-Type: application/json" \
-d '{"name":"ci","password":"ci-password","type":"user"}' | jq -r '.token')
if [ -z "$TOKEN" ] || [ "$TOKEN" = "null" ]; then echo "ERROR: Failed to obtain Verdaccio token" && exit 1; fi
echo "@daffodil:registry=${REGISTRY_URL}" >> "$HOME/.npmrc"
echo "//localhost:${{ env.REGISTRY_PORT }}/:_authToken=${TOKEN}" >> "$HOME/.npmrc"
- name: Set test version for commerce package
run: |
sed -i "s/version = '.*'/version = '${{ env.TEST_VERSION }}'/" \
tools/schematics/ng-add/generators/version.ts
- name: Build @daffodil/* packages
run: npx nx run @daffodil/commerce:build
- name: Set test version in root
run: npm version "${{ env.TEST_VERSION }}" --no-git-tag-version
- uses: graycoreio/github-actions/set-versions-from-root@main
- name: Compute @daffodil/commerce dependencies
id: daff-deps
run: |
PACKAGES=$(npx nx graph --focus=@daffodil/commerce --file=stdout | \
jq -r '.graph.dependencies["@daffodil/commerce"] | map(.target) | join(",")')
echo "packages=${PACKAGES}" >> "$GITHUB_OUTPUT"
- name: Publish @daffodil/* packages to Verdaccio
run: |
npx nx run-many \
-t publish \
--projects="${{ steps.daff-deps.outputs.packages }},@daffodil/commerce" -- --tag latest
- name: Compute test directory
id: test-dir
run: |
DIR_NAME="test-daff-cli-${{ matrix.driver }}"
echo "name=${DIR_NAME}" >> "$GITHUB_OUTPUT"
echo "path=${{ env.WORK_DIR }}/${DIR_NAME}" >> "$GITHUB_OUTPUT"
- name: Restore cached base app
id: cache-base-app
uses: actions/cache/restore@v4
with:
path: ${{ steps.test-dir.outputs.path }}
key: commerce-base-app-scss-standalone-${{ steps.angular-version.outputs.version }}
- name: Scaffold test app
if: steps.cache-base-app.outputs.cache-hit != 'true'
env:
DIR_NAME: "${{ steps.test-dir.outputs.name }}"
run: |
rm -rf "${{ steps.test-dir.outputs.path }}"
mkdir -p "${{ env.WORK_DIR }}"
cd "${{ env.WORK_DIR }}"
npx -y @angular/cli@${{ steps.angular-version.outputs.version }} new "$DIR_NAME" \
--style=scss \
--skip-tests \
--defaults
- name: Cache base app
if: steps.cache-base-app.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: ${{ steps.test-dir.outputs.path }}
key: commerce-base-app-scss-standalone-${{ steps.angular-version.outputs.version }}
- name: Add schematic
working-directory: ${{ steps.test-dir.outputs.path }}
run: |
CI=true npx ng add @daffodil/commerce@${{ env.TEST_VERSION }} \
--driver=${{ matrix.driver }} \
${{ matrix.driver == 'magento' && format('--driver-version={0}', matrix['magento-version']) || '' }} \
--is-new-project \
--defaults \
--skip-confirmation
- name: Verify daff.json was generated
working-directory: ${{ steps.test-dir.outputs.path }}
run: |
if [ ! -f daff.json ]; then
echo "ERROR: daff.json was not generated by the schematic" && exit 1
fi
- name: Verify daff.json contains magento versions
if: ${{ matrix.driver == 'magento' }}
working-directory: ${{ steps.test-dir.outputs.path }}
run: |
PROJECT_NAME="${{ steps.test-dir.outputs.name }}"
VERSION=$(jq -r ".projects[\"${PROJECT_NAME}\"].drivers.magento" daff.json)
if [ "$VERSION" != ${{ matrix.magento-version }} ] || [ -z "$VERSION" ]; then
echo "ERROR: daff.json is missing correct version in projects.${PROJECT_NAME}.drivers.magento" && cat daff.json && exit 1
fi
echo "daff.json generated with magento version ${VERSION}"
- name: Verify schematic wrote the condition to angular.json
if: ${{ matrix.driver == 'magento' }}
working-directory: ${{ steps.test-dir.outputs.path }}
run: |
PROJECT_NAME="${{ steps.test-dir.outputs.name }}"
VERSION=$(jq -r ".projects[\"${PROJECT_NAME}\"].drivers.magento" daff.json)
CONDITIONS=$(jq -c ".projects[\"${PROJECT_NAME}\"].architect.build.conditions" angular.json)
EXPECTED_ENTRY="order-magento-2.4.1"
if ! echo "$CONDITIONS" | jq -e --arg c "$EXPECTED_ENTRY" 'index($c)' > /dev/null; then
echo "ERROR: expected condition ${EXPECTED_ENTRY} in ${CONDITIONS}" && exit 1
fi
echo "angular.json contains ${EXPECTED_ENTRY}"
- name: Verify daff version syncs angular.json and updates daff.json
if: ${{ matrix.driver == 'magento' }}
working-directory: ${{ steps.test-dir.outputs.path }}
run: |
PROJECT_NAME="${{ steps.test-dir.outputs.name }}"
NEW_VERSION="2.4.0"
npx daff version ${PROJECT_NAME} magento ${NEW_VERSION}
VERSION=$(jq -r ".projects[\"${PROJECT_NAME}\"].drivers.magento" daff.json)
if [ "$VERSION" != "$NEW_VERSION"] || [ -z "$VERSION" ]; then
echo "ERROR: daff version did not update daff.json" && exit 1
fi
CONDITIONS=$(jq -c ".projects[\"${PROJECT_NAME}\"].architect.build.conditions" angular.json)
EXPECTED="[\"order-magento-2.4.0\"]"
if [ "$CONDITIONS" != "$EXPECTED" ]; then
echo "ERROR: expected conditions ${EXPECTED}, got ${CONDITIONS}" && exit 1
fi
echo "daff version wrote ${CONDITIONS} to angular.json after revision"