Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reusable_go_lint_test: Support private repo authentication #8

Merged
merged 14 commits into from
Sep 1, 2024
20 changes: 20 additions & 0 deletions .github/workflows/reusable_docker_pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ on:
type: string
description: "Custom repository name"
default: ""
go-private-repos-authentication:
description: 'Enable authentication for private repositories'
type: boolean
default: false

jobs:
docker_build:
Expand All @@ -47,6 +51,21 @@ jobs:
else
echo "IMAGE_NAME=$(echo $GITHUB_REPOSITORY | cut -d '/' -f 2)" >> $GITHUB_ENV
fi

# This block is used to not hard-coded the secrets in Build Docker image
# Secrets are only added when necessary
- name: Generate and mask build secrets
id: set-build-secrets
run: |
SECRETS=""
if [ -n "${{ inputs.go-private-repos-authentication }}" ]; then
SECRETS+='"GO_PRIVATE_TOKEN=${{ secrets.GO_PRIVATE_TOKEN }}"\n'
fi
echo "::add-mask::$SECRETS"
echo "SECRETS<<EOF" >> $GITHUB_OUTPUT
echo -e "$SECRETS" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
shell: bash

- name: Build Docker image
uses: docker/build-push-action@v6
Expand All @@ -55,6 +74,7 @@ jobs:
outputs: type=docker,dest=/tmp/${{ env.IMAGE_NAME }}.tar
context: ${{ inputs.dockerContext }}
file: ${{ inputs.dockerfile }}
secrets: ${{ steps.set-build-secrets.outputs.SECRETS }}

- name: Upload Docker image to workspace
if: inputs.publish == true
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/reusable_go_lint_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ on:
description: 'Run build'
type: boolean
default: false
go-private-repos-authentication:
description: 'Enable authentication for private repositories'
type: boolean
default: false

jobs:
build:
Expand All @@ -59,6 +63,11 @@ jobs:
with:
go-version: ${{ inputs.go-version }}

- name: Configure Private Module Access
if: ${{ inputs.go-private-repos-authentication }}
run: |
git config --global url."https://${{ secrets.GO_PRIVATE_TOKEN }}@github.com/".insteadOf "https://github.com/"

- name: Print Go environment
run: go env

Expand Down Expand Up @@ -92,6 +101,11 @@ jobs:
with:
go-version: ${{ inputs.go-version }}

- name: Configure Private Module Access
if: ${{ inputs.go-private-repos-authentication }}
run: |
git config --global url."https://${{ secrets.GO_PRIVATE_TOKEN }}@github.com/".insteadOf "https://github.com/"

- name: Install Dependencies
if: ${{ inputs.install-dependencies-command != '' }}
run: ${{ inputs.install-dependencies-command }}
Expand All @@ -115,6 +129,11 @@ jobs:
with:
go-version: ${{ inputs.go-version }}

- name: Configure Private Module Access
if: ${{ inputs.go-private-repos-authentication }}
run: |
git config --global url."https://${{ secrets.GO_PRIVATE_TOKEN }}@github.com/".insteadOf "https://github.com/"

- name: Install Dependencies
if: ${{ inputs.install-dependencies-command != '' }}
run: ${{ inputs.install-dependencies-command }}
Expand Down Expand Up @@ -142,6 +161,11 @@ jobs:
with:
go-version: ${{ inputs.go-version }}

- name: Configure Private Module Access
if: ${{ inputs.go-private-repos-authentication }}
run: |
git config --global url."https://${{ secrets.GO_PRIVATE_TOKEN }}@github.com/".insteadOf "https://github.com/"

- name: Install Dependencies
if: ${{ inputs.install-dependencies-command != '' }}
run: ${{ inputs.install-dependencies-command }}
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 0.4.0

- reusable_go_lint_test: Add go-private-repos input, allowing access to private repositories

## 0.3.2

- reusable_go_lint_test: Allow build job to be optional
Expand Down