Skip to content

Commit a252c8f

Browse files
committed
add tests for daff.json
1 parent 76fe61b commit a252c8f

1 file changed

Lines changed: 170 additions & 0 deletions

File tree

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
name: Daffodil Daff CLI
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
ref:
7+
required: false
8+
type: string
9+
node-version:
10+
required: false
11+
type: string
12+
default: '22.21.x'
13+
angular-version:
14+
required: false
15+
type: string
16+
default: '^20'
17+
secrets:
18+
NX_KEY:
19+
required: true
20+
AZURE_NX_CACHE_READONLY_CONNECTION_STRING:
21+
required: true
22+
23+
env:
24+
WORK_DIR: /tmp/daffodil-daff-cli-test
25+
TEST_VERSION: 0.0.0-test.${{ github.run_id }}
26+
REGISTRY_PORT: 4873
27+
NX_KEY: ${{ secrets.NX_KEY }}
28+
29+
jobs:
30+
test:
31+
name: "daff CLI (${{ matrix.driver }}, @angular${{ inputs.angular-version }})"
32+
runs-on: ubuntu-latest
33+
services:
34+
verdaccio:
35+
image: verdaccio/verdaccio
36+
ports:
37+
- 4873:4873
38+
options: >-
39+
--health-cmd "node -e \"require('http').get('http://localhost:4873/-/ping',r=>process.exit(r.statusCode===200?0:1)).on('error',()=>process.exit(1))\""
40+
--health-interval 5s
41+
--health-timeout 3s
42+
--health-retries 10
43+
strategy:
44+
fail-fast: false
45+
matrix:
46+
driver: [magento, demo]
47+
48+
steps:
49+
- uses: actions/checkout@v6
50+
with:
51+
fetch-depth: 1
52+
ref: ${{ inputs.ref && inputs.ref || github.sha }}
53+
54+
- uses: graycoreio/github-actions/setup-node@main
55+
with:
56+
node-version: ${{ inputs.node-version }}
57+
use-stamp-cache: true
58+
working-directory: ${{ github.workspace }}
59+
60+
- uses: graycoreio/daffodil/.github/actions/setup-nx-remote-cache@develop
61+
with:
62+
cache-mode: read-only
63+
read-only-azure-connection-string: ${{ secrets.AZURE_NX_CACHE_READONLY_CONNECTION_STRING }}
64+
event-name: 'manual-setup'
65+
66+
- name: Authenticate with Verdaccio
67+
run: |
68+
REGISTRY_URL="http://localhost:${{ env.REGISTRY_PORT }}"
69+
TOKEN=$(curl -s -X PUT ${REGISTRY_URL}/-/user/org.couchdb.user:ci \
70+
-H "Content-Type: application/json" \
71+
-d '{"name":"ci","password":"ci-password","type":"user"}' | jq -r '.token')
72+
if [ -z "$TOKEN" ] || [ "$TOKEN" = "null" ]; then echo "ERROR: Failed to obtain Verdaccio token" && exit 1; fi
73+
echo "@daffodil:registry=${REGISTRY_URL}" >> "$HOME/.npmrc"
74+
echo "//localhost:${{ env.REGISTRY_PORT }}/:_authToken=${TOKEN}" >> "$HOME/.npmrc"
75+
76+
- name: Set test version for commerce package
77+
run: |
78+
sed -i "s/version = '.*'/version = '${{ env.TEST_VERSION }}'/" \
79+
tools/schematics/ng-add/generators/version.ts
80+
81+
- name: Build @daffodil/* packages
82+
run: npx nx run @daffodil/commerce:build
83+
84+
- name: Set test version in root
85+
run: npm version "${{ env.TEST_VERSION }}" --no-git-tag-version
86+
87+
- uses: graycoreio/github-actions/set-versions-from-root@main
88+
89+
- name: Compute @daffodil/commerce dependencies
90+
id: daff-deps
91+
run: |
92+
PACKAGES=$(npx nx graph --focus=@daffodil/commerce --file=stdout | \
93+
jq -r '.graph.dependencies["@daffodil/commerce"] | map(.target) | join(",")')
94+
echo "packages=${PACKAGES}" >> "$GITHUB_OUTPUT"
95+
96+
- name: Publish @daffodil/* packages to Verdaccio
97+
run: |
98+
npx nx run-many \
99+
-t publish \
100+
--projects="${{ steps.daff-deps.outputs.packages }},@daffodil/commerce"
101+
102+
- name: Compute test directory
103+
id: test-dir
104+
run: |
105+
DIR_NAME="test-daff-cli-${{ matrix.driver }}"
106+
echo "name=${DIR_NAME}" >> "$GITHUB_OUTPUT"
107+
echo "path=${{ env.WORK_DIR }}/${DIR_NAME}" >> "$GITHUB_OUTPUT"
108+
109+
- name: Scaffold test app
110+
run: |
111+
rm -rf "${{ steps.test-dir.outputs.path }}"
112+
mkdir -p "${{ env.WORK_DIR }}"
113+
cd "${{ env.WORK_DIR }}"
114+
npx -y @angular/cli@${{ inputs.angular-version }} new "${{ steps.test-dir.outputs.name }}" \
115+
--style=scss \
116+
--skip-tests \
117+
--defaults
118+
119+
- name: Add @daffodil/commerce schematic
120+
working-directory: ${{ steps.test-dir.outputs.path }}
121+
run: |
122+
CI=true npx ng add @daffodil/commerce@${{ env.TEST_VERSION }} \
123+
--driver=${{ matrix.driver }} \
124+
--is-new-project \
125+
--defaults \
126+
--skip-confirmation
127+
128+
- name: Verify daff.json was generated
129+
working-directory: ${{ steps.test-dir.outputs.path }}
130+
run: |
131+
if [ ! -f daff.json ]; then
132+
echo "ERROR: daff.json was not generated by the schematic" && exit 1
133+
fi
134+
PROJECT_NAME="${{ steps.test-dir.outputs.name }}"
135+
VERSION=$(jq -r ".projects[\"${PROJECT_NAME}\"].drivers.magento" daff.json)
136+
if [ "$VERSION" = "null" ] || [ -z "$VERSION" ]; then
137+
echo "ERROR: daff.json is missing projects.${PROJECT_NAME}.drivers.magento" && cat daff.json && exit 1
138+
fi
139+
echo "daff.json generated with magento version ${VERSION}"
140+
141+
- name: Verify schematic wrote the production condition to angular.json
142+
working-directory: ${{ steps.test-dir.outputs.path }}
143+
run: |
144+
PROJECT_NAME="${{ steps.test-dir.outputs.name }}"
145+
VERSION=$(jq -r ".projects[\"${PROJECT_NAME}\"].drivers.magento" daff.json)
146+
147+
CONDITIONS=$(jq -c ".projects[\"${PROJECT_NAME}\"].architect.build.configurations.production.conditions" angular.json)
148+
EXPECTED_ENTRY="magento-${VERSION}"
149+
if ! echo "$CONDITIONS" | jq -e --arg c "$EXPECTED_ENTRY" 'index($c)' > /dev/null; then
150+
echo "ERROR: expected condition ${EXPECTED_ENTRY} in ${CONDITIONS}" && exit 1
151+
fi
152+
echo "angular.json contains ${EXPECTED_ENTRY}"
153+
154+
- name: Verify daff sync re-applies a revised daff.json
155+
working-directory: ${{ steps.test-dir.outputs.path }}
156+
run: |
157+
PROJECT_NAME="${{ steps.test-dir.outputs.name }}"
158+
NEW_VERSION="2.4.99"
159+
160+
jq ".projects[\"${PROJECT_NAME}\"].drivers.magento = \"${NEW_VERSION}\"" \
161+
daff.json > daff.json.tmp && mv daff.json.tmp daff.json
162+
163+
npx daff sync
164+
165+
CONDITIONS=$(jq -c ".projects[\"${PROJECT_NAME}\"].architect.build.configurations.production.conditions" angular.json)
166+
EXPECTED="[\"magento-${NEW_VERSION}\"]"
167+
if [ "$CONDITIONS" != "$EXPECTED" ]; then
168+
echo "ERROR: expected conditions ${EXPECTED}, got ${CONDITIONS}" && exit 1
169+
fi
170+
echo "daff sync wrote ${CONDITIONS} to angular.json after revision"

0 commit comments

Comments
 (0)