GitHub Actions Workflow: Prepare and Deploy Artifact
This document explains the structure and functionality of a GitHub Actions workflow designed to prepare and deploy artifacts for a GitHub Pages site. The workflow is manually triggered (workflow_dispatch
) and includes two main jobs: prepare_deploy_artifact
and deploy
.
Workflow Triggers
The workflow is triggered manually via the Run workflow button in the GitHub UI. It requires the following inputs:
- PageName:
- Description: Name of the artifact generated during the page generation process.
- Required: Yes
- Default:
latest
- PagePipelineID:
- Description: Pipeline ID of the workflow run that generated the page artifact.
- Required: Yes
- Default:
latest
- PackageName:
- Description: Name of the artifact generated during the package build process.
- Required: Yes
- Default:
latest
- PackagePipelineID:
- Description: Pipeline ID of the workflow run that generated the package artifact.
- Required: Yes
- Default:
latest
Jobs in the Workflow
1. Prepare and Deploy Artifact Job (prepare_deploy_artifact
)
Environment:
- Runs on:
ubuntu-latest
.
Steps:
- Download Pages Artifact:
- Downloads the artifact generated during the page generation process into the
pages
directory. - Uses the
actions/download-artifact@v4
action with the providedPageName
andPagePipelineID
.
- Downloads the artifact generated during the page generation process into the
- Download Packages Artifact:
- Downloads the artifact generated during the package build process into the
pages
directory. - Uses the
actions/download-artifact@v4
action with the providedPackageName
andPackagePipelineID
.
- Downloads the artifact generated during the package build process into the
- List Files:
- Lists the contents of the
pages
directory to verify that the artifacts were downloaded successfully.
- Lists the contents of the
- Upload Combined Artifact:
- Uploads the combined contents of the
pages
directory as a new artifact nameddeploy_artifact
usingactions/upload-pages-artifact@v3
.
- Uploads the combined contents of the
2. Deploy Job (deploy
)
Conditions:
- Runs only if the trigger is from the
main
branch (github.ref == 'refs/heads/main'
). - Depends on the successful completion of the
prepare_deploy_artifact
job.
Permissions:
- Grants the necessary permissions for deploying to GitHub Pages:
contents: read
pages: write
id-token: write
Environment:
- Specifies the
github-pages
environment. - Sets the URL of the deployed site to
$
.
Steps:
- Deploy to GitHub Pages:
- Deploys the previously uploaded artifact (
deploy_artifact
) to GitHub Pages usingactions/deploy-pages@v4
.
- Deploys the previously uploaded artifact (
Key Features
- Manual Triggering:
- The workflow is designed to be manually triggered, allowing flexibility in specifying the artifacts and pipeline IDs.
- Artifact Management:
- Combines artifacts from two separate workflows (page generation and package build) into a single directory (
pages
) for deployment.
- Combines artifacts from two separate workflows (page generation and package build) into a single directory (
- Environment Configuration:
- Configures the
github-pages
environment with appropriate permissions and outputs the deployed site’s URL.
- Configures the
- Verification:
- Includes a step to list the contents of the
pages
directory, ensuring that the artifacts are correctly downloaded before proceeding.
- Includes a step to list the contents of the
Example Use Case
This workflow is ideal for automating the deployment of a GitHub Pages site that relies on artifacts generated by multiple upstream workflows. For example:
- The
PageGeneration
workflow generates static HTML files for documentation. - The
build_packages
workflow generates downloadable assets (e.g., ISOs or binaries).
By combining these artifacts into a single directory and deploying them to GitHub Pages, you can create a unified site that hosts both documentation and downloadable assets.