Skip to content

Commit 9867e58

Browse files
authored
Refactor publish pipeline around Git tags (GEA-12976) (#217)
1 parent a5d56b8 commit 9867e58

7 files changed

+94
-23
lines changed

.editorconfig

+4
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ indent_style = tab
1111

1212
[*.md]
1313
trim_trailing_whitespace = false
14+
15+
[*.sh]
16+
indent_size = 4
17+
indent_style = space

.gitlab-ci.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ stages:
1616
- unit_tests
1717
- integration_tests
1818
- examples
19+
- publish
1920

2021
include:
21-
- /pangea-sdk/.sdk-ci.yml
2222
- /examples/.examples-ci.yml
23+
- /pangea-sdk/.sdk-ci.yml

.pre-commit-config.yaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ repos:
44
hooks:
55
- id: check-json
66
- id: end-of-file-fixer
7-
-
8-
id: trailing-whitespace
7+
- id: trailing-whitespace
98
exclude: .md
109
- id: check-merge-conflict
1110
- id: debug-statements

CONTRIBUTING.md

+18
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@ Future support is incoming.
66
To install our linters, simply run `./dev/setup_repo.sh`
77
These linters will run on every `git commit` operation.
88

9+
## Publishing
10+
11+
Publishing pangea-sdk to pkg.go.dev is handled via a private GitLab CI pipeline.
12+
This pipeline is triggered when a Git tag is pushed to the repository. Git tags
13+
should be formatted as `pangea-sdk/vX.Y.Z`, where `vX.Y.Z` is the version number
14+
to publish.
15+
16+
1. Update the `version` constant in `pangea-sdk/v3/pangea/pangea.go`.
17+
2. Update the release notes in `CHANGELOG.md`.
18+
3. Author a commit with these changes and land it on `main`.
19+
4. `git tag -m pangea-sdk/vX.Y.Z pangea-sdk/vX.Y.Z 0000000`. Replace `vX.Y.Z`
20+
with the new version number and `0000000` with the commit SHA from the
21+
previous step.
22+
5. `git push --tags origin main`.
23+
24+
From here the GitLab CI pipeline will pick up the pushed Git tag and publish
25+
the package to pkg.go.dev.
26+
927
## Contributors
1028

1129
- Andrés Tournour ([email protected]). Code.

dev/validate_tag.sh

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
if [ $# -lt 1 ]; then
6+
echo "usage: validate_tag.sh <git_tag>"
7+
exit 1
8+
fi
9+
10+
GIT_TAG=$1
11+
12+
if [[ ! $GIT_TAG == "pangea-sdk/v"* ]]; then
13+
echo "Git tag must begin with a 'pangea-sdk/v'."
14+
exit 1
15+
fi
16+
17+
PACKAGE_NAME=$(echo "$GIT_TAG" | cut -d "/" -f 1)
18+
VERSION=$(echo "$GIT_TAG" | cut -d "/" -f 2)
19+
20+
if [[ ! "$VERSION" == *"v"* ]]; then
21+
echo "Git tag must contain a version number that's prefixed with 'v'."
22+
exit 1
23+
fi
24+
25+
# Trim the 'v'.
26+
VERSION="${VERSION:1}"
27+
28+
# Move to repo root.
29+
PARENT_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd -P)
30+
pushd "$PARENT_PATH/.."
31+
32+
GO_CONST_VERSION=$(grep -Eo "version.+=.+" pangea-sdk/v3/pangea/pangea.go | head -1)
33+
34+
if [[ ! "$GO_CONST_VERSION" == *"$VERSION"* ]]; then
35+
echo "Git tag version '$VERSION' does not match Go constant version '$GO_CONST_VERSION'."
36+
exit 1
37+
fi
38+
39+
popd

examples/.examples-ci.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ go-sdk-examples:
22
stage: examples
33
parallel:
44
matrix:
5-
- GO_VERSION: ['1.19', '1.20', '1.21']
5+
- GO_VERSION: ["1.19", "1.20", "1.21"]
66
EXAMPLE_FOLDER:
77
- audit
88
- authn
@@ -34,3 +34,5 @@ go-sdk-examples:
3434
script:
3535
- cd examples/${EXAMPLE_FOLDER}
3636
- bash ../../dev/run_examples.sh
37+
rules:
38+
- if: $CI_COMMIT_BRANCH

pangea-sdk/.sdk-ci.yml

+27-19
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
.go-sdk-base:
1+
.sdk-base:
22
before_script:
33
- cd pangea-sdk/v3
4-
- go install github.com/boumenot/gocover-cobertura@latest
54
rules:
65
- if: $CI_PIPELINE_SOURCE == "push"
76

8-
go-sdk-test-it:
7+
sdk-test-it:
98
stage: integration_tests
109
variables:
11-
# Set each service test environment
10+
# Set each service test environment
1211
SERVICE_AUDIT_ENV: LVE
1312
SERVICE_AUTHN_ENV: LVE
1413
SERVICE_EMBARGO_ENV: LVE
@@ -23,22 +22,21 @@ go-sdk-test-it:
2322
before_script:
2423
- echo $ENV
2524
- echo $CLOUD
26-
# Update environment variables
27-
# Domain
25+
# Update environment variables
26+
# Domain
2827
- export PANGEA_INTEGRATION_DOMAIN_${ENV}="$(eval echo \$PANGEA_INTEGRATION_DOMAIN_${ENV}_${CLOUD})"
29-
# Tokens
28+
# Tokens
3029
- export PANGEA_INTEGRATION_TOKEN_${ENV}="$(eval echo \$PANGEA_INTEGRATION_TOKEN_${ENV}_${CLOUD})"
3130
- export PANGEA_INTEGRATION_VAULT_TOKEN_${ENV}="$(eval echo \$PANGEA_INTEGRATION_VAULT_TOKEN_${ENV}_${CLOUD})"
3231
- export PANGEA_INTEGRATION_CUSTOM_SCHEMA_TOKEN_${ENV}="$(eval echo \$PANGEA_INTEGRATION_CUSTOM_SCHEMA_TOKEN_${ENV}_${CLOUD})"
3332
- export PANGEA_INTEGRATION_MULTI_CONFIG_TOKEN_${ENV}="$(eval echo \$PANGEA_INTEGRATION_MULTI_CONFIG_TOKEN_${ENV}_${CLOUD})"
34-
# Config IDs
33+
# Config IDs
3534
- export PANGEA_AUDIT_CONFIG_ID_1_${ENV}="$(eval echo \$PANGEA_AUDIT_CONFIG_ID_1_${ENV}_${CLOUD})"
3635
- export PANGEA_AUDIT_CONFIG_ID_2_${ENV}="$(eval echo \$PANGEA_AUDIT_CONFIG_ID_2_${ENV}_${CLOUD})"
3736
- export PANGEA_REDACT_CONFIG_ID_1_${ENV}="$(eval echo \$PANGEA_REDACT_CONFIG_ID_1_${ENV}_${CLOUD})"
3837
- export PANGEA_REDACT_CONFIG_ID_2_${ENV}="$(eval echo \$PANGEA_REDACT_CONFIG_ID_2_${ENV}_${CLOUD})"
3938

4039
- cd pangea-sdk/v3
41-
- go install github.com/boumenot/gocover-cobertura@latest
4240

4341
parallel:
4442
matrix:
@@ -76,35 +74,45 @@ go-sdk-test-it:
7674
ENV: ${SERVICE_VAULT_ENV}
7775
TEST: vault
7876
rules:
79-
- if: '$CLOUD == "GCP" && $TEST == "file_scan"'
77+
- if: $CI_COMMIT_BRANCH && '$CLOUD == "GCP" && $TEST == "file_scan"'
8078
allow_failure: true
81-
- if: '$CLOUD == "GCP" && $TEST != "file_scan"'
79+
- if: $CI_COMMIT_BRANCH && '$CLOUD == "GCP" && $TEST != "file_scan"'
8280
allow_failure: true
83-
- if: '$CLOUD != "GCP"'
81+
- if: $CI_COMMIT_BRANCH && '$CLOUD != "GCP"'
8482
allow_failure: false
8583
script:
8684
- go test -count=1 -tags integration -v ./service/${TEST}/...
8785

88-
go-sdk-lint:
89-
extends: .go-sdk-base
86+
sdk-lint:
87+
extends: .sdk-base
9088
stage: lint
9189
script:
9290
- make verify
9391

94-
go-sdk-generate-docs:
95-
extends: .go-sdk-base
92+
sdk-generate-docs:
93+
extends: .sdk-base
9694
stage: lint
9795
allow_failure: true
9896
script:
9997
- make docgen
10098
artifacts:
10199
expire_in: 1 month
102100
expose_as: go_sdk
103-
paths: ['pangea-sdk/v3/go_sdk.json']
101+
paths: ["pangea-sdk/v3/go_sdk.json"]
104102
when: on_success
105103

106-
go-sdk-unit-testing:
107-
extends: .go-sdk-base
104+
sdk-unit-testing:
105+
extends: .sdk-base
108106
stage: unit_tests
109107
script:
110108
- make unit
109+
110+
sdk-publish:
111+
stage: publish
112+
variables:
113+
GOPROXY: proxy.golang.org
114+
script:
115+
- bash ./dev/validate_tag.sh "$CI_COMMIT_TAG"
116+
- go list -m github.com/pangeacyber/pangea-go/pangea-sdk/v3@"$CI_COMMIT_TAG"
117+
rules:
118+
- if: $CI_COMMIT_TAG

0 commit comments

Comments
 (0)