Skip to content

Commit 9497a7a

Browse files
authored
Merge pull request #9 from LBHackney-IT/feature/github_actions_secrets
Use GITHUB_TOKEN in GitHub Actions
2 parents 46ab689 + e713f3d commit 9497a7a

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

.github/workflows/publish.yml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ jobs:
1010
calculate-version:
1111
name: Calculate Version
1212
runs-on: ubuntu-latest
13-
env:
14-
LBHPACKAGESTOKEN: ${{secrets.LBHPACKAGESTOKEN }}
1513
outputs:
1614
version: ${{ steps.gitversion.outputs.nuGetVersionV2 }}
1715
steps:
@@ -36,8 +34,6 @@ jobs:
3634
name: Check code formatting
3735
runs-on: ubuntu-latest
3836
needs: calculate-version
39-
env:
40-
LBHPACKAGESTOKEN: ${{secrets.LBHPACKAGESTOKEN }}
4137
steps:
4238
- name: Checkout
4339
uses: actions/checkout@v2
@@ -51,16 +47,16 @@ jobs:
5147
runs-on: ubuntu-latest
5248
needs: calculate-version
5349
env:
54-
LBHPACKAGESTOKEN: ${{secrets.LBHPACKAGESTOKEN }}
50+
LBHPACKAGESTOKEN: ${{secrets.GITHUB_TOKEN }}
5551
outputs:
5652
version: ${{ needs.calculate-version.outputs.version }}
5753
steps:
5854
- name: Checkout
5955
uses: actions/checkout@v2
6056
- name: Build
61-
run: docker-compose build hackney-shared-processes-test
57+
run: docker compose build hackney-shared-processes-test
6258
- name: Run tests
63-
run: docker-compose run hackney-shared-processes-test
59+
run: docker compose run hackney-shared-processes-test
6460

6561
publish-package:
6662
name: Publish Package
@@ -70,8 +66,7 @@ jobs:
7066
- check-code-formatting
7167
env:
7268
VERSION: ${{ needs.build-and-test.outputs.version }}
73-
LBHPACKAGESTOKEN: ${{secrets.LBHPACKAGESTOKEN }}
74-
NUGET_DEPLOY_KEY: ${{secrets.NUGET_DEPLOY_KEY }}
69+
LBHPACKAGESTOKEN: ${{ secrets.GITHUB_TOKEN }}
7570
steps:
7671
- name: Checkout
7772
uses: actions/checkout@v2
@@ -80,4 +75,4 @@ jobs:
8075
- name: Publish the Package
8176
run: |
8277
cd Hackney.Shared.Processes/bin/Release
83-
dotnet nuget push Hackney.Shared.Processes.*.nupkg -s https://nuget.pkg.github.com/LBHackney-IT/index.json --api-key ${{secrets.NUGET_DEPLOY_KEY }}
78+
dotnet nuget push Hackney.Shared.Processes.*.nupkg -s https://nuget.pkg.github.com/LBHackney-IT/index.json --api-key ${{ secrets.GITHUB_TOKEN }}

Hackney.Shared.Processes.Tests/Dockerfile

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ FROM mcr.microsoft.com/dotnet/core/sdk:3.1
33
# disable microsoft telematry
44
ENV DOTNET_CLI_TELEMETRY_OPTOUT='true'
55

6-
ARG LBHPACKAGESTOKEN
7-
ENV LBHPACKAGESTOKEN=$LBHPACKAGESTOKEN
86
WORKDIR /app
97

108
# Copy csproj and restore as distinct layers
@@ -13,8 +11,16 @@ COPY ./Hackney.Shared.Processes/Hackney.Shared.Processes.csproj ./Hackney.Shared
1311
COPY ./Hackney.Shared.Processes.Tests/Hackney.Shared.Processes.Tests.csproj ./Hackney.Shared.Processes.Tests/
1412
COPY /nuget.config /root/.nuget/NuGet/NuGet.Config
1513

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

1925
# Copy everything else and build
2026
COPY . .

docker-compose.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,12 @@ services:
66
build:
77
context: .
88
dockerfile: Hackney.Shared.Processes.Tests/Dockerfile
9-
args:
10-
- LBHPACKAGESTOKEN=${LBHPACKAGESTOKEN}
9+
secrets:
10+
- LBHPACKAGESTOKEN
11+
12+
# see https://docs.docker.com/compose/how-tos/use-secrets/#build-secrets
13+
# Combines with a "secrets" block in each service to expose it as a file in
14+
# /run/secrets/, e.g. /run/secrets/LBHPACKAGESTOKEN
15+
secrets:
16+
LBHPACKAGESTOKEN:
17+
environment: LBHPACKAGESTOKEN

0 commit comments

Comments
 (0)