Skip to content

Commit

Permalink
chore: Adds a new step in release process that marks Jira version as …
Browse files Browse the repository at this point in the history
…released (#2136)

* add jira go library

* TEMPORARY call from gh action

* TEMPORARY: pass token

* version id

* release

* test gha

* own job

* check error

* add to release gh

* check pre

* don't check pre-release inside script

* check pre-release in gha
  • Loading branch information
lantoli authored Apr 12, 2024
1 parent 46e5dcb commit 108b8a1
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,17 @@ jobs:
env:
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jira-release-version:
if: ${{ !contains(inputs.version_number, 'pre') }}
needs: [ release ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491
with:
go-version-file: 'go.mod'
- run: make jira-release-version
env:
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
VERSION_NUMBER: ${{ inputs.version_number }}
4 changes: 4 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,7 @@ generate-changelog-entry:
.PHONY: check-changelog-entry-file
check-changelog-entry-file:
go run ./tools/check-changelog-entry-file/*.go

.PHONY: jira-release-version
jira-release-version:
go run ./tools/jira-release-version/*.go
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/mongodb/terraform-provider-mongodbatlas
go 1.22

require (
github.com/andygrunwald/go-jira/v2 v2.0.0-20240116150243-50d59fe116d6
github.com/aws/aws-sdk-go v1.51.18
github.com/go-test/deep v1.1.0
github.com/hashicorp/go-changelog v0.0.0-20240318095659-4d68c58a6e7f
Expand Down Expand Up @@ -51,12 +52,14 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/go-git/go-git/v5 v5.11.0 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.6.0 // indirect
Expand Down Expand Up @@ -106,6 +109,7 @@ require (
github.com/skeema/knownhosts v1.2.1 // indirect
github.com/spf13/afero v1.9.2 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/trivago/tgo v1.0.7 // indirect
github.com/ulikunitz/xz v0.5.10 // indirect
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0XSf3YxCJs6N6AOSrOx3obionmG7T0y0=
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
github.com/andybalholm/crlf v0.0.0-20171020200849-670099aa064f/go.mod h1:k8feO4+kXDxro6ErPXBRTJ/ro2mf0SsFG8s7doP9kJE=
github.com/andygrunwald/go-jira/v2 v2.0.0-20240116150243-50d59fe116d6 h1:pb8RtP8VEWP/BX1M7Kk/AAIGtqThmahV4L/+VcIVcEc=
github.com/andygrunwald/go-jira/v2 v2.0.0-20240116150243-50d59fe116d6/go.mod h1:TrfsnL20VgD+KgEw4gbTYuSAPE8T1ZxjMCFBGgGvNvI=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
Expand Down Expand Up @@ -300,6 +302,8 @@ github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
Expand Down Expand Up @@ -341,6 +345,8 @@ github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3a
github.com/go-test/deep v1.0.7/go.mod h1:QV8Hv/iy04NyLBxAdO9njL0iVPN1S4d/A3NVv1V36o8=
github.com/go-test/deep v1.1.0 h1:WOcxcdHcvdgThNXjw0t76K42FXTU7HpNQWHpA2HHNlg=
github.com/go-test/deep v1.1.0/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down Expand Up @@ -730,6 +736,8 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/trivago/tgo v1.0.7 h1:uaWH/XIy9aWYWpjm2CU3RpcqZXmX2ysQ9/Go+d9gyrM=
github.com/trivago/tgo v1.0.7/go.mod h1:w4dpD+3tzNIIiIfkWWa85w5/B77tlvdZckQ+6PkFnhc=
github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/ulikunitz/xz v0.5.10 h1:t92gobL9l3HE202wg3rlk19F6X+JOxl9BBrCCMYEYd8=
github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
Expand Down
78 changes: 78 additions & 0 deletions tools/jira-release-version/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package main

import (
"context"
"fmt"
"log"
"os"
"strings"
"time"

jira "github.com/andygrunwald/go-jira/v2/onpremise"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
)

const (
envJira = "JIRA_API_TOKEN"
envVersion = "VERSION_NUMBER"
projectID = "CLOUDP"
jiraURL = "https://jira.mongodb.org"
versionPrefix = "terraform-provider-"
)

func main() {
client := getJiraClient()
versionName := versionPrefix + getVersion()
versionID := getVersionID(client, versionName)
setReleased(client, versionID)
url := fmt.Sprintf("%s/projects/%s/versions/%s", jiraURL, projectID, versionID)
fmt.Printf("Version released, please check all tickets are marked as done: %s\n", url)
}

func getJiraClient() *jira.Client {
apiToken := os.Getenv(envJira)
if apiToken == "" {
log.Fatalf("Environment variable %s is required", envJira)
}
tp := jira.BearerAuthTransport{Token: apiToken}
client, err := jira.NewClient(jiraURL, tp.Client())
if err != nil {
log.Fatalf("Error getting Jira client: %v", err)
}
return client
}

func getVersion() string {
version := os.Getenv(envVersion)
if version == "" {
log.Fatalf("Environment variable %s is required", envVersion)
}
return strings.TrimPrefix(version, "v")
}

func getVersionID(client *jira.Client, versionName string) string {
projects, _, err := client.Project.Get(context.Background(), projectID)
if err != nil {
log.Fatalf("Error getting project info: %v", err)
}
for i := range projects.Versions {
v := &projects.Versions[i]
if v.Name == versionName {
return v.ID
}
}
log.Fatalf("Version not found: %s", versionName)
return ""
}

func setReleased(client *jira.Client, versionID string) {
version := &jira.Version{
ID: versionID,
Released: conversion.Pointer(true),
ReleaseDate: time.Now().UTC().Format("2006-01-02"),
}
_, _, err := client.Version.Update(context.Background(), version)
if err != nil {
log.Fatalf("Error updating version %s: %v", versionID, err)
}
}

0 comments on commit 108b8a1

Please sign in to comment.