Skip to content

Commit 9cc8f9c

Browse files
committed
Update build and release workflows (#91)
(cherry picked from commit b57e7c2)
1 parent 4f046db commit 9cc8f9c

File tree

2 files changed

+87
-93
lines changed

2 files changed

+87
-93
lines changed

.github/workflows/build.yml

Lines changed: 39 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ name: Build
44
on:
55
push:
66
paths-ignore:
7-
- '.github/workflows/**'
7+
- ".github/workflows/**"
88
workflow_dispatch:
99

1010
jobs:
@@ -16,13 +16,10 @@ jobs:
1616
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
1717

1818
- name: Install cloc
19-
run: sudo apt update && sudo apt install cloc -y
19+
run: sudo apt update && sudo apt install -y cloc
2020

2121
- name: Print lines of code
22-
run: |
23-
cloc --include-lang \
24-
C#,SQL,Razor,"Bourne Shell",PowerShell,HTML,CSS,Sass,JavaScript,TypeScript \
25-
--vcs git
22+
run: cloc --include-lang C#,SQL,Razor,"Bourne Shell",PowerShell,HTML,CSS,Sass,JavaScript,TypeScript --vcs git
2623

2724

2825
build-artifacts:
@@ -40,15 +37,15 @@ jobs:
4037
echo "GitHub event: $GITHUB_EVENT"
4138
4239
- name: Restore/Clean service
43-
working-directory: ./src/KeyConnector
40+
working-directory: src/KeyConnector
4441
run: |
4542
echo "Restore"
4643
dotnet restore
4744
echo "Clean"
4845
dotnet clean -c "Release" -o obj/build-output/publish
4946
5047
- name: Publish service
51-
working-directory: ./src/KeyConnector
48+
working-directory: src/KeyConnector
5249
run: |
5350
echo "Publish"
5451
dotnet publish -c "Release" -o obj/build-output/publish
@@ -62,7 +59,7 @@ jobs:
6259
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
6360
with:
6461
name: KeyConnector.zip
65-
path: ./src/KeyConnector/KeyConnector.zip
62+
path: src/KeyConnector/KeyConnector.zip
6663
if-no-files-found: error
6764

6865

@@ -71,18 +68,34 @@ jobs:
7168
runs-on: ubuntu-22.04
7269
needs: build-artifacts
7370
env:
74-
_SERVICE_NAME: key-connector
71+
_AZ_REGISTRY: bitwardenprod.azurecr.io
72+
_PROJECT_NAME: key-connector
7573
steps:
7674
- name: Checkout repo
7775
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
7876

79-
- name: Setup DCT
80-
id: setup-dct
81-
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/rc' || github.ref == 'refs/heads/hotfix-rc'
82-
uses: bitwarden/gh-actions/setup-docker-trust@main
77+
- name: Login to Azure - PROD Subscription
78+
uses: Azure/login@92a5484dfaf04ca78a94597f4f19fea633851fa2 # v1.4.7
8379
with:
84-
azure-creds: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }}
85-
azure-keyvault-name: "bitwarden-ci"
80+
creds: ${{ secrets.AZURE_PROD_KV_CREDENTIALS }}
81+
82+
- name: Login to PROD ACR
83+
run: az acr login -n ${_AZ_REGISTRY%.azurecr.io}
84+
85+
- name: Generate Docker image tag
86+
id: tag
87+
run: |
88+
IMAGE_TAG=$(echo "${GITHUB_REF:11}" | sed "s#/#-#g") # slash safe branch name
89+
if [[ "$IMAGE_TAG" == "master" ]]; then
90+
IMAGE_TAG=dev
91+
fi
92+
echo "image_tag=$IMAGE_TAG" >> $GITHUB_OUTPUT
93+
94+
- name: Generate image full name
95+
id: image-name
96+
env:
97+
IMAGE_TAG: ${{ steps.tag.outputs.image_tag }}
98+
run: echo "name=${_AZ_REGISTRY}/${_PROJECT_NAME}:${IMAGE_TAG}" >> $GITHUB_OUTPUT
8699

87100
- name: Get build artifact
88101
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
@@ -91,47 +104,14 @@ jobs:
91104

