Skip to content

Instantly share code, notes, and snippets.

@atemate
Last active July 24, 2023 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atemate/94110c920b7fd843119ab1bf90038de0 to your computer and use it in GitHub Desktop.
Save atemate/94110c920b7fd843119ab1bf90038de0 to your computer and use it in GitHub Desktop.
GitHub Action to install a python package from a private GCP repostiroty (artifact registry)
name: Setup private pypi - GCP Artifact Registry
inputs:
central_project:
type: string
required: true
description: GCP project where the Artifact Registry is located
central_repo:
type: string
required: true
description: Repository name in the Artifact Registry
central_repo_location:
type: string
required: true
description: Repository location in the Artifact Registry
runs:
using: composite
steps:
- name: Configure pip access to GCP Artifact Registry
env:
central_project: ${{ inputs.central_project }}
central_repo: ${{ inputs.central_repo }}
central_repo_location: ${{ inputs.central_repo_location }}
shell: bash
run: |
set -eux
pip install -q -U keyring keyrings.google-artifactregistry-auth
keyring --list-backends
gcloud auth list
PYPIRC_PATH=$HOME/.pypirc
gcloud artifacts print-settings python \
--project=${central_project} --repository=${central_repo} --location=${central_repo_location} \
--json-key=${{ steps.auth.outputs.credentials_file_path }} > $PYPIRC_PATH
PIP_CONF_PATH="$HOME/.config/pip/pip.conf"
mkdir -p $(dirname $PIP_CONF_PATH)
cat <<END > $PIP_CONF_PATH
[global]
extra-index-url = https://${central_repo_location}-python.pkg.dev/${central_project}/${central_repo}/simple/
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment