Skip to content

Commit de46399

Browse files
authored
chore(): Optimize caching in Github Actions (#2702)
* Dont prune in the build-step * Separate Headless Chrome tests * Add dist as artifact, rather than just the tarball * Build jasmine in build-step * Bundle just offline and node_modules * Build with Webpack 5
1 parent da8c660 commit de46399

File tree

5 files changed

+174
-601
lines changed

5 files changed

+174
-601
lines changed

.github/workflows/test.yml

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,11 @@ jobs:
2121
uses: actions/setup-node@v2-beta
2222
with:
2323
node-version: '14'
24-
- name: Get cache directory
25-
id: yarn-cache-dir-path
26-
run: echo "::set-output name=dir::$(yarn cache dir)"
2724
- name: Use yarn cache
2825
uses: actions/cache@v2
2926
with:
3027
path: |
31-
${{ steps.yarn-cache-dir-path.outputs.dir }}
28+
./node_modules
3229
~/.npm-packages-offline-cache
3330
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
3431
restore-keys: |
@@ -37,7 +34,6 @@ jobs:
3734
- name: Install deps
3835
run: |
3936
yarn config set yarn-offline-mirror ~/.npm-packages-offline-cache
40-
yarn config set yarn-offline-mirror-pruning true
4137
yarn install --frozen-lockfile --prefer-offline
4238
- name: Build
4339
id: yarn-pack-dir
@@ -46,10 +42,7 @@ jobs:
4642
uses: actions/upload-artifact@v2
4743
with:
4844
name: angularfire-${{ github.run_id }}
49-
path: |
50-
angularfire.tgz
51-
publish.sh
52-
unpack.sh
45+
path: dist
5346
retention-days: 1
5447
test:
5548
runs-on: ubuntu-latest
@@ -66,14 +59,11 @@ jobs:
6659
with:
6760
node-version: ${{ matrix.node }}
6861
check-latest: true
69-
- name: Get cache directory
70-
id: yarn-cache-dir-path
71-
run: echo "::set-output name=dir::$(yarn cache dir)"
7262
- name: Use yarn cache
7363
uses: actions/cache@v2
7464
with:
7565
path: |
76-
${{ steps.yarn-cache-dir-path.outputs.dir }}
66+
./node_modules
7767
~/.npm-packages-offline-cache
7868
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
7969
restore-keys: |
@@ -91,17 +81,52 @@ jobs:
9181
yarn install --frozen-lockfile --prefer-offline
9282
- name: 'Download Artifacts'
9383
uses: actions/download-artifact@v2
94-
- name: Expand Artifact
84+
- name: Run tests
9585
run: |
96-
mkdir -p dist/packages-dist
97-
chmod +x angularfire-${{ github.run_id }}/unpack.sh
98-
./angularfire-${{ github.run_id }}/unpack.sh
86+
mv angularfire-${{ github.run_id }} dist
87+
yarn test:node
88+
headless:
89+
runs-on: ubuntu-latest
90+
needs: build
91+
name: Test Headless Chrome (Ubuntu)
92+
steps:
93+
- name: Checkout
94+
uses: actions/checkout@v2
95+
- name: Setup node
96+
uses: actions/setup-node@v2-beta
97+
with:
98+
node-version: '14'
99+
check-latest: true
100+
- name: Use yarn cache
101+
uses: actions/cache@v2
102+
with:
103+
path: |
104+
./node_modules
105+
~/.npm-packages-offline-cache
106+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
107+
restore-keys: |
108+
${{ runner.os }}-yarn-
109+
${{ runner.os }}-
110+
- name: Use Firebase emulator cache
111+
uses: actions/cache@v2
112+
with:
113+
path: ~/.cache/firebase/emulators
114+
key: firebase_emulators
115+
- name: Install deps
116+
run: |
117+
yarn config set yarn-offline-mirror ~/.npm-packages-offline-cache
118+
yarn config set yarn-offline-mirror-pruning true
119+
yarn install --frozen-lockfile --prefer-offline
120+
- name: 'Download Artifacts'
121+
uses: actions/download-artifact@v2
99122
- name: Run tests
100-
run: yarn test:all
123+
run: |
124+
mv angularfire-${{ github.run_id }} dist
125+
yarn test:chrome-headless
101126
publish:
102127
runs-on: ubuntu-latest
103128
name: Publish (NPM)
104-
needs: test
129+
needs: ['test', 'headless']
105130
if: ${{ github.ref == 'refs/heads/master' || github.event_name == 'release' }}
106131
steps:
107132
- name: Setup node
@@ -113,7 +138,7 @@ jobs:
113138
uses: actions/download-artifact@v2
114139
- name: Publish
115140
run: |
116-
cd ./angularfire-${{ github.run_id }}/
141+
cd ./angularfire-${{ github.run_id }}/packages-dist
117142
chmod +x publish.sh
118143
./publish.sh
119144
env:

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*.spec.*
22
test-config.*
3+
publish.sh

package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
"description": "The official Angular library for Firebase.",
55
"private": true,
66
"scripts": {
7-
"test": "npm run test:node",
7+
"test": "npm run build:jasmine && npm run test:node",
88
"test:watch": "firebase emulators:exec --project=angularfire2-test \"ng test --watch=true --browsers=Chrome\"",
99
"test:chrome": "firebase emulators:exec --project=angularfire2-test \"ng test --watch=false --browsers=Chrome\"",
1010
"test:chrome-headless": "firebase emulators:exec --project=angularfire2-test \"ng test --watch=false --browsers=ChromeHeadless\"",
1111
"lint": "ng lint",
12-
"test:node": "tsc -p tsconfig.jasmine.json; cp ./dist/packages-dist/schematics/versions.json ./dist/out-tsc/jasmine/schematics && firebase emulators:exec --project=angularfire2-test \"node -r tsconfig-paths/register ./tools/jasmine.js\"",
12+
"test:node": "firebase emulators:exec --project=angularfire2-test \"node -r tsconfig-paths/register ./tools/jasmine.js\"",
1313
"test:typings": "node ./tools/run-typings-test.js",
1414
"test:build": "bash ./test/ng-build/build.sh",
1515
"test:all": "npm run test:node && npm run test:chrome-headless && npm run test:typings && npm run test:build",
1616
"build": "ttsc -p tsconfig.build.json; node ./tools/build.js",
17+
"build:jasmine": "tsc -p tsconfig.jasmine.json; cp ./dist/packages-dist/schematics/versions.json ./dist/out-tsc/jasmine/schematics",
1718
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 1"
1819
},
1920
"husky": {
@@ -118,5 +119,8 @@
118119
"typedoc": "^0.16.4",
119120
"typescript": ">=4.0.0 <4.1.0"
120121
},
121-
"typings": "index.d.ts"
122+
"typings": "index.d.ts",
123+
"resolutions": {
124+
"webpack": "5.4.0"
125+
}
122126
}

tools/build.sh

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ fi;
1616

1717
npm --no-git-tag-version --allow-same-version -f version $OVERRIDE_VERSION
1818
yarn build
19-
TARBALL=$(npm pack ./dist/packages-dist | tail -n 1)
20-
cp $TARBALL angularfire.tgz
19+
yarn build:jasmine
2120

22-
echo "npm publish \$(dirname \"\$0\")/angularfire.tgz --tag $NPM_TAG" > ./publish.sh
23-
chmod +x ./publish.sh
24-
25-
echo "tar -xzvf \$(dirname \"\$0\")/angularfire.tgz && rsync -a package/ ./dist/packages-dist/" > ./unpack.sh
26-
chmod +x ./unpack.sh
21+
echo "npm publish . --tag $NPM_TAG" > ./dist/packages-dist/publish.sh
22+
chmod +x ./dist/packages-dist/publish.sh

0 commit comments

Comments
 (0)