title | description | author | ms.author | ms.date | ms.topic |
---|---|---|---|---|---|
Tutorial: Authenticate vcpkg Git-based registries in GitHub Actions |
Learn to configure Git credentials for private repositories when using vcpkg on GitHub Actions |
vicroms |
viromer |
01/10/2024 |
tutorial |
When using vcpkg with private registries it is necessary to provide access credentials to authenticate Git operations executed internally by vcpkg.
In this tutorial you will learn how to authenticate a private Git repository to use in your GitHub Actions workflow.
[!div class="checklist"]
- A GitHub account
- A private vcpkg Git-registry hosted on GitHub
- vcpkg
Follow the instructions on GitHub to generate a fine-grained Personal Access Token (PAT) and grant it permission to access the private repository where your vcpkg Git registry is hosted.
Note
Never store a GitHub Personal Access Token in your repository files
The next step is to follow GitHub's instructions to store the PAT as a secret available in your GitHub Actions workflows.
Now is time to add an authentication step to your workflow, use the following template
in your workflow's YAML file. Replace PRIVATE_REPO_URL
with the URL of your private repository,
for example: https://github.com/Microsoft/secret-vcpkg-registry
; replace PRIVATE_REGISTRY_PAT
with the name of the secret variable you created in the previous step.
This workflow step must run before any other workflow step that invokes vcpkg.
- name: Authenticate private registries
shell: bash
run: git config --global credential.PRIVATE_REPO_URL.helper '!f() { echo username=unused; echo password=${{secrets.PRIVATE_REGISTRY_PAT }}; }; f'
The following example shows how to provide Git credentials for multiple private
repositories using the credential.<url>.helper
pattern.
- name: Authenticate private registries
shell: bash
run: |
git config --global credential.https://github.com/vcpkg/private_registry.helper '!f() { echo username=unused; echo password=${{secrets.private_registry_pat}}; }; f'
git config --global credential.https://github.com/vcpkg/secret_registry.helper `!f() { echo username=unused; echo password=${{secrets.secret_registry_pat}}; }; f'