Skip to content

Commit b1dd714

Browse files
committed
wip - refactor entire workflow to work around GH secrets uselessness
1 parent d6a8277 commit b1dd714

5 files changed

Lines changed: 109 additions & 69 deletions

File tree

.github/workflows/publish-python-packages.yaml

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,33 @@ on:
66
paths:
77
- '**/pyproject.toml'
88
- 'packages/**/__about__.py'
9+
inputs:
10+
aws_account_id:
11+
description: The AWS account ID that owns the CodeArtifact domain
12+
type: string
13+
required: false
14+
default: 505071440022
15+
aws_region:
16+
description: The AWS region where the CodeArtifact repository is hosted
17+
type: string
18+
required: false
19+
default: us-west-2
20+
aws_iam_role_name:
21+
description: The name of the IAM role to assume for accessing CodeArtifact
22+
type: string
23+
required: false
24+
default: GithubActions_Schema_CodeArtifact_Publish
25+
domain:
26+
description: The CodeArtifact domain name
27+
type: string
28+
required: false
29+
default: overture-pypi
30+
repository:
31+
description: The CodeArtifact repository name
32+
type: string
33+
required: false
34+
default: overture
35+
936

1037
permissions:
1138
id-token: write
@@ -19,11 +46,6 @@ jobs:
1946
before_commit: ${{ github.event.before }}
2047
after_commit: ${{ github.event.after }}
2148

22-
get-index-url:
23-
uses: ./.github/workflows/reusable-get-code-artifact-index-url.yaml
24-
with:
25-
role_name: GithubActions_Schema_CodeArtifact_Publish
26-
2749
publish:
2850
needs: [check, get-index-url]
2951
if: github.event.repository.full_name == github.repository && needs.check.outputs.num_changed_packages > 0
@@ -43,8 +65,18 @@ jobs:
4365
- name: Sync code to make packages visible to Python
4466
run: uv sync --all-packages
4567

68+
- name: Get CodeArtifact index URL
69+
id: get-code-artifact-index-url
70+
run: |
71+
echo 'index_url=<<EOF' >> $GITHUB_OUTPUT
72+
./.github/workflows/scripts/get-code-artifact-index-url.sh \
73+
"${{ inputs.aws_account_id }}" "${{ inputs.aws_region }}" \
74+
"${{ inputs.domain }}" "${{ inputs.repository }}" >> $GITHUB_OUTPUT
75+
echo EOF >> $GITHUB_OUTPUT
76+
4677
- name: Publish package ${{ matrix.package }} version ${{ matrix.after }} to PyPI
4778
run: |
79+
echo TODO: TEMP: VERIFY: "${{ steps.get-code-artifact-index-url.index_url }}" TODO DELETE THIS DO NOT MERGE
4880
package="${{ matrix.package }}"
4981
before="${{ matrix.before }}"
5082
after="${{ matrix.after }}"
@@ -60,5 +92,4 @@ jobs:
6092
echo " Source tarball file [$tarball] not found. Aborting!"
6193
exit 1
6294
fi
63-
printf "TODO: DELETE THIS temporary %s\n" "${{ needs.get-index-url.secrets.index_url }}"
64-
uv publish "$wheel" "$tarball" --publish-url "${{ needs.get-index-url.secrets.index_url }}"
95+
uv publish "$wheel" "$tarball" --publish-url "${{ steps.get-code-artifact-index-url.index_url }}"

.github/workflows/reusable-check-python-package-versions.yaml

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,31 @@ on:
1515
PR or the latest commit in a push.
1616
type: string
1717
required: true
18+
aws_account_id:
19+
description: The AWS account ID that owns the CodeArtifact domain
20+
type: string
21+
required: false
22+
default: 505071440022
23+
aws_region:
24+
description: The AWS region where the CodeArtifact repository is hosted
25+
type: string
26+
required: false
27+
default: us-west-2
28+
aws_iam_role_name:
29+
description: The name of the IAM role to assume for accessing CodeArtifact
30+
type: string
31+
required: false
32+
default: GithubActions_Schema_CodeArtifact_ReadOnly
33+
domain:
34+
description: The CodeArtifact domain name
35+
type: string
36+
required: false
37+
default: overture-pypi
38+
repository:
39+
description: The CodeArtifact repository name
40+
type: string
41+
required: false
42+
default: overture
1843
outputs:
1944
changed_packages:
2045
description: >-
@@ -27,9 +52,6 @@ on:
2752

