About the presenter
Presenter Name
☁️ Presenter Title
For questions or help with this series: msusdev@microsoft.com
All demos and source code available on GitHub:
Series road map
Session 1:Introduction to GitHub Actions
- Session 2:
- ↪️ Automatically build and test your code with GitHub Actions
- Session 3:
- Deploy your code to Azure with GitHub Actions
Today’s agenda
- Review GitHub Actions
- Automate build for a web app
::: notes
We’ll show you how to implement continuous integration (CI) for code maintained in GitHub repositories. You’ll learn to:
- Build a project in a workflow
- Create build assets for deployment
- Distribute builds as packages
:::
Review: GitHub Actions
::: notes
-
Create a GitHub repository with a single README file
-
Use Visual Studio Code to create a simple node project:
node_modules/ package-lock.json
{ "name": "simple", "main": "app.js" }
npm install --save moment
console.log('Hello, world!'); var moment = require('moment'); var date = moment().format('LL'); console.log(date);
Note: You can use GitHub Codespaces to perform this task quickly.
-
Create a .github/workflows/build.yml file.
Note: The name of this file is arbitrary. For the remainder of this demo, we will assume you named this file build.yml.
-
In the build.yml file, add and validate:
name: Node Continuous Integration on: push jobs: build-node: name: Build Node runs-on: ubuntu-latest container: node:14 steps: - run: node --version name: Check Node Version - run: npm --version name: Check NPM Version - uses: actions/checkout@v2 name: Checkout Code - run: npm install name: Install NPM Packages - run: node app.js name: Run Application
:::
Demo: Automate Build
::: notes
-
Create a GitHub repository using the msusdev-examples/contoso-spaces-next-web-app template.
-
Test the web app using the following commands:
npm install npm run dev
Note: You can use GitHub Codespaces to perform this task quickly.
-
Terminate the running
dev
command. -
Observe the
scripts.build
property of the package.json file. -
Create a .github/workflows/integration.yml file.
Note: The name of this file is arbitrary. For the remainder of this demo, we will assume you named this file integration.yml.
-
In the integration.yml file, create a build job and validate:
name: Build Next.js web application on: push jobs: build-project: name: Build Project runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 - name: Install NPM dependencies run: npm install - name: Build project assets run: npm run build
-
Upload an artifact and validate:
... - name: Upload static site uses: actions/upload-artifact@v2 with: name: static-site path: .next/
-
Create a release job and validate:
... release-project: name: Release Project runs-on: ubuntu-latest needs: build-project
-
Download an artifact in the release job and validate:
... steps: - name: Download site content uses: actions/download-artifact@v2 with: name: static-site
-
View the contents of the artifact and validate:
... - name: View content run: ls -R
-
Compress the folder and validate:
- name: Archive site content uses: thedoctor0/zip-release@master with: filename: site.zip
-
Create a GitHub release and validate:
- name: Create GitHub release uses: actions/create-release@v1 env: GITHUB_TOKEN: $ with: tag_name: $ release_name: Release $
-
Upload the final asset to release and validate:
- name: Create GitHub release id: create-new-release uses: actions/create-release@v1 env: GITHUB_TOKEN: $ with: tag_name: $ release_name: Release $ - name: Upload release asset uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: $ with: upload_url: $ asset_path: ./site.zip asset_name: site-v$.zip asset_content_type: application/zip
:::
Reviewing today’s session
- Review GitHub Actions
- Automate build for a web app
Reference Links
- https://github.com/actions/upload-artifact
- https://github.com/actions/download-artifact
- https://github.com/actions/create-release
- https://github.com/marketplace/actions/zip-release
Reference Links (continued)
- https://docs.github.com/actions/reference/workflow-syntax-for-github-actions
-
https://docs.github.com/actions/reference/context-and-expression-syntax-for-github-actions
- https://docs.github.com/actions/guides/publishing-docker-images
- https://github.com/docker/build-push-action/