Skip to content

Commit f12111c

Browse files
authored
Merge pull request #144 from stefanotorresi/feature/new-obs-release-process
new obs release process
2 parents 5bb1c3d + fb1b129 commit f12111c

File tree

6 files changed

+110
-52
lines changed

6 files changed

+110
-52
lines changed

.ci/gh_release_to_obs_changeset.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import argparse
44
import json
5+
import os
56
import sys
67
import textwrap
7-
from urllib import request
8+
import urllib.request
89
import urllib.error
910
from datetime import datetime
1011
from datetime import timezone
@@ -25,9 +26,18 @@
2526
releaseSegment = f"/tags/{args.tag}" if args.tag else "/latest"
2627
url = f'https://api.github.com/repos/{args.repo}/releases{releaseSegment}'
2728

29+
request = urllib.request.Request(url)
30+
31+
githubToken = os.getenv("GITHUB_OAUTH_TOKEN")
32+
if githubToken:
33+
request.add_header("Authorization", "token " + githubToken)
34+
2835
try:
29-
response = request.urlopen(url)
36+
response = urllib.request.urlopen(request)
3037
except urllib.error.HTTPError as error:
38+
if error.code == 404:
39+
print(f"Release {args.tag} not found in {args.repo}. Skipping changelog generation.")
40+
sys.exit(0)
3141
print(f"GitHub API responded with a {error.code} error!", file=sys.stderr)
3242
print("Url:", url, file=sys.stderr)
3343
print("Response:", json.dumps(json.load(error), indent=4), file=sys.stderr, sep="\n")

