Skip to content

Commit bf13aed

Browse files
Fix Github CI - Add tag_semver.sh and minor code refactor
1 parent c00a90c commit bf13aed

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

Diff for: internal/auth/auth.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ import (
1515
crusoeapi "github.com/crusoecloud/client-go/swagger/v1alpha5"
1616
)
1717

18+
const (
19+
timestampHeader = "X-Crusoe-Timestamp"
20+
authHeader = "Authorization"
21+
authVersion = "1.0"
22+
)
23+
24+
var errSemicolonSeparator = errors.New("invalid semicolon separator in query")
25+
1826
// AuthenticatingTransport is a struct implementing http.Roundtripper
1927
// that authenticates a request to Crusoe Cloud before sending it out.
2028
type AuthenticatingTransport struct {
@@ -44,12 +52,6 @@ func (t AuthenticatingTransport) RoundTrip(r *http.Request) (*http.Response, err
4452
return t.RoundTripper.RoundTrip(r)
4553
}
4654

47-
const (
48-
timestampHeader = "X-Crusoe-Timestamp"
49-
authHeader = "Authorization"
50-
authVersion = "1.0"
51-
)
52-
5355
// Verifies if the token signature is valid for a given request.
5456
func addSignature(req *http.Request, encodedKeyID, encodedKey string) error {
5557
req.Header.Set(timestampHeader, time.Now().UTC().Format(time.RFC3339))
@@ -109,8 +111,6 @@ func generateMessageV1_0(req *http.Request) ([]byte, error) {
109111
return []byte(messageString.String()), nil
110112
}
111113

112-
var errSemicolonSeparator = errors.New("invalid semicolon separator in query")
113-
114114
// Canonicalizes the query into a deterministic string.
115115
// see https://cs.opensource.google/go/go/+/refs/tags/go1.18.8:src/net/url/url.go;l=921
116116
func canonicalizeQuery(query string) (canonicalQuery string, err error) {

Diff for: scripts/tag_semver.sh

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
MAJOR_VERSION=$1
5+
MINOR_VERSION=$2
6+
TAG_PREFIX=$3
7+
8+
# find the latest tag
9+
NEW_VERSION="${TAG_PREFIX}v${MAJOR_VERSION}.${MINOR_VERSION}.0"
10+
git fetch -q --tags --prune --prune-tags
11+
tags=$(git tag -l ${TAG_PREFIX}v${MAJOR_VERSION}.${MINOR_VERSION}.* --sort=-version:refname)
12+
if [[ ! -z "$tags" ]]; then
13+
arr=(${tags})
14+
for val in ${arr[@]}; do
15+
if [[ "$val" =~ ^${TAG_PREFIX}v${MAJOR_VERSION}+\.${MINOR_VERSION}\.[0-9]+$ ]]; then
16+
prev_build=$(echo ${val} | cut -d. -f3)
17+
new_build=$((prev_build+1))
18+
NEW_VERSION="${TAG_PREFIX}v${MAJOR_VERSION}.${MINOR_VERSION}.${new_build}"
19+
break
20+
fi
21+
done
22+
fi
23+
24+
echo "Version for this commit: ${NEW_VERSION}"
25+
echo "RELEASE_VERSION=${NEW_VERSION}" >> variables.env

0 commit comments

Comments
 (0)