Skip to content

Commit 4d14d46

Browse files
committed
adding files referenced by the example workflows
1 parent 1c4c5b0 commit 4d14d46

File tree

4 files changed

+290
-0
lines changed

4 files changed

+290
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: _build
2+
run-name: Build ${{ inputs.project-name }}
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
project-name:
8+
type: string
9+
required: true
10+
project-path:
11+
type: string
12+
required: true
13+
version:
14+
type: string
15+
required: true
16+
17+
jobs:
18+
build:
19+
name: Build
20+
runs-on: ubuntu-22.04
21+
steps:
22+
- name: Check out repository
23+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
24+
with:
25+
fetch-depth: 0
26+
27+
- name: Set up .NET
28+
uses: actions/setup-dotnet@3e891b0cb619bf60e2c25674b222b8940e2c1c25 # v4.1.0
29+
30+
- name: Cache NuGet packages
31+
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
32+
with:
33+
path: ~/.nuget/packages
34+
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
35+
restore-keys: |
36+
${{ runner.os }}-nuget-
37+
38+
- name: Install dependencies
39+
run: dotnet restore ${{ inputs.project-path }}/${{ inputs.project-name }}.csproj
40+
41+
- name: Build
42+
run: dotnet build --verbosity minimal ${{ inputs.project-path }}/${{ inputs.project-name }}.csproj
43+
44+
- name: Publish
45+
run: |
46+
echo "Publish"
47+
dotnet publish ${{ inputs.project-path }}/${{ inputs.project-name }}.csproj \
48+
-c Release --no-restore \
49+
-o ./tmp/publish-${{ inputs.project-name }} -p:Version=${{ inputs.version }}
50+
51+
- name: Create artifact
52+
run: |
53+
cd ./tmp/publish-${{ inputs.project-name }}
54+
zip -r ${{ inputs.project-name }}.zip .
55+
mv ${{ inputs.project-name }}.zip ../../
56+
pwd
57+
ls -atlh ../../
58+
59+
- name: Upload artifact
60+
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
61+
with:
62+
name: ${{ inputs.project-name }}.zip
63+
path: ./${{ inputs.project-name }}.zip
64+
if-no-files-found: error
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: _docker
2+
run-name: "Build ${{ inputs.project-name }} docker image and push ${{ inputs.push-docker-image }} to ACR"
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
project-name:
8+
type: string
9+
required: true
10+
project-path:
11+
type: string
12+
required: true
13+
version:
14+
type: string
15+
required: false
16+
push-docker-image:
17+
type: boolean
18+
required: false
19+
default: false
20+
image-name:
21+
type: string
22+
required: true
23+
24+
jobs:
25+
docker:
26+
name: Docker
27+
runs-on: ubuntu-22.04
28+
steps:
29+
- name: Check out repository
30+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
31+
with:
32+
fetch-depth: 0
33+
34+
- name: Log in to Azure
35+
if: ${{ inputs.push-docker-image }}
36+
uses: Azure/login@a65d910e8af852a8061c627c456678983e180302 # v1.6.1
37+
with:
38+
creds: ${{ secrets.AZURE_PROD_KV_CREDENTIALS }}
39+
40+
- name: Log in to ACR
41+
if: ${{ inputs.push-docker-image }}
42+
run: az acr login -n bitwardenprod
43+
44+
- name: Generate Docker image tag
45+
id: tag
46+
env:
47+
VERSION: ${{ inputs.version }}
48+
run: |
49+
IMAGE_TAG=$VERSION
50+
# IMAGE_TAG=$(echo "${GITHUB_REF#refs/heads/}" | sed "s#/#-#g") # slash safe branch name
51+
# if [[ "$IMAGE_TAG" == "main" ]]; then
52+
# IMAGE_TAG=$VERSION
53+
# fi
54+
echo "image_tag=$IMAGE_TAG" >> $GITHUB_OUTPUT
55+
56+
- name: Generate tag list
57+
id: tag-list
58+
env:
59+
IMAGE_TAG: ${{ steps.tag.outputs.image_tag }}
60+
IMAGE_NAME: ${{ inputs.image-name }}
61+
run: echo "tags=bitwardenprod.azurecr.io/${IMAGE_NAME}:${IMAGE_TAG}" >> $GITHUB_OUTPUT
62+
63+
- name: Get build artifact
64+
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
65+
with:
66+
name: ${{ inputs.project-name }}.zip
67+
68+
- name: Set up build artifact
69+
run: |
70+
mkdir -p ${{ inputs.project-path }}/obj/build-output/publish
71+
unzip ${{ inputs.project-name }}.zip \
72+
-d ${{ inputs.project-path }}/obj/build-output/publish
73+
74+
- name: Build Docker image
75+
uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355 # v6.10.0
76+
with:
77+
context: ${{ inputs.project-path }}
78+
file: ${{ inputs.project-path }}/Dockerfile
79+
platforms: linux/amd64
80+
push: ${{ inputs.push-docker-image }}
81+
tags: ${{ steps.tag-list.outputs.tags }}
82+
env:
83+
DOCKER_BUILD_RECORD_UPLOAD: false
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: _test
2+
run-name: Test ${{ inputs.project-name }}
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
project-name:
8+
type: string
9+
required: true
10+
project-path:
11+
type: string
12+
required: true
13+
14+
jobs:
15+
check-test-secrets:
16+
name: Check for test secrets
17+
runs-on: ubuntu-22.04
18+
outputs:
19+
available: ${{ steps.check-test-secrets.outputs.available }}
20+
permissions:
21+
contents: read
22+
23+
steps:
24+
- name: Check
25+
id: check-test-secrets
26+
run: |
27+
if [ "${{ secrets.CODECOV_TOKEN }}" != '' ]; then
28+
echo "available=true" >> $GITHUB_OUTPUT;
29+
else
30+
echo "available=false" >> $GITHUB_OUTPUT;
31+
fi
32+
33+
testing:
34+
name: Test
35+
runs-on: ubuntu-22.04
36+
needs: check-test-secrets
37+
permissions:
38+
checks: write
39+
contents: read
40+
pull-requests: write
41+
42+
steps:
43+
- name: Check out repo
44+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
45+
with:
46+
fetch-depth: 0
47+
48+
- name: Set up .NET
49+
uses: actions/setup-dotnet@3e891b0cb619bf60e2c25674b222b8940e2c1c25 # v4.1.0
50+
51+
- name: Cache NuGet packages
52+
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
53+
with:
54+
path: ~/.nuget/packages
55+
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
56+
restore-keys: |
57+
${{ runner.os }}-nuget-
58+
59+
- name: Install dependencies
60+
run: dotnet restore --locked-mode ${{ inputs.project-path }}/${{ inputs.project-name }}.csproj
61+
62+
- name: Build
63+
run: dotnet build --verbosity minimal ${{ inputs.project-path }}/${{ inputs.project-name }}.csproj
64+
65+
- name: Test
66+
run: dotnet test ${{ inputs.project-path }}/${{ inputs.project-name }}.csproj --no-build --logger "trx;LogFileName=mothership-test-results.trx"
67+
68+
- name: Report test results
69+
uses: dorny/test-reporter@31a54ee7ebcacc03a09ea97a7e5465a47b84aea5 # v1.9.1
70+
if: ${{ needs.check-test-secrets.outputs.available == 'true' && !cancelled() }}
71+
with:
72+
name: Test Results
73+
path: "**/*-test-results.trx"
74+
reporter: dotnet-trx
75+
fail-on-error: true
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: _version
2+
run-name: Calculate version
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
is-release:
8+
type: boolean
9+
default: false
10+
outputs:
11+
version:
12+
description: "version to be built"
13+
value: ${{ jobs.version.outputs.version }}
14+
15+
jobs:
16+
version:
17+
name: Calculate version
18+
runs-on: ubuntu-22.04
19+
outputs:
20+
version: ${{ steps.version.outputs.value }}
21+
steps:
22+
- name: Check out repository
23+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
24+
with:
25+
fetch-depth: 0
26+
27+
- name: Generate version
28+
id: version
29+
run: |
30+
ls -la
31+
git fetch --prune --tags
32+
33+
echo "Calculating next version..."
34+
35+
base_version=$(cat Directory.build.props |
36+
grep -o "<BaseVersion>.*</BaseVersion>" |
37+
grep -Eo "[0-9]+\.[0-9]+"
38+
)
39+
major_version=$(echo $base_version | grep -Eo "[0-9]+" | head -1)
40+
minor_version=$(echo $base_version | grep -Eo "[0-9]+" | sed -n 2p)
41+
42+
latest_tag_version=$(git tag --sort=committerdate --list | tail -1)
43+
echo " latest_tag_version: $latest_tag_version"
44+
45+
major_latest_tag_version=$(echo $latest_tag_version | grep -Eo "[0-9]+" | head -1)
46+
echo " major_latest_tag_version: $major_latest_tag_version"
47+
48+
minor_latest_tag_version=$(echo $latest_tag_version | grep -Eo "[0-9]+" | sed -n 2p)
49+
echo " minor_latest_tag_version: $minor_latest_tag_version"
50+
51+
if [[ "$major_latest_tag_version" != "$major_version" ]] || \
52+
[[ "$minor_latest_tag_version" != "$minor_version" ]]; then
53+
patch_version="0"
54+
else
55+
patch_version=$((${latest_tag_version##*.} + 1))
56+
fi
57+
58+
echo " patch_version: $patch_version"
59+
60+
version_suffix=$patch_version
61+
62+
if [[ "${{ inputs.is-release }}" == "false" ]]; then
63+
version_suffix=$version_suffix-${GITHUB_SHA:0:7}
64+
fi
65+
66+
echo " version: $base_version.$version_suffix"
67+
echo "value=$base_version.$version_suffix" >> $GITHUB_OUTPUT
68+
echo "Done"

0 commit comments

Comments
 (0)