92105
- name: Setup build artifact
93106
run: |
94-
mkdir -p ./src/KeyConnector/obj/build-output/publish
95-
unzip KeyConnector.zip \
96-
-d ./src/KeyConnector/obj/build-output/publish
97-
98-
- name: Build Docker images
99-
run: |
100-
docker build -t ${{ env._SERVICE_NAME }} \
101-
./src/KeyConnector
102-
103-
- name: Tag and Push RC to Docker Hub
104-
if: (github.ref == 'refs/heads/rc')
105-
env:
106-
DOCKER_CONTENT_TRUST: 1
107-
DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE: ${{ steps.setup-dct.outputs.dct-delegate-repo-passphrase }}
108-
run: |
109-
docker tag ${{ env._SERVICE_NAME }} \
110-
bitwarden/${{ env._SERVICE_NAME }}:rc
111-
docker push bitwarden/${{ env._SERVICE_NAME }}:rc
107+
mkdir -p src/KeyConnector/obj/build-output/publish
108+
unzip KeyConnector.zip -d src/KeyConnector/obj/build-output/publish
112109
113-
- name: Tag and Push Hotfix to Docker Hub
114-
if: (github.ref == 'refs/heads/hotfix-rc')
115-
env:
116-
DOCKER_CONTENT_TRUST: 1
117-
DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE: ${{ steps.setup-dct.outputs.dct-delegate-repo-passphrase }}
118-
run: |
119-
docker tag ${{ env._SERVICE_NAME }} \
120-
bitwarden/${{ env._SERVICE_NAME }}:hotfix
121-
docker push bitwarden/${{ env._SERVICE_NAME }}:hotfix
122-
123-
- name: Tag and Push Dev to Docker Hub
124-
if: (github.ref == 'refs/heads/master')
125-
env:
126-
DOCKER_CONTENT_TRUST: 1
127-
DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE: ${{ steps.setup-dct.outputs.dct-delegate-repo-passphrase }}
128-
run: |
129-
docker tag ${{ env._SERVICE_NAME }} \
130-
bitwarden/${{ env._SERVICE_NAME }}:dev
131-
docker push bitwarden/${{ env._SERVICE_NAME }}:dev
132-
133-
- name: Log out of Docker and disable Docker Notary
134-
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/rc' || github.ref == 'refs/heads/hotfix-rc'
135-
run: |
136-
docker logout
137-
echo "DOCKER_CONTENT_TRUST=0" >> $GITHUB_ENV
110+
- name: Build Docker image
111+
uses: docker/build-push-action@1104d471370f9806843c095c1db02b5a90c5f8b6 # v3.3.1
112+
with:
113+
context: src/KeyConnector
114+
file: src/KeyConnector/Dockerfile
115+
platforms: linux/amd64
116+
push: true
117+
tags: ${{ steps.image-name.outputs.name }}

.github/workflows/release.yml

Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
22
name: Release
3+
run-name: Release - ${{ github.event.inputs.release_type }}
34

45
on:
56
workflow_dispatch:
67
inputs:
78
release_type:
89
description: 'Release Options'
9-
required: true
1010
default: 'Initial Release'
1111
type: choice
1212
options:
@@ -31,6 +31,7 @@ jobs:
3131
echo "==================================="
3232
exit 1
3333
fi
34+
3435
- name: Checkout repo
3536
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
3637

@@ -48,12 +49,31 @@ jobs:
4849
BRANCH_NAME=$(basename ${{ github.ref }})
4950
echo "::set-output name=branch-name::$BRANCH_NAME"
5051
52+
release-github:
53+
name: Create GitHub Release
54+
if: ${{ github.event.inputs.release_type != 'Dry Run' }}
55+
runs-on: ubuntu-22.04
56+
needs: setup
57+
steps:
58+
- name: Create release
59+
uses: ncipollo/release-action@6c75be85e571768fa31b40abf38de58ba0397db5 # v1.13.0
60+
with:
61+
commit: ${{ github.sha }}
62+
tag: "v${{ needs.setup.outputs.release_version }}"
63+
name: "Version ${{ needs.setup.outputs.release_version }}"
64+
body: "<insert release notes here>"
65+
token: ${{ secrets.GITHUB_TOKEN }}
66+
draft: true
67+
5168
release-docker:
5269
name: Build Docker images
5370
runs-on: ubuntu-22.04
54-
needs: setup
71+
needs:
72+
- setup
73+
- release-github
5574
env:
56-
_SERVICE_NAME: key-connector
75+
_AZ_REGISTRY: bitwardenprod.azurecr.io
76+
_PROJECT_NAME: key-connector
5777
_RELEASE_VERSION: ${{ needs.setup.outputs.release_version }}
5878
_BRANCH_NAME: ${{ needs.setup.outputs.branch-name }}
5979
_RELEASE_OPTION: ${{ github.event.inputs.release_type }}
@@ -66,66 +86,60 @@ jobs:
6686
echo "GitHub event: $GITHUB_EVENT"
6787
echo "Github Release Option: $_RELEASE_OPTION"
6888
89+
- name: Login to Azure - Prod Subscription
90+
uses: Azure/login@92a5484dfaf04ca78a94597f4f19fea633851fa2 # v1.4.7
91+
with:
92+
creds: ${{ secrets.AZURE_PROD_KV_CREDENTIALS }}
93+
94+
- name: Login to Azure ACR
95+
run: az acr login -n ${_AZ_REGISTRY%.azurecr.io}
96+
6997
- name: Setup DCT
7098
id: setup-dct
7199
uses: bitwarden/gh-actions/setup-docker-trust@main
72100
with:
73101
azure-creds: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }}
74102
azure-keyvault-name: "bitwarden-ci"
75103

