Master GitHub Actions with hands-on labs and exercises. Learn how to automate workflows, run tests, deploy applications, and more using GitHub's powerful automation platform. This repository has everything you need to get started with continuous integration and continuous deployment.
In this lab, you will learn how to create a GitHub Actions workflow that uploads and downloads artifacts across multiple operating systems. You will configure a workflow to build an ASP.NET Core application on Windows, Ubuntu, and macOS, upload the generated artifacts, and then download and verify these artifacts.
Duration: 30-45 minutes
.github/workflows
directory in the root of your repository.upload-and-download-artifact-multiple-os.yml
.Open the newly created file and define the workflow name and trigger conditions:
name: Upload and Download Artifact on Multiple Operating Systems
on:
push:
paths:
- '.github/workflows/upload-and-download-artifact-multiple-os.yml'
- 'src/dotnet/WebApp/**'
workflow_dispatch:
push
trigger: Runs the workflow when changes are pushed to specific paths.workflow_dispatch
trigger: Allows you to manually trigger the workflow.jobs
section to define the upload
job, which builds and uploads artifacts across multiple operating systems.Use a matrix strategy to specify the OS:
jobs:
upload:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: $
defaults:
run:
working-directory: ./src/dotnet/WebApp
shell: bash
steps:
- name: Checkout Code
uses: actions/checkout@v4.1.7
- name: Set up .NET Core
uses: actions/setup-dotnet@v4.0.1
with:
dotnet-version: '8.x'
- name: Build Code
run: dotnet build --configuration Release
- name: Publish Code
run: |
if [[ "$RUNNER_OS" == "Windows" ]]; then
PUBLISH_DIR="$\\webapp"
else
PUBLISH_DIR="$/webapp"
fi
mkdir -p "$PUBLISH_DIR"
dotnet publish -c Release --output "$PUBLISH_DIR"
ls "$PUBLISH_DIR"
- name: Upload Artifact
uses: actions/upload-artifact@v4.3.6
with:
name: '.net-web-app-$'
path: $/webapp
Add the download
job to retrieve the uploaded artifacts and verify them:
download:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: $
needs: upload
defaults:
run:
shell: bash
steps:
- name: Download Artifact
uses: actions/download-artifact@v4.1.8
with:
name: '.net-web-app-$'
- name: List Downloaded Files
run: ls -R ./downloaded-artifacts
- name: Verify Artifact Content
run: echo "Downloaded artifact verified successfully."
needs
keyword: Ensures the download
job runs only after the upload
job completes."Add workflow for artifact upload and download on multiple OS"
.upload
job summary and confirm that artifacts are uploaded successfully for all operating systems.download
job logs to ensure artifacts were downloaded and listed correctly.In this lab, you created a GitHub Actions workflow to upload and download artifacts across multiple operating systems. You used matrix strategies to build and publish your ASP.NET Core application for Windows, Ubuntu, and macOS. Finally, you verified the workflow by downloading and inspecting the artifacts.