29
loading...
This website collects cookies to deliver better user experience
Do you want to build your first Angular App and deploy over cloud using GitHub Actions? How to deploy/publish Angular App to GitHub Pages automatically? Did you use GitHub Actions to build and deploy Angular App over GitHub Pages? Stay tuned in this article I will show you step by step from creating angular app to building and deploying using GitHub Actions.
ng new sample-app
ng add angular-cli-ghpages
CI=true
by default. Learn more here…name: Angular GitHub CI # 👈
main
branch got new push.on:
push:
branches:
- main # 👈
ubuntu-latest
.jobs:
ci:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x, 12.x]
# 👆
node10
and node12
/ Therefore, at a time there will be parallelly 2 jobs will run one for 10.x and one for 12.x
steps:
- uses:
actions/checkout@v2
# 👆
- name: Use Node.js $
- uses: actions/setup-node@v1
with:
node-version:
$
# 👆
node_modules
. Learn more about Caching GitHub Workflow dependencies here.- name: Install Dependencies
if:
steps.cache-nodemodules.outputs.cache-hit != 'true'
# 👆 if cache hits the skip this step.
run: npm ci
production mode
to compile our project. We need to pass -- --prod
so that ng build --prod
will be executed.- name: Build
run: npm run build -- --prod
- name: Lint
run: npm run lint
"browsers": "ChromeHeadless"
and"codeCoverage": true,
"sourceMap": false
“watch”: false
angular.json
file.angular.json
file identify project name.projects.sample-app.architect.test
"configurations": {
"production": {
"sourceMap": false,
"codeCoverage": true,
"browsers": "ChromeHeadless",
"watch": false
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"configurations": { 👈
"production": {
"sourceMap": false,
"codeCoverage": true,
"browsers": "ChromeHeadless",
"watch": false
}
},👈
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.scss"
],
"scripts": []
}
},
main.yml
file. Which will use above production test configuration while running in build machine.- name: Test
run: npm run test -- --prod
CI
job.ng deploy
is the Angular CLI command that automates the deployment of Angular App to GitHub Pages. When you run ng deploy
, it executes a builder that performs the deployment for you.angular-cli-ghpages
builder by Running script ng add angular-cli-ghpages
on command line from root of your project.base-href
to our repository name
so that It can host our static files successfully. Since our GitHub repository name is angular-ci-cd-with-github-actions
my deploy script would be: ng deploy --base-href=/angular-ci-cd-with-github-actions/
package.json
"deploy": "ng deploy --base-href=/angular-ci-cd-with-github-actions/"
npm run deploy
if: success()
is always implied unless you specify if: always()
or if: failure()
. Therefore, I am not adding if condition in my steps.TOKEN_GITHUB_ACTION
to your repository.- name: Conventional Changelog Action
id: changelog
uses: TriPSs/conventional-changelog-action@v3
with:
github-token: $
output-file: 'false'
- name: Deploy
run: |
npm run deploy
Rupesh
and you can ask doubts/questions and get more help, tips and tricks.Your bright future is awaiting for you so visit today FullstackMaster and allow me to help you to board on your dream software company as a new Software Developer, Architect or Lead Engineer role.