76-
- name: Checkout repo
77-
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
78-
79-
- name: Pull latest selfhost image
104+
- name: Pull image
80105
run: |
81106
if [[ "${{ github.event.inputs.release_type }}" == "Dry Run" ]]; then
82-
docker pull bitwarden/$_SERVICE_NAME:latest
107+
docker pull $_AZ_REGISTRY/$_PROJECT_NAME:dev
83108
else
84-
docker pull bitwarden/$_SERVICE_NAME:$_BRANCH_NAME
109+
docker pull $_AZ_REGISTRY/$_PROJECT_NAME:$_BRANCH_NAME
85110
fi
86111
87112
- name: Tag version and latest
88113
run: |
89114
if [[ "${{ github.event.inputs.release_type }}" == "Dry Run" ]]; then
90-
docker tag bitwarden/$_SERVICE_NAME:latest bitwarden/$_SERVICE_NAME:dryrun
115+
docker tag $_AZ_REGISTRY/$_PROJECT_NAME:dev bitwarden/$_PROJECT_NAME:dryrun
91116
else
92-
docker tag bitwarden/$_SERVICE_NAME:$_BRANCH_NAME bitwarden/$_SERVICE_NAME:$_RELEASE_VERSION
93-
docker tag bitwarden/$_SERVICE_NAME:$_BRANCH_NAME bitwarden/$_SERVICE_NAME:latest
117+
docker tag $_AZ_REGISTRY/$_PROJECT_NAME:$_BRANCH_NAME $_AZ_REGISTRY/$_PROJECT_NAME:$_RELEASE_VERSION
118+
docker tag $_AZ_REGISTRY/$_PROJECT_NAME:$_BRANCH_NAME $_AZ_REGISTRY/$_PROJECT_NAME:latest
119+
120+
docker tag $_AZ_REGISTRY/$_PROJECT_NAME:$_BRANCH_NAME bitwarden/$_PROJECT_NAME:$_RELEASE_VERSION
121+
docker tag $_AZ_REGISTRY/$_PROJECT_NAME:$_BRANCH_NAME bitwarden/$_PROJECT_NAME:latest
94122
fi
95123
96-
- name: List Docker images
97-
run: docker images
124+
- name: Push release version and latest image to ACR
125+
if: ${{ github.event.inputs.release_type != 'Dry Run' }}
126+
run: |
127+
docker push $_AZ_REGISTRY/$_PROJECT_NAME:$_RELEASE_VERSION
128+
docker push $_AZ_REGISTRY/$_PROJECT_NAME:latest
98129
99-
- name: Push version and latest image
130+
- name: Push release version and latest image to Docker Hub
100131
if: ${{ github.event.inputs.release_type != 'Dry Run' }}
101132
env:
102133
DOCKER_CONTENT_TRUST: 1
103134
DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE: ${{ steps.setup-dct.outputs.dct-delegate-repo-passphrase }}
104135
run: |
105-
docker push bitwarden/$_SERVICE_NAME:$_RELEASE_VERSION
106-
docker push bitwarden/$_SERVICE_NAME:latest
136+
docker push bitwarden/$_PROJECT_NAME:$_RELEASE_VERSION
137+
docker push bitwarden/$_PROJECT_NAME:latest
107138
108139
- name: Log out of Docker
109140
run: docker logout
110141

111142

112-
release-github:
113-
name: Create GitHub Release
114-
if: ${{ github.event.inputs.release_type != 'Dry Run' }}
115-
runs-on: ubuntu-22.04
116-
needs: setup
117-
steps:
118-
- name: Create release
119-
uses: ncipollo/release-action@6c75be85e571768fa31b40abf38de58ba0397db5 # v1.13.0
120-
with:
121-
commit: ${{ github.sha }}
122-
tag: "v${{ needs.setup.outputs.release_version }}"
123-
name: "Version ${{ needs.setup.outputs.release_version }}"
124-
body: "<insert release notes here>"
125-
token: ${{ secrets.GITHUB_TOKEN }}
126-
draft: true
127-
128-
129143
check-failures:
130144
name: Check for failures
131145
if: always()

0 commit comments

Comments
 (0)