Skip to content

Commit c6e5a4b

Browse files
authored
Allows the workflow to configure access to private Go modules. (#33)
* Fix _checks-golang * Adds support for private Go modules Allows the workflow to configure access to private Go modules. It adds an input parameter `goprivate` to specify the module path prefixes. It also configures Git to use the GitHub App token for authentication when accessing private repositories. * _atlas-migratios: Enables checkout using GitHub App authentication Adds support for authenticating with a GitHub App to access private repositories. This allows the workflow to checkout code and configure Git using the GitHub App's token, enabling access to repositories without relying on user-specific credentials. Also adds support for configuring GOPRIVATE environment variable. * Enables GitHub App authentication for private repos Adds support for authenticating with a GitHub App to access private repositories during the build process. This allows the workflow to clone private repositories and use their contents during the Docker image build. It configures Git to use a GitHub App token for authentication and passes the token as a build argument. * minor changes * minor change * minor changes * minor change * test actions * changes * test new branch * test on checks-golang * use @main actions
1 parent 32c62f3 commit c6e5a4b

3 files changed

Lines changed: 85 additions & 8 deletions

File tree

.github/workflows/_atlas-migrations-reusable.yml

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,31 @@ on:
6262
description: "Whether to use Google Cloud SQL instead of traditional PostgreSQL"
6363
type: boolean
6464
default: false
65+
github_app_auth:
66+
description: "Use GitHub App Token"
67+
required: false
68+
type: boolean
69+
default: false
70+
github_app_repos:
71+
description: "Additional repositories to access (one per line)"
72+
required: false
73+
type: string
74+
default: ""
75+
goprivate:
76+
description: "Comma-separated list of module path prefixes for GOPRIVATE"
77+
required: false
78+
type: string
79+
default: ""
6580
secrets:
6681
DATABASE_URL:
6782
description: "Database connection URL for the target environment (for traditional PostgreSQL)"
6883
required: false
84+
app_id:
85+
description: "GitHub App ID"
86+
required: false
87+
app_pem:
88+
description: "GitHub App PEM"
89+
required: false
6990
outputs:
7091
migration_status:
7192
description: "Status of the migration operation"
@@ -98,8 +119,17 @@ jobs:
98119
- 5432:5432
99120

100121
steps:
101-
- name: Checkout code
102-
uses: actions/checkout@v4
122+
- name: Checkout with GitHub App
123+
id: checkout
124+
uses: zondax/_actions/checkout-with-app@main
125+
with:
126+
github_app_auth: ${{ inputs.github_app_auth }}
127+
github_app_repos: ${{ inputs.github_app_repos }}
128+
patch_git_config: false
129+
checkout_submodules: true
130+
app_id: ${{ secrets.app_id }}
131+
app_pem: ${{ secrets.app_pem }}
132+
goprivate: ${{ inputs.goprivate }}
103133

104134
- name: Setup Go
105135
uses: actions/setup-go@v4

.github/workflows/_checks-golang.yaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ on:
4545
required: false
4646
type: boolean
4747
default: true
48+
goprivate:
49+
description: "Comma-separated list of module path prefixes for GOPRIVATE"
50+
required: false
51+
type: string
52+
default: ""
4853
secrets:
4954
app_id:
5055
description: "GitHub App ID"
@@ -71,15 +76,15 @@ jobs:
7176

7277
steps:
7378
- name: Checkout with GitHub App
79+
id: checkout
7480
uses: zondax/_actions/checkout-with-app@main
7581
with:
7682
github_app_auth: ${{ inputs.github_app_auth }}
77-
github_app_repos: |
78-
${{ github.repository }}
79-
${{ inputs.github_app_repos }}
83+
github_app_repos: ${{ inputs.github_app_repos }}
8084
checkout_submodules: true
8185
app_id: ${{ secrets.app_id }}
8286
app_pem: ${{ secrets.app_pem }}
87+
goprivate: ${{ inputs.goprivate }}
8388

8489
- name: Build
8590
run: |

.github/workflows/_cloud-run-build-docker.yml

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,27 @@ on:
2626
required: false
2727
type: string
2828
default: ''
29+
github_app_auth:
30+
description: "Use GitHub App Token"
31+
required: false
32+
type: boolean
33+
default: false
34+
github_app_repos:
35+
description: "Additional repositories to access (one per line)"
36+
required: false
37+
type: string
38+
default: ""
2939
outputs:
3040
image_tag:
3141
description: "The full tag of the built image."
3242
value: ${{ jobs.build.outputs.image_tag }}
43+
secrets:
44+
app_id:
45+
description: "GitHub App ID"
46+
required: false
47+
app_pem:
48+
description: "GitHub App PEM"
49+
required: false
3350
jobs:
3451
build:
3552
runs-on: zondax-runners
@@ -41,7 +58,16 @@ jobs:
4158
contents: read # Required for actions/checkout and GitHub API access
4259
pull-requests: write # Required for commenting on PRs
4360
steps:
44-
- uses: actions/checkout@v4
61+
- name: Checkout with GitHub App
62+
id: checkout
63+
uses: zondax/_actions/checkout-with-app@main
64+
with:
65+
github_app_auth: ${{ inputs.github_app_auth }}
66+
github_app_repos: ${{ inputs.github_app_repos }}
67+
patch_git_config: false
68+
checkout_submodules: true
69+
app_id: ${{ secrets.app_id }}
70+
app_pem: ${{ secrets.app_pem }}
4571
- name: Authenticate with GCP
4672
uses: zondax/_actions/gcp-wif-auth@main
4773
with:
@@ -64,6 +90,15 @@ jobs:
6490
DOCKERFILE_FLAGS+=" -f $f"
6591
done
6692
IMAGE_TAG_SHA="${{ vars.PULUMI_GAR_LOCATION }}-docker.pkg.dev/${{ vars.PULUMI_GCP_PROJECT_ID }}/${{ vars.PULUMI_GAR_REPOSITORY }}/${{ inputs.image_name }}:${{ github.sha }}"
93+
94+
# Use Docker secrets for GitHub token if GitHub App auth is enabled
95+
if [ "${{ inputs.github_app_auth }}" = "true" ]; then
96+
echo "${{ steps.checkout.outputs.token }}" > /tmp/github_token
97+
SECRET_ARGS="--secret id=github_token,src=/tmp/github_token"
98+
else
99+
SECRET_ARGS=""
100+
fi
101+
67102
if [ "${{ inputs.build_tool }}" = "bake" ]; then
68103
# If bake_targets is set, add them as arguments
69104
BAKE_TARGETS=""
@@ -73,10 +108,17 @@ jobs:
73108
BAKE_TARGETS+=" $t"
74109
done
75110
fi
76-
docker buildx bake $DOCKERFILE_FLAGS $BAKE_TARGETS --set "*.tags=$IMAGE_TAG_SHA"
111+
if [ "${{ inputs.github_app_auth }}" = "true" ]; then
112+
docker buildx bake $DOCKERFILE_FLAGS $BAKE_TARGETS --set "*.tags=$IMAGE_TAG_SHA" --secret id=github_token,src=/tmp/github_token
113+
else
114+
docker buildx bake $DOCKERFILE_FLAGS $BAKE_TARGETS --set "*.tags=$IMAGE_TAG_SHA"
115+
fi
77116
else
78-
docker build $DOCKERFILE_FLAGS --tag "$IMAGE_TAG_SHA" .
117+
docker build $DOCKERFILE_FLAGS $SECRET_ARGS --tag "$IMAGE_TAG_SHA" .
79118
fi
119+
120+
# Clean up token file
121+
[ -f /tmp/github_token ] && rm -f /tmp/github_token
80122
echo "image_tag=$IMAGE_TAG_SHA" >> $GITHUB_OUTPUT
81123
- name: Push Docker image to Artifact Registry
82124
run: |

0 commit comments

Comments
 (0)