Skip to content

Commit

Permalink
Merge pull request #46 from LBHackney-IT/feature/github_actions_secrets
Browse files Browse the repository at this point in the history
Use GITHUB_TOKEN in GitHub Actions
  • Loading branch information
spikeheap authored Oct 9, 2024
2 parents 6c0ca1c + 1e1fa44 commit 3a216cd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
14 changes: 5 additions & 9 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ jobs:
calculate-version:
name: Calculate Version
runs-on: ubuntu-latest
env:
LBHPACKAGESTOKEN: ${{ secrets.LBHPACKAGESTOKEN }}
outputs:
version: ${{ steps.gitversion.outputs.nuGetVersionV2 }}
steps:
Expand All @@ -35,8 +33,6 @@ jobs:
name: Check code formatting
runs-on: ubuntu-latest
needs: calculate-version
env:
LBHPACKAGESTOKEN: ${{ secrets.LBHPACKAGESTOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -50,23 +46,23 @@ jobs:
runs-on: ubuntu-latest
needs: calculate-version
env:
LBHPACKAGESTOKEN: ${{ secrets.LBHPACKAGESTOKEN }}
LBHPACKAGESTOKEN: ${{ secrets.GITHUB_TOKEN }}
outputs:
version: ${{ needs.calculate-version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Build
run: docker-compose build hackney-shared-asset-test
run: docker compose build hackney-shared-asset-test
- name: Run tests
run: docker-compose run hackney-shared-asset-test
run: docker compose run hackney-shared-asset-test

publish-package:
name: Publish Package
runs-on: ubuntu-latest
needs: build-and-test
env:
LBHPACKAGESTOKEN: ${{ secrets.LBHPACKAGESTOKEN }}
LBHPACKAGESTOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ needs.build-and-test.outputs.version }}
steps:
- name: Checkout
Expand All @@ -76,4 +72,4 @@ jobs:
- name: Publish the Package
run: |
cd Hackney.Shared.Asset/bin/Release
dotnet nuget push Hackney.Shared.Asset.*.nupkg -s https://nuget.pkg.github.com/LBHackney-IT/index.json --api-key ${{ secrets.NUGET_KEY }}
dotnet nuget push Hackney.Shared.Asset.*.nupkg -s https://nuget.pkg.github.com/LBHackney-IT/index.json --api-key ${{ secrets.GITHUB_TOKEN }}
14 changes: 10 additions & 4 deletions Hackney.Shared.Asset.Tests/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ FROM mcr.microsoft.com/dotnet/core/sdk:3.1
# disable microsoft telematry
ENV DOTNET_CLI_TELEMETRY_OPTOUT='true'

ARG LBHPACKAGESTOKEN
ENV LBHPACKAGESTOKEN=$LBHPACKAGESTOKEN
WORKDIR /app

# Copy csproj and restore as distinct layers
Expand All @@ -13,8 +11,16 @@ COPY ./Hackney.Shared.Asset/Hackney.Shared.Asset.csproj ./Hackney.Shared.Asset/
COPY ./Hackney.Shared.Asset.Tests/Hackney.Shared.Asset.Tests.csproj ./Hackney.Shared.Asset.Tests/
COPY /nuget.config /root/.nuget/NuGet/NuGet.Config

RUN dotnet restore ./Hackney.Shared.Asset/Hackney.Shared.Asset.csproj
RUN dotnet restore ./Hackney.Shared.Asset.Tests/Hackney.Shared.Asset.Tests.csproj
# We mount secrets so they can't end up in logs or build layers.
# We chain both restore commands so we only make the token available
# once and don't store it elsewhere.
# see:
# - https://docs.docker.com/reference/dockerfile/#arg
# - https://docs.docker.com/compose/how-tos/use-secrets/
RUN --mount=type=secret,id=LBHPACKAGESTOKEN \
export LBHPACKAGESTOKEN=$(cat /run/secrets/LBHPACKAGESTOKEN) && \
dotnet restore ./Hackney.Shared.Asset/Hackney.Shared.Asset.csproj && \
dotnet restore ./Hackney.Shared.Asset.Tests/Hackney.Shared.Asset.Tests.csproj

# Copy everything else and build
COPY . .
Expand Down
11 changes: 9 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,12 @@ services:
build:
context: .
dockerfile: Hackney.Shared.Asset.Tests/Dockerfile
args:
- LBHPACKAGESTOKEN=${LBHPACKAGESTOKEN}
secrets:
- LBHPACKAGESTOKEN

# see https://docs.docker.com/compose/how-tos/use-secrets/#build-secrets
# Combines with a "secrets" block in each service to expose it as a file in
# /run/secrets/, e.g. /run/secrets/LBHPACKAGESTOKEN
secrets:
LBHPACKAGESTOKEN:
environment: LBHPACKAGESTOKEN

0 comments on commit 3a216cd

Please sign in to comment.