VuePress GitHub Actions Deployment¶
VuePress GitHub Actions Deployment is an automated workflow configuration that enables the continuous deployment of a VuePress project to a GitHub repository (such as a GitHub Pages site) whenever code is pushed to the main branch.^[600-developer__blog__vuepress-blog__vuepress-init.md]
Workflow Configuration¶
The deployment process is defined in a YAML file, typically located at .github/workflows/ci.yml.^[600-developer__blog__vuepress-blog__vuepress-init.md] The configuration generally consists of three main stages: source acquisition, environment setup, and deployment.^[600-developer__blog__vuepress-blog__vuepress-init.md]
Triggers¶
The workflow is designed to run automatically under specific conditions.^[600-developer__blog__vuepress-blog__vuepress-init.md]
- Push events: The deployment triggers whenever code is pushed to the
mainbranch.^[600-developer__blog__vuepress-blog__vuepress-init.md] - Manual dispatch: The workflow can also be triggered manually via the GitHub interface.^[600-developer__blog__vuepress-blog__vuepress-init.md]
Execution Steps¶
The job typically runs on an ubuntu-latest environment and involves the following steps:^[600-developer__blog__vuepress-blog__vuepress-init.md]
- Checkout: This step uses
actions/checkout@v3to clone the repository.^[600-developer__blog__vuepress-blog__vuepress-init.md] It is configured withfetch-depth: 0to ensure that the full git history is retrieved, which is necessary for displaying accurate "Last Updated" timestamps.^[600-developer__blog__vuepress-blog__vuepress-init.md] - Node Setup: The environment is prepared using
actions/setup-node@v3to install a specific version of Node.js (e.g.,16.3.0).^[600-developer__blog__vuepress-blog__vuepress-init.md] - Clean and Install: The workflow cleans the build directory (usually
./public) and runsnpm install -Dto install project dependencies.^[600-developer__blog__vuepress-blog__vuepress-init.md] - Deploy: Finally, an action such as
jenkey2011/vuepress-deploy@masteris used to execute the build script and push the output to the target repository.^[600-developer__blog__vuepress-blog__vuepress-init.md]
Environment Variables¶
The deployment step requires specific environment variables to authenticate and identify the target location.^[600-developer__blog__vuepress-blog__vuepress-init.md]
- ACCESS_TOKEN: A Personal Access Token stored in the repository's secrets, allowing the workflow to write to the target repository.^[600-developer__blog__vuepress-blog__vuepress-init.md]
- TARGET_REPO: The GitHub repository where the static files will be deployed (e.g.,
username/repo.github.io).^[600-developer__blog__vuepress-blog__vuepress-init.md] - TARGET_BRANCH: The branch in the target repository that will be updated (e.g.,
master).^[600-developer__blog__vuepress-blog__vuepress-init.md] - BUILD_SCRIPT: The command to build the VuePress site (typically
npm run build).^[600-developer__blog__vuepress-blog__vuepress-init.md] - BUILD_DIR: The directory where the build output is generated, which matches the
destconfiguration inconfig.js(usuallypublic).^[600-developer__blog__vuepress-blog__vuepress-init.md]
Configuration Requirements¶
To ensure the deployment functions correctly with VuePress and the source repository, specific configurations are necessary:
- Build Directory: The
config.jsmust define adestfield (e.g.,'public') specifying the output folder.^[600-developer__blog__vuepress-blog__vuepress-init.md] - Path Constraints: File paths in the project should not contain Chinese characters to prevent build errors.^[600-developer__blog__vuepress-blog__vuepress-init.md]
- Relative Links: Image links should use relative paths.^[600-developer__blog__vuepress-blog__vuepress-init.md]
Related Concepts¶
- [[VuePress]]
- CI/CD
Sources¶
^[600-developer__blog__vuepress-blog__vuepress-init.md]