Skip to content

Commit

Permalink
chore(): Optimize caching in Github Actions (#2702)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jamesdaniels authored Dec 3, 2020
1 parent da8c660 commit de46399
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 601 deletions.
65 changes: 45 additions & 20 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,11 @@ jobs:
uses: actions/setup-node@v2-beta
with:
node-version: '14'
- name: Get cache directory
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Use yarn cache
uses: actions/cache@v2
with:
path: |
${{ steps.yarn-cache-dir-path.outputs.dir }}
./node_modules
~/.npm-packages-offline-cache
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
Expand All @@ -37,7 +34,6 @@ jobs:
- name: Install deps
run: |
yarn config set yarn-offline-mirror ~/.npm-packages-offline-cache
yarn config set yarn-offline-mirror-pruning true
yarn install --frozen-lockfile --prefer-offline
- name: Build
id: yarn-pack-dir
Expand All @@ -46,10 +42,7 @@ jobs:
uses: actions/upload-artifact@v2
with:
name: angularfire-${{ github.run_id }}
path: |
angularfire.tgz
publish.sh
unpack.sh
path: dist
retention-days: 1
test:
runs-on: ubuntu-latest
Expand All @@ -66,14 +59,11 @@ jobs:
with:
node-version: ${{ matrix.node }}
check-latest: true
- name: Get cache directory
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Use yarn cache
uses: actions/cache@v2
with:
path: |
${{ steps.yarn-cache-dir-path.outputs.dir }}
./node_modules
~/.npm-packages-offline-cache
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
Expand All @@ -91,17 +81,52 @@ jobs:
yarn install --frozen-lockfile --prefer-offline
- name: 'Download Artifacts'
uses: actions/download-artifact@v2
- name: Expand Artifact
- name: Run tests
run: |
mkdir -p dist/packages-dist
chmod +x angularfire-${{ github.run_id }}/unpack.sh
./angularfire-${{ github.run_id }}/unpack.sh
mv angularfire-${{ github.run_id }} dist
yarn test:node
headless:
runs-on: ubuntu-latest
needs: build
name: Test Headless Chrome (Ubuntu)
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v2-beta
with:
node-version: '14'
check-latest: true
- name: Use yarn cache
uses: actions/cache@v2
with:
path: |
./node_modules
~/.npm-packages-offline-cache
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
${{ runner.os }}-
- name: Use Firebase emulator cache
uses: actions/cache@v2
with:
path: ~/.cache/firebase/emulators
key: firebase_emulators
- name: Install deps
run: |
yarn config set yarn-offline-mirror ~/.npm-packages-offline-cache
yarn config set yarn-offline-mirror-pruning true
yarn install --frozen-lockfile --prefer-offline
- name: 'Download Artifacts'
uses: actions/download-artifact@v2
- name: Run tests
run: yarn test:all
run: |
mv angularfire-${{ github.run_id }} dist
yarn test:chrome-headless
publish:
runs-on: ubuntu-latest
name: Publish (NPM)
needs: test
needs: ['test', 'headless']
if: ${{ github.ref == 'refs/heads/master' || github.event_name == 'release' }}
steps:
- name: Setup node
Expand All @@ -113,7 +138,7 @@ jobs:
uses: actions/download-artifact@v2
- name: Publish
run: |
cd ./angularfire-${{ github.run_id }}/
cd ./angularfire-${{ github.run_id }}/packages-dist
chmod +x publish.sh
./publish.sh
env:
Expand Down
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.spec.*
test-config.*
publish.sh
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
"description": "The official Angular library for Firebase.",
"private": true,
"scripts": {
"test": "npm run test:node",
"test": "npm run build:jasmine && npm run test:node",
"test:watch": "firebase emulators:exec --project=angularfire2-test \"ng test --watch=true --browsers=Chrome\"",
"test:chrome": "firebase emulators:exec --project=angularfire2-test \"ng test --watch=false --browsers=Chrome\"",
"test:chrome-headless": "firebase emulators:exec --project=angularfire2-test \"ng test --watch=false --browsers=ChromeHeadless\"",
"lint": "ng lint",
"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\"",
"test:node": "firebase emulators:exec --project=angularfire2-test \"node -r tsconfig-paths/register ./tools/jasmine.js\"",
"test:typings": "node ./tools/run-typings-test.js",
"test:build": "bash ./test/ng-build/build.sh",
"test:all": "npm run test:node && npm run test:chrome-headless && npm run test:typings && npm run test:build",
"build": "ttsc -p tsconfig.build.json; node ./tools/build.js",
"build:jasmine": "tsc -p tsconfig.jasmine.json; cp ./dist/packages-dist/schematics/versions.json ./dist/out-tsc/jasmine/schematics",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 1"
},
"husky": {
Expand Down Expand Up @@ -118,5 +119,8 @@
"typedoc": "^0.16.4",
"typescript": ">=4.0.0 <4.1.0"
},
"typings": "index.d.ts"
"typings": "index.d.ts",
"resolutions": {
"webpack": "5.4.0"
}
}
10 changes: 3 additions & 7 deletions tools/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ fi;

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

echo "npm publish \$(dirname \"\$0\")/angularfire.tgz --tag $NPM_TAG" > ./publish.sh
chmod +x ./publish.sh

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

0 comments on commit de46399

Please sign in to comment.