Skip to content

Commit 7cd9101

Browse files
authored
Update workflows to publish from the release tag (#233)
1 parent 63a710e commit 7cd9101

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

.github/workflows/build.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on:
55
push:
66
branches:
77
- "main"
8+
tags:
9+
- "v*"
810
pull_request:
911

1012
concurrency:
@@ -21,6 +23,8 @@ jobs:
2123
steps:
2224
- name: Check out repo
2325
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
26+
with:
27+
persist-credentials: false
2428

2529
- name: Set up .NET
2630
uses: actions/setup-dotnet@d4c94342e560b34958eacfc5d055d21461ed1c5d # v5.0.0
@@ -52,6 +56,8 @@ jobs:
5256
steps:
5357
- name: Check out repo
5458
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
59+
with:
60+
persist-credentials: false
5561

5662
- name: Login to GitHub Container Registry
5763
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
@@ -63,8 +69,11 @@ jobs:
6369
- name: Generate Docker image tag
6470
id: tag
6571
run: |
72+
# Tags use the tag name as the image tag (strip leading 'v')
73+
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
74+
IMAGE_TAG="${GITHUB_REF#refs/tags/v}"
6675
# Main branch always uses 'dev' tag
67-
if [[ "$GITHUB_REF" == "refs/heads/main" ]]; then
76+
elif [[ "$GITHUB_REF" == "refs/heads/main" ]]; then
6877
IMAGE_TAG=dev
6978
# PRs use 'pr-<number>' format for consistency
7079
elif [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then
@@ -131,7 +140,7 @@ jobs:
131140
output-format: sarif
132141

133142
- name: Upload Grype results to GitHub
134-
uses: github/codeql-action/upload-sarif@f779452ac5af1c261dce0346a8f964149f49322b # v3.26.13
143+
uses: github/codeql-action/upload-sarif@e296a935590eb16afc0c0108289f68c87e2a89a5 # v4.30.7
135144
with:
136145
sarif_file: ${{ steps.container-scan.outputs.sarif }}
137146
sha: ${{ contains(github.event_name, 'pull_request') && github.event.pull_request.head.sha || github.sha }}

.github/workflows/publish.yml

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ jobs:
2929
steps:
3030
- name: Version output
3131
id: version-output
32+
env:
33+
INPUT_VERSION: ${{ inputs.version }}
3234
run: |
33-
if [[ "${{ inputs.version }}" == "latest" || "${{ inputs.version }}" == "" ]]; then
35+
if [[ "$INPUT_VERSION" == "latest" || "$INPUT_VERSION" == "" ]]; then
3436
VERSION=$(curl -sSfL "https://api.github.com/repos/bitwarden/key-connector/releases" | jq -c '.[] | select(.tag_name) | .tag_name' | head -1 | grep -ohE '20[0-9]{2}\.([1-9]|1[0-2])\.[0-9]+')
3537
if [[ -z "$VERSION" ]]; then
3638
echo "Failed to fetch latest version"
@@ -39,8 +41,8 @@ jobs:
3941
echo "Latest Released Version: $VERSION"
4042
echo "version=$VERSION" >> $GITHUB_OUTPUT
4143
else
42-
echo "Release Version: ${{ inputs.version }}"
43-
echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT
44+
echo "Release Version: $INPUT_VERSION"
45+
echo "version=$INPUT_VERSION" >> $GITHUB_OUTPUT
4446
fi
4547
4648
publish-docker:
@@ -63,32 +65,19 @@ jobs:
6365
username: ${{ github.actor }}
6466
password: ${{ secrets.GITHUB_TOKEN }}
6567

66-
- name: Pull image
67-
run: docker pull ghcr.io/bitwarden/key-connector:dev
68+
- name: Pull versioned image
69+
run: docker pull ghcr.io/bitwarden/key-connector:$_RELEASE_VERSION
6870

69-
- name: Tag version and latest
70-
run: |
71-
if [[ "${{ inputs.publish_type }}" == "Dry Run" ]]; then
72-
docker tag ghcr.io/bitwarden/key-connector:dev ghcr.io/bitwarden/key-connector:dryrun
73-
else
74-
docker tag ghcr.io/bitwarden/key-connector:dev ghcr.io/bitwarden/key-connector:$_RELEASE_VERSION
75-
docker tag ghcr.io/bitwarden/key-connector:dev ghcr.io/bitwarden/key-connector:latest
76-
fi
71+
- name: Tag as latest
72+
run: docker tag ghcr.io/bitwarden/key-connector:$_RELEASE_VERSION ghcr.io/bitwarden/key-connector:latest
7773

78-
- name: Push release version and latest image
74+
- name: Push latest image
7975
if: ${{ inputs.publish_type != 'Dry Run' }}
80-
run: |
81-
docker push ghcr.io/bitwarden/key-connector:$_RELEASE_VERSION
82-
docker push ghcr.io/bitwarden/key-connector:latest
76+
run: docker push ghcr.io/bitwarden/key-connector:latest
8377

8478
- name: Verify the signed image with Cosign
8579
if: ${{ inputs.publish_type != 'Dry Run' }}
8680
run: |
87-
cosign verify \
88-
--certificate-identity-regexp="https://github\.com/bitwarden/key-connector/.*" \
89-
--certificate-oidc-issuer "https://token.actions.githubusercontent.com" \
90-
ghcr.io/bitwarden/key-connector:$_RELEASE_VERSION
91-
9281
cosign verify \
9382
--certificate-identity-regexp="https://github\.com/bitwarden/key-connector/.*" \
9483
--certificate-oidc-issuer "https://token.actions.githubusercontent.com" \

.github/workflows/release.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ jobs:
3434
3535
- name: Check out repo
3636
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
37+
with:
38+
persist-credentials: false
3739

3840
- name: Check release version
3941
id: version
@@ -46,7 +48,7 @@ jobs:
4648
- name: Get branch name
4749
id: branch
4850
run: |
49-
BRANCH_NAME=$(basename ${{ github.ref }})
51+
BRANCH_NAME=$(basename $GITHUB_REF)
5052
echo "branch-name=$BRANCH_NAME" >> $GITHUB_OUTPUT
5153
5254
release-github:

0 commit comments

Comments
 (0)