-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DEVOPS-1750] Build and release pipeline for go SDK (#632)
## Type of change <!-- (mark with an `X`) --> ``` - [ ] Bug fix - [ ] New feature development - [ ] Tech debt (refactoring, code cleanup, dependency upgrades, etc) - [x] Build/deploy pipeline (DevOps) - [ ] Other ``` ## Objective <!--Describe what the purpose of this PR is. For example: what bug you're fixing or what new feature you're adding--> ## Code changes <!--Explain the changes you've made to each file or major component. This should help the reviewer understand your changes--> <!--Also refer to any related changes or PRs in other repositories--> - **languages/go/.version:** Add file to hold current go SDK version - **.github/workflows/version-bump.yml** Add go SDK to version bump workflow - **.github/workflows/golang-release.yml** replace it with `.github/workflows/release-go.yaml` workflow. - **.github/workflows/build-go.yaml** Add build go as a separate workflow - **.github/workflows/release-go.yml** Update release go pipeline to our standards. Sync go SDK folder to external repo. Create release tag. ## Before you submit - Please add **unit tests** where it makes sense to do so
- Loading branch information
1 parent
932945d
commit c0fe4ac
Showing
5 changed files
with
207 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
name: Build Go SDK | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- rc | ||
- hotfix-rc | ||
|
||
pull_request: | ||
|
||
env: | ||
GO111MODULE: on | ||
GO_VERSION: "^1.18" | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | ||
|
||
- name: Setup Go environment | ||
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 | ||
with: | ||
go-version: ${{ env.GO_VERSION }} | ||
|
||
- name: Cache dependencies | ||
uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4.0.0 | ||
with: | ||
path: ~/go/pkg/mod | ||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go- | ||
- name: npm ci | ||
run: npm ci | ||
|
||
- name: Generate schemas | ||
run: npm run schemas | ||
|
||
- name: Build | ||
working-directory: languages/go | ||
run: go build -v ./... | ||
|
||
- name: Test | ||
working-directory: languages/go | ||
run: go test -v ./... |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
name: Release Go | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
release_type: | ||
description: "Release Options" | ||
required: true | ||
default: "Release" | ||
type: choice | ||
options: | ||
- Release | ||
- Dry Run | ||
|
||
env: | ||
GO111MODULE: on | ||
GO_VERSION: "^1.18" | ||
|
||
jobs: | ||
validate: | ||
name: Setup | ||
runs-on: ubuntu-22.04 | ||
outputs: | ||
version: ${{ steps.version.outputs.version }} | ||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | ||
|
||
- name: Branch check | ||
if: ${{ github.event.inputs.release_type != 'Dry Run' }} | ||
run: | | ||
if [[ "$GITHUB_REF" != "refs/heads/rc" ]] && [[ "$GITHUB_REF" != "refs/heads/hotfix-rc" ]]; then | ||
echo "===================================" | ||
echo "[!] Can only release from the 'rc' or 'hotfix-rc' branches" | ||
echo "===================================" | ||
exit 1 | ||
fi | ||
- name: Get version | ||
id: version | ||
run: | | ||
VERSION=$(cat languages/go/.version | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+") | ||
echo "version=$VERSION" >> $GITHUB_OUTPUT | ||
repo-sync: | ||
name: Push changed files to SDK Go repo | ||
runs-on: ubuntu-22.04 | ||
needs: validate | ||
env: | ||
_KEY_VAULT: "bitwarden-ci" | ||
_BOT_EMAIL: [email protected] | ||
_BOT_NAME: bitwarden-devops-bot | ||
_PKG_VERSION: ${{ needs.validate.outputs.version }} | ||
steps: | ||
- name: Checkout SDK repo | ||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0 | ||
with: | ||
path: sdk | ||
|
||
- name: Checkout SDK-Go repo | ||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0 | ||
with: | ||
repository: bitwarden/sm-sdk-go | ||
path: sm-sdk-go | ||
ref: main | ||
|
||
- name: Login to Azure - Prod Subscription | ||
uses: Azure/login@92a5484dfaf04ca78a94597f4f19fea633851fa2 # v1.4.7 | ||
with: | ||
creds: ${{ secrets.AZURE_CI_SERVICE_PRINCIPAL }} | ||
|
||
- name: Retrieve secrets | ||
id: retrieve-secrets | ||
uses: bitwarden/gh-actions/get-keyvault-secrets@62d1bf7c3e31c458cc7236b1e69a475d235cd78f | ||
with: | ||
keyvault: ${{ env._KEY_VAULT }} | ||
secrets: "github-pat-bitwarden-devops-bot-repo-scope" | ||
|
||
- name: Setup Git | ||
working-directory: sm-sdk-go | ||
run: | | ||
git config --local user.email "${{ env._BOT_EMAIL }}" | ||
git config --local user.name "${{ env._BOT_NAME }}" | ||
- name: Update files | ||
run: | | ||
# Copy files to local sm-sdk-go repo path | ||
cp --verbose -rf sdk/languages/go sm-sdk-go | ||
- name: Push changes | ||
working-directory: sm-sdk-go | ||
run: | | ||
git add . | ||
git commit -m "Update Go SDK to ${{ github.sha }}" | ||
if [[ "${{ github.event.inputs.release_type }}" == "Dry Run" ]]; then | ||
echo "===================================" | ||
echo "[!] Dry Run - Skipping push" | ||
echo "===================================" | ||
git ls-files -m | ||
exit 0 | ||
else | ||
git push origin main | ||
fi | ||
- name: Create release tag on SDK Go repo | ||
if: ${{ github.event.inputs.release_type != 'Dry Run' }} | ||
working-directory: sm-sdk-go | ||
run: | | ||
# Check if tag exists, set output then exit 0 if true. | ||
if git log v${{ env._PKG_VERSION }} >/dev/null 2>&1; then | ||
echo "===================================" | ||
echo "[!] Tag v${{ env._PKG_VERSION }} already exists" | ||
echo "===================================" | ||
exit 1 | ||
fi | ||
git tag v${{ env._PKG_VERSION }} | ||
git push origin v${{ env._PKG_VERSION }} | ||
github-release: | ||
name: GitHub Release | ||
runs-on: ubuntu-22.04 | ||
needs: | ||
- repo-sync | ||
- validate | ||
env: | ||
_PKG_VERSION: ${{ needs.validate.outputs.version }} | ||
steps: | ||
- name: Login to Azure - Prod Subscription | ||
uses: Azure/login@92a5484dfaf04ca78a94597f4f19fea633851fa2 # v1.4.7 | ||
with: | ||
creds: ${{ secrets.AZURE_CI_SERVICE_PRINCIPAL }} | ||
|
||
- name: Retrieve secrets | ||
id: retrieve-secrets | ||
uses: bitwarden/gh-actions/get-keyvault-secrets@62d1bf7c3e31c458cc7236b1e69a475d235cd78f | ||
with: | ||
keyvault: ${{ env._KEY_VAULT }} | ||
secrets: "github-pat-bitwarden-devops-bot-repo-scope" | ||
|
||
- name: Create release | ||
if: ${{ github.event.inputs.release_type != 'Dry Run' }} | ||
uses: ncipollo/release-action@6c75be85e571768fa31b40abf38de58ba0397db5 # v1.13.0 | ||
with: | ||
tag: v${{ env._PKG_VERSION }} | ||
name: v${{ env._PKG_VERSION }} | ||
body: "<insert release notes here>" | ||
token: ${{ steps.retrieve-secrets.outputs.github-pat-bitwarden-devops-bot-repo-scope }} | ||
draft: true | ||
repo: bitwarden/sm-sdk-go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.1.0 |