.travis.yml

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ jobs:
1414
- stage: Test
1515
name: Unit tests
1616
script: make test
17-
- stage: Build & release
17+
- stage: Release
18+
name: Build and upload binaries on GitHub
1819
if: tag IS present
1920
services:
2021
- docker
@@ -24,16 +25,38 @@ jobs:
2425
- make -j4 build-all
2526
deploy:
2627
provider: releases
27-
api_key: $GITHUB_OAUTH_TOKEN
28-
file_glob: yes
28+
token: $GITHUB_OAUTH_TOKEN
29+
file_glob: true
2930
file: build/bin/*
3031
name: $TRAVIS_TAG
3132
skip_cleanup: true
33+
overwrite: true
3234
on:
3335
tags: true
34-
after_deploy:
36+
- stage: OBS delivery
37+
name: Commit to OBS dev project
38+
if: branch = master AND type != pull_request
39+
services:
40+
- docker
41+
env:
42+
- VERSION=$TRAVIS_COMMIT
43+
script:
44+
- |
45+
docker run --rm -t -v "$(pwd):/package" -w /package \
46+
-e OBS_USER -e OBS_PASS -e OBS_PROJECT -e OBS_PACKAGE -e VERSION -e REPOSITORY=$TRAVIS_REPO_SLUG -e GITHUB_OAUTH_TOKEN \
47+
shap/continuous_deliver \
48+
bash -c "/scripts/init_osc_creds.sh && make obs-commit"
49+
- stage: OBS delivery
50+
name: Submit Request to OBS stable project
51+
if: tag IS present
52+
services:
53+
- docker
54+
env:
55+
- VERSION=$TRAVIS_TAG
56+
script:
3557
- |
36-
docker run --rm -t -v "$(pwd):/package" -v "$GOPATH/pkg/mod:/root/go/pkg/mod" -w /package \
37-
-e OBS_USER -e OBS_PASS -e OBS_PROJECT -e OBS_PACKAGE -e VERSION -e REPOSITORY=$TRAVIS_REPO_SLUG \
58+
docker run --rm -t -v "$(pwd):/package" -w /package \
59+
-e OBS_USER -e OBS_PASS -e OBS_PROJECT -e OBS_PACKAGE -e VERSION -e REPOSITORY=$TRAVIS_REPO_SLUG -e GITHUB_OAUTH_TOKEN \
60+
-e PACKAGE_NAME=$OBS_PACKAGE -e TARGET_PROJECT=$OBS_DOWNSTREAM_PROJECT \
3861
shap/continuous_deliver \
39-
bash -c "/scripts/init_osc_creds.sh && make obs-commit" || travis_terminate 1
62+
bash -c "/scripts/init_osc_creds.sh && make obs-commit && /scripts/submit.sh"

Makefile

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# this is the what ends up in the RPM "Version" field and it is also used as suffix for the built binaries
2-
# it can be arbitrary for local builds, but it if you want to commit to OBS it must correspond to a Git tag with an associated GitHub release
3-
VERSION ?= dev
2+
# if you want to commit to OBS it must be a remotely available Git reference
3+
VERSION ?= $(shell git rev-parse --short HEAD)
44

55
# we only use this to comply with RPM changelog conventions at SUSE
66
@@ -13,7 +13,7 @@ REPOSITORY ?= clusterlabs/ha_cluster_exporter
1313
# the Go archs we crosscompile to
1414
ARCHS ?= amd64 arm64 ppc64le s390x
1515

16-
default: clean mod-tidy fmt vet-check test build
16+
default: clean download mod-tidy fmt vet-check test build
1717

1818
download:
1919
go mod download
@@ -47,32 +47,34 @@ fmt-check:
4747
test: download
4848
go test -v ./...
4949

50-
coverage: coverage.out
51-
coverage.out:
52-
go test -cover -coverprofile=coverage.out ./...
53-
go tool cover -html=coverage.out
50+
coverage:
51+
@mkdir build
52+
go test -cover -coverprofile=build/coverage ./...
53+
go tool cover -html=build/coverage
5454

5555
clean: clean-bin clean-obs
5656
go clean
57-
rm -f coverage.out
57+
rm -rf build
5858

5959
clean-bin:
6060
rm -rf build/bin
6161

6262
clean-obs:
6363
rm -rf build/obs
6464

65-
obs-workdir: build/obs
66-
build/obs:
67-
osc checkout $(OBS_PROJECT)/$(OBS_PACKAGE) -o build/obs
65+
obs-workdir: clean-obs
66+
@mkdir -p build/obs
67+
osc checkout $(OBS_PROJECT) $(OBS_PACKAGE) -o build/obs
6868
rm -f build/obs/*.tar.gz
6969
cp -rv packaging/obs/* build/obs/
70-
sed -i 's/%%VERSION%%/$(VERSION)/' build/obs/_service
70+
# we interpolate environment variables in OBS _service file so that we control what is downloaded by the tar_scm source service
71+
sed -i 's~%%VERSION%%~$(VERSION)~' build/obs/_service
72+
sed -i 's~%%REPOSITORY%%~$(REPOSITORY)~' build/obs/_service
7173
cd build/obs; osc service runall
7274
.ci/gh_release_to_obs_changeset.py $(REPOSITORY) -a $(AUTHOR) -t $(VERSION) -f build/obs/$(OBS_PACKAGE).changes || true
7375

7476
obs-commit: obs-workdir
7577
cd build/obs; osc addremove
76-
cd build/obs; osc commit -m "Automated $(VERSION) release"
78+
cd build/obs; osc commit -m "Update to git ref $(VERSION)"
7779

78-
.PHONY: default download install static-checks vet-check fmt fmt-check mod-tidy test clean clean-bin clean-obs build build-all obs-commit obs-workdir $(ARCHS)
80+
.PHONY: default download install static-checks vet-check fmt fmt-check mod-tidy test coverage clean clean-bin clean-obs build build-all obs-commit obs-workdir $(ARCHS)

README.md

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ This is a bespoke Prometheus exporter used to enable the monitoring of Pacemaker
88
1. [Features](#features)
99
2. [Installation](#installation)
1010
3. [Usage](#usage)
11-
4. [Development](#development)
11+
1. [Metrics](doc/metrics.md)
12+
5. [Contributing](#contributing)
13+
1. [Design](doc/design.md)
14+
2. [Development](doc/development.md)
1215
5. [License](#license)
1316

1417
## Features
@@ -32,7 +35,6 @@ The project can be installed in many ways, including but not limited to:
3235
2. [Go](#go)
3336
3. [RPM](#rpm)
3437

35-
3638
### Manual clone & build
3739

3840
```
@@ -73,6 +75,8 @@ It will export the metrics under the `/metrics` path, on port `9664` by default.
7375
While the exporter can run outside a HA cluster node, it won't export any metric it can't collect; e.g. it won't export DRBD metrics if it can't be locally inspected with `drbdsetup`.
7476
A warning message will inform the user of such cases.
7577

78+
Please, refer to [doc/metrics.md](doc/metrics.md) for extensive details about all the exported metrics.
79+
7680
**Hint:**
7781
You can deploy a full HA Cluster via Terraform with [SUSE/ha-sap-terraform-deployments](https://github.com/SUSE/ha-sap-terraform-deployments).
7882

@@ -102,30 +106,7 @@ systemctl --now enable prometheus-ha_cluster_exporter
102106

103107
Pull requests are more than welcome!
104108

105-
We recommend having a look at the [design document](doc/design.md) before contributing.
106-
107-
#### Makefile
108-
109-
Most development tasks can be accomplished via [make](Makefile).
110-
111-
The default target will clean, analyse, test and build the amd64 binary into the `build/bin` directory.
112-
113-
You can also cross-compile to the various architectures we support with `make build-all`.
114-
115-
##### Open Build Service releases
116-
117-
The CI will automatically publish GitHub releases to SUSE's Open Build Service: to perform a new release, just publish a new GH release or push a git tag. Tags must always follow the [SemVer](https://semver.org/) scheme.
118-
119-
If you wish to produce an OBS working directory locally, after you have configured [`osc`](https://en.opensuse.org/openSUSE:OSC) locally, you can run:
120-
```
121-
make obs-workdir
122-
```
123-
This will checkout the OBS project and prepare a release in the `build/obs` directory.
124-
125-
Note that, by default, `dev` is used as the RPM `Version` field, as well as a suffix for all the binary file names.
126-
To prepare an actual release, you can use the `VERSION` environment variable to set this value to an actual release tag.
127-
128-
To commit the release to OBS, run `make obs-commit`.
109+
We recommend having a look at the [design document](doc/design.md) and the [development notes](doc/development.md) before contributing.
129110

130111
## License
131112

doc/development.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Developer notes
2+
3+
1. [Makefile](#makefile)
4+
2. [OBS packaging](#obs-packaging)
5+
6+
7+
## Makefile
8+
9+
Most development tasks can be accomplished via [make](../Makefile).
10+
11+
For starters, you can run the default target with just `make`.
12+
13+
The default target will clean, analyse, test and build the amd64 binary into the `build/bin` directory.
14+
15+
You can also cross-compile to the various architectures we support with `make build-all`.
16+
17+
18+
## OBS Packaging
19+
20+
The CI will automatically publish GitHub releases to SUSE's Open Build Service: to perform a new release, just publish a new GH release or push a git tag. Tags must always follow the [SemVer](https://semver.org/) scheme.
21+
22+
If you wish to produce an OBS working directory locally, having configured [`osc`](https://en.opensuse.org/openSUSE:OSC) already, you can run:
23+
```
24+
make obs-workdir
25+
```
26+
This will checkout the OBS project and prepare a new OBS commit in the `build/obs` directory.
27+
28+
Note that, by default, the current Git working directory HEAD reference is used to download the sources from the remote, so this reference must have been pushed beforehand.
29+
30+
You can use the `OSB_PROJECT`, `OBS_PACKAGE`, `REPOSITORY` and `VERSION` environment variables to change the behaviour of OBS-related make targets.
31+
32+
For example, if you were on a feature branch of your own fork, you may want to change these variables, so:
33+
```bash
34+
git push feature/yxz # don't forget to make changes remotely available
35+
export OBS_PROJECT=home:JohnDoe
36+
export OBS_PACKAGE=my_project_branch
37+
export REPOSITORY=johndoe/my_forked_repo
38+
export VERSION=feature/yxz
39+
make obs-workdir
40+
```
41+
will prepare to commit on OBS into `home:JohnDoe/my_project_branch` by checking out the branch `feature/yxz` from `github.com/johndoe/my_forked_repo`.
42+
43+
At last, to actually perform the commit into OBS, run `make obs-commit`.

packaging/obs/_service

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
<services>
22
<service name="tar_scm" mode="disabled">
3-
<param name="url">git://github.com/ClusterLabs/ha_cluster_exporter.git</param>
3+
<param name="url">git://github.com/%%REPOSITORY%%.git</param>
44
<param name="scm">git</param>
55
<param name="revision">%%VERSION%%</param>
66
<param name="exclude">.git</param>
7-
<param name="versionformat">@PARENT_TAG@</param>
7+
<param name="versionformat">@PARENT_TAG@+git.%ct.%h</param>
88
<param name="filename">prometheus-ha_cluster_exporter</param>
99
</service>
1010
<service name="set_version" mode="disabled">
11-
<param name="version">%%VERSION%%</param>
1211
<param name="file">prometheus-ha_cluster_exporter.spec</param>
1312
</service>
1413
<service name="recompress" mode="disabled">

0 commit comments

Comments
 (0)