-
Notifications
You must be signed in to change notification settings - Fork 0
79 lines (69 loc) · 2.51 KB
/
publish.yaml
File metadata and controls
79 lines (69 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
name: Release and Publish to Google Artifact Registry
permissions:
id-token: write
contents: read
on:
push:
tags:
- "v*.*.*"
jobs:
publish-gar:
name: Build and Publish to GAR
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- name: Validate tag format
env:
TAG: ${{ github.ref_name }}
run: |
VERSION="${TAG#v}"
if ! [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Invalid version format '$VERSION'. Expected format: x.y.z"
exit 1
fi
echo "Releasing version: $VERSION (from tag: $TAG)"
- name: Verify GitHub Release exists
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ github.ref_name }}
run: |
if ! gh release view "$TAG" --repo "$GITHUB_REPOSITORY" > /dev/null 2>&1; then
echo "Error: No GitHub Release found for tag '$TAG'."
echo "Create a release via GitHub UI instead of pushing tags manually."
exit 1
fi
- name: Verify tag is on master
env:
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
run: |
git fetch origin "$DEFAULT_BRANCH" --quiet
if ! git merge-base --is-ancestor "$GITHUB_SHA" "origin/$DEFAULT_BRANCH"; then
echo "Error: Tag commit $GITHUB_SHA is not reachable from origin/$DEFAULT_BRANCH."
echo "Only tags on the $DEFAULT_BRANCH branch can be published."
exit 1
fi
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install build dependencies
run: pip install build twine setuptools-scm
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v3
with:
token_format: "access_token"
workload_identity_provider: "projects/668763687485/locations/global/workloadIdentityPools/github/providers/github"
service_account: "github-experimentation@optimizely-iac.iam.gserviceaccount.com"
- name: Build and Publish
run: |
python -m build
python -m twine upload \
--repository-url https://us-east1-python.pkg.dev/artifact-registry-e3ca/private-python/ \
--username oauth2accesstoken \
--password ${{ steps.auth.outputs.access_token }} \
dist/*