2853

2954
jobs:
30-
get-index-url:
31-
uses: ./.github/workflows/reusable-get-code-artifact-index-url.yaml
32-
3355
check-python-package-versions:
3456
needs: get-index-url
3557
runs-on: ubuntu-latest
@@ -90,13 +112,30 @@ jobs:
90112
echo EOF >> $GITHUB_OUTPUT
91113
printf 'num_changed_packages=%s\n' "$(jq -c '. | length' /tmp/package-version-diff.json)" >> $GITHUB_OUTPUT
92114
115+
- name: Configure AWS credentials
116+
uses: aws-actions/configure-aws-credentials@v4
117+
with:
118+
aws-region: ${{ inputs.aws_region }}
119+
role-to-assume: arn:aws:iam::${{ inputs.aws_account_id }}:role/${{ inputs.aws_iam_role_name }}
120+
role-session-name: GitHubActions_${{github.job}}_${{github.run_id}}
121+
122+
- name: Get CodeArtifact index URL
123+
id: get-code-artifact-index-url
124+
run: |
125+
echo 'index_url=<<EOF' >> $GITHUB_OUTPUT
126+
./.github/workflows/scripts/get-code-artifact-index-url.sh \
127+
"${{ inputs.aws_account_id }}" "${{ inputs.aws_region }}" \
128+
"${{ inputs.domain }}" "${{ inputs.repository }}" >> $GITHUB_OUTPUT
129+
echo EOF >> $GITHUB_OUTPUT
130+
93131
- name: Fail if any of the new versions already exist in the repo
94132
run: |
133+
echo TODO: TEMP: VERIFY: "${{ steps.get-code-artifact-index-url.index_url }}" TODO DELETE THIS DO NOT MERGE
95134
jq -c '.[]' /tmp/package-version-diff.json | while read -r entry; do
96135
package=$(echo "$entry" | jq -r '.package')
97136
after=$(echo "$entry" | jq -r '.after')
98137
exit_code=0
99-
output=$(uv run pip download "${package}==${after}" --index-url "${{ needs.get-index-url.secrets.index_url }}simple/" --no-deps -d /tmp --quiet 2>&1) || exit_code=$?
138+
output=$(uv run pip download "${package}==${after}" --index-url "${{ steps.get-code-artifact-index-url.index_url }}simple/" --no-deps -d /tmp --quiet 2>&1) || exit_code=$?
100139
if [[ $exit_code -eq 0 || (
101140
"${output,,}" != *"could not find a version"* &&
102141
"${output,,}" != *"no matching distributions"*

.github/workflows/reusable-get-code-artifact-index-url.yaml

Lines changed: 0 additions & 57 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
if [ $# -ne 4 ]; then
6+
>&2 echo "Usage: $0 <aws_account_id> <aws_region> <domain> <repository>"
7+
exit 1
8+
fi
9+
10+
readonly aws_account_id="$1"
11+
readonly aws_region="$2"
12+
readonly domain="$3"
13+
readonly repository="$4"
14+
15+
# Use the `aws-actions/configure-aws-credentials` GitHub action before calling this script to
16+
# ensure the necessary AWS credentials, for an appropriate role, are available in the environment.
17+
18+
auth_token=$( \
19+
aws codeartifact get-authorization-token \
20+
--region "$aws_region" \
21+
--domain "$domain" \
22+
--domain-owner "$aws_account_id" \
23+
--query authorizationToken \
24+
--output text)
25+
26+
printf "https://aws:%s@%s-%s.d.codeartifact.%s.amazonaws.com/\n" \
27+
"$auth_token" "$domain" "$aws_account_id" "$aws_region"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
__version__ = "0.1.0"
22

3-
# TEMPORARY COMMENT updated, again, and again, and again, and again
3+
# TEMPORARY COMMENT updated, again, and again, and again, and again, and again

0 commit comments

Comments
 (0)