Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub actions workflows #163

Merged
merged 37 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
e9720e6
Create exporter.yml
stefanotorresi Jun 15, 2020
32f62a8
rename workflow
stefanotorresi Jun 15, 2020
acbdc85
add build job
stefanotorresi Jun 16, 2020
5565d63
add artifacts
stefanotorresi Jun 16, 2020
f57b355
remove build matrix
stefanotorresi Jun 16, 2020
18f3ad6
fix build-all make target
stefanotorresi Jun 16, 2020
0ad064d
change artifact name
stefanotorresi Jun 16, 2020
948b464
add obs-delivery job
stefanotorresi Jun 16, 2020
959f103
remove travis config
stefanotorresi Jun 16, 2020
006a87d
fix obs job
stefanotorresi Jun 16, 2020
f27a4ce
build all branches
stefanotorresi Jun 16, 2020
1ec31b3
add release event triggeris
stefanotorresi Jun 16, 2020
21acf3b
set OSCRC_FILE env var
stefanotorresi Jun 16, 2020
3465d9d
fix env var usage
stefanotorresi Jun 16, 2020
4954f9e
fix oscrc creds init
stefanotorresi Jun 16, 2020
2d9262c
try not splitting run steps
stefanotorresi Jun 16, 2020
238683c
run helper script first
stefanotorresi Jun 16, 2020
f592fbe
fix make changelog target
stefanotorresi Jun 16, 2020
e6ee8c8
split run steps again for clarity
stefanotorresi Jun 16, 2020
9ad798f
separate revision from version
stefanotorresi Jun 16, 2020
ed0f499
add number of commits since tags to development versions
stefanotorresi Jun 16, 2020
0758f19
put dev number in suffix
stefanotorresi Jun 16, 2020
5e61b95
use dash before arch suffix
stefanotorresi Jun 16, 2020
9508322
fix changelog generation
stefanotorresi Jun 16, 2020
d118de6
add dashbaord packaging files to ignored paths
stefanotorresi Jun 16, 2020
6e8b3bf
add dashboards workflow
stefanotorresi Jun 17, 2020
9fb54d7
add friendlier message about grafana.com
stefanotorresi Jun 17, 2020
12eb3af
use plain node action instead of jsonlint container
stefanotorresi Jun 17, 2020
bedf4dd
fix find cmd
stefanotorresi Jun 17, 2020
08cf933
don't run exporter workflow on changes to dashboard workflow config
stefanotorresi Jun 17, 2020
bf7add1
fix _service exclude params
stefanotorresi Jun 17, 2020
8c544c3
add dashboards development notes
stefanotorresi Jun 17, 2020
985d2f9
update exporter development notes
stefanotorresi Jun 17, 2020
976029e
remove branch restriction and enable workflows for pull requests targ…
stefanotorresi Jun 17, 2020
eae38a1
add a textual workflow description
stefanotorresi Jun 17, 2020
a414a77
line break
stefanotorresi Jun 17, 2020
8038af5
add more workflow docs
stefanotorresi Jun 17, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .ci/get_version_from_git.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh
TAG=$(git describe --tags --abbrev=0 2>/dev/null)
SUFFIX=$(git show -s --format=%ct.%h HEAD)

if [ -n "${TAG}" ]; then
COMMITS_SINCE_TAG=$(git rev-list ${TAG}.. --count)
if [ "${COMMITS_SINCE_TAG}" -gt 0 ]; then
SUFFIX="dev${COMMITS_SINCE_TAG}.${SUFFIX}"
fi
else
TAG="0"
fi

echo "${TAG}+git.${SUFFIX}"
51 changes: 51 additions & 0 deletions .github/workflows/dashboards-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Dashboards CI
MalloZup marked this conversation as resolved.
Show resolved Hide resolved

# this workflow will
# - check for JSON syntax errors on every pull request
# - commit to the OBS development upstream whenever master the master branch is updated

on:
push:
paths:
- 'dashboards/**'
- 'packaging/obs/grafana-ha-cluster-dashboards/**'
- '.github/workflows/dashboards*'
pull_request:
paths:
- 'dashboards/**'
- 'packaging/obs/grafana-ha-cluster-dashboards/**'
- '.github/workflows/dashboards*'

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- run: npm -g install jsonlint
- name: validate JSON
run: find dashboards -name "*.json" -type f -exec jsonlint -c {} \;

obs-commit:
needs: build
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
container: shap/continuous_deliver
MalloZup marked this conversation as resolved.
Show resolved Hide resolved
env:
OBS_USER: ${{ secrets.OBS_USER }}
OBS_PASS: ${{ secrets.OBS_PASS }}
OBS_PROJECT: ${{ secrets.OBS_PROJECT }}
REVISION: ${{ github.sha }}
REPOSITORY: ${{ github.repository }}
GITHUB_OAUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: configure OSC
run: |
/scripts/init_osc_creds.sh
mkdir -p $HOME/.config/osc
cp /root/.config/osc/oscrc $HOME/.config/osc
- run: make dashboards-obs-commit

107 changes: 107 additions & 0 deletions .github/workflows/exporter-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: Exporter CI
MalloZup marked this conversation as resolved.
Show resolved Hide resolved

# this workflow will
# - check build and test the go codebase on every pull request
# - commit to the OBS development upstream whenever master the master branch is updated
# - perform an OBS Submit Request to downstream whenever a GitHub release is published
# - attach build artifacts to GitHub releases

on:
push:
paths-ignore:
- 'dashboards/**'
- 'packaging/obs/grafana-ha-cluster-dashboards/**'
- '.github/workflows/dashboards*'
pull_request:
paths-ignore:
- 'dashboards/**'
- 'packaging/obs/grafana-ha-cluster-dashboards/**'
- '.github/workflows/dashboards*'
release:
types: [ published ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v2
with:
go-version: ^1.12
id: go
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: static analysis
run: make static-checks
- name: test
run: make test
- name: build
run: make -j4 build-all
- uses: actions/upload-artifact@v2
with:
name: ha_cluster_exporter
path: build/bin

obs-commit:
needs: build
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
container: shap/continuous_deliver
env:
OBS_USER: ${{ secrets.OBS_USER }}
OBS_PASS: ${{ secrets.OBS_PASS }}
OBS_PROJECT: ${{ secrets.OBS_PROJECT }}
REVISION: ${{ github.sha }}
REPOSITORY: ${{ github.repository }}
GITHUB_OAUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: configure OSC
run: |
/scripts/init_osc_creds.sh
mkdir -p $HOME/.config/osc
cp /root/.config/osc/oscrc $HOME/.config/osc
- run: make exporter-obs-commit

obs-submit-request:
needs: build
if: github.event.release
runs-on: ubuntu-latest
container: shap/continuous_deliver
env:
OBS_USER: ${{ secrets.OBS_USER }}
OBS_PASS: ${{ secrets.OBS_PASS }}
OBS_PROJECT: ${{ secrets.OBS_PROJECT }}
PACKAGE_NAME: prometheus-ha_cluster_exporter
TARGET_PROJECT: ${{ secrets.OBS_DOWNSTREAM_PROJECT }}
REVISION: ${{ github.event.release.tag_name }}
REPOSITORY: ${{ github.repository }}
GITHUB_OAUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: configure OSC
run: |
/scripts/init_osc_creds.sh
mkdir -p $HOME/.config/osc
cp /root/.config/osc/oscrc $HOME/.config/osc
- run: make exporter-obs-workdir
- run: make exporter-obs-changelog
- run: make exporter-obs-commit
- run: /scripts/submit.sh

github-release-assets:
needs: build
if: github.event.release
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v2
with:
name: ha_cluster_exporter
- uses: AButler/upload-release-assets@v2.0
with:
files: 'ha_cluster_exporter-*'
repo-token: ${{ secrets.GITHUB_TOKEN }}
62 changes: 0 additions & 62 deletions .travis.yml

This file was deleted.

29 changes: 17 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# this is the what ends up in the RPM "Version" field and it is also used as suffix for the built binaries
# if you want to release to OBS it must be a remotely available Git reference
VERSION ?= $(shell git describe --tags --abbrev=0)dev+git.$(shell git show -s --format=%ct.%h HEAD)
# this is the what ends up in the RPM "Version" field and embedded in the --version CLI flag
VERSION ?= $(shell .ci/get_version_from_git.sh)

# this
DATE = $(shell date --iso-8601=seconds)

# if you want to release to OBS, this must be a remotely available Git reference
REVISION ?= master

# we only use this to comply with RPM changelog conventions at SUSE
AUTHOR ?= shap-staff@suse.de

Expand All @@ -21,11 +25,11 @@ download:

build: amd64

build-all: clean-bin $(ARCHS)
build-all: clean $(ARCHS)

$(ARCHS):
@mkdir -p build/bin
CGO_ENABLED=0 GOOS=linux GOARCH=$@ go build -trimpath -ldflags "-s -w -X main.version=$(VERSION) -X main.buildDate=$(DATE)" -o build/bin/ha_cluster_exporter-$(VERSION)-$@
CGO_ENABLED=0 GOOS=linux GOARCH=$@ go build -trimpath -ldflags "-s -w -X main.version=$(VERSION) -X main.buildDate=$(DATE)" -o build/bin/ha_cluster_exporter-$@

install:
go install
Expand Down Expand Up @@ -56,32 +60,33 @@ clean:
go clean
rm -rf build

exporter-obs-workdir:
rm -rf build/obs/prometheus-ha_cluster_exporter
exporter-obs-workdir: build/obs/prometheus-ha_cluster_exporter
build/obs/prometheus-ha_cluster_exporter:
@mkdir -p build/obs/prometheus-ha_cluster_exporter
osc checkout $(OBS_PROJECT) prometheus-ha_cluster_exporter -o build/obs/prometheus-ha_cluster_exporter
rm -f build/obs/prometheus-ha_cluster_exporter/*.tar.gz
cp -rv packaging/obs/prometheus-ha_cluster_exporter/* build/obs/prometheus-ha_cluster_exporter/
# we interpolate environment variables in OBS _service file so that we control what is downloaded by the tar_scm source service
sed -i 's~%%VERSION%%~$(VERSION)~' build/obs/prometheus-ha_cluster_exporter/_service
sed -i 's~%%REVISION%%~$(REVISION)~' build/obs/prometheus-ha_cluster_exporter/_service
sed -i 's~%%REPOSITORY%%~$(REPOSITORY)~' build/obs/prometheus-ha_cluster_exporter/_service
cd build/obs/prometheus-ha_cluster_exporter; osc service runall

exporter-obs-changelog: exporter-obs-workdir
.ci/gh_release_to_obs_changeset.py $(REPOSITORY) -a $(AUTHOR) -t $(VERSION) -f build/obs/exporter/prometheus-ha_cluster_exporter.changes || true
.ci/gh_release_to_obs_changeset.py $(REPOSITORY) -a $(AUTHOR) -t $(REVISION) -f build/obs/prometheus-ha_cluster_exporter/prometheus-ha_cluster_exporter.changes

exporter-obs-commit: exporter-obs-workdir exporter-obs-changelog
exporter-obs-commit: exporter-obs-workdir
cd build/obs/prometheus-ha_cluster_exporter; osc addremove
cd build/obs/prometheus-ha_cluster_exporter; osc commit -m "Update to version $(VERSION)"

dashboards-obs-workdir:
rm -rf build/obs/grafana-ha-cluster-dashboards
dashboards-obs-workdir: build/obs/grafana-ha-cluster-dashboards
build/obs/grafana-ha-cluster-dashboards:
@mkdir -p build/obs/grafana-ha-cluster-dashboards
osc checkout $(OBS_PROJECT) grafana-ha-cluster-dashboards -o build/obs/grafana-ha-cluster-dashboards
rm -f build/obs/grafana-ha-cluster-dashboards/*.tar.gz
cp -rv packaging/obs/grafana-ha-cluster-dashboards/* build/obs/grafana-ha-cluster-dashboards/
# we interpolate environment variables in OBS _service file so that we control what is downloaded by the tar_scm source service
sed -i 's~%%VERSION%%~$(VERSION)~' build/obs/grafana-ha-cluster-dashboards/_service
sed -i 's~%%REVISION%%~$(REVISION)~' build/obs/grafana-ha-cluster-dashboards/_service
sed -i 's~%%REPOSITORY%%~$(REPOSITORY)~' build/obs/grafana-ha-cluster-dashboards/_service
cd build/obs/grafana-ha-cluster-dashboards; osc service runall

Expand Down
9 changes: 7 additions & 2 deletions dashboards/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ zypper in grafana-ha-cluster-dashboards
systemctl restart grafana-server
```

For the latest development version, please refer to the [development upstream project in OBS](https://build.opensuse.org/project/show/network:ha-clustering:sap-deployments:devel).
For the latest development version, please refer to the [development upstream project in OBS](https://build.opensuse.org/project/show/network:ha-clustering:sap-deployments:devel), which is automatically updated everytime we merge changes in this repository.

### Manual

Expand All @@ -39,5 +39,10 @@ Once done, restart the Grafana server.

### Grafana.com

TO-DO
Dashboards will be soon available on [grafana.com/dashboards](https://grafana.com/dashboards)

## Development notes

- Please make sure the `version` field in the JSON is incremented just once per PR.
- Unlike the exporter, OBS Submit Requests are not automated for the dashboard package.
Once PRs are merged, you will have to manually perform a Submit Request, after updating the `version` field in the `_service` file and adding an entry to the `grafana-ha-cluster-dashboards.changes` file.
6 changes: 3 additions & 3 deletions doc/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ You can also cross-compile to the various architectures we support with `make bu

## OBS Packaging

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.
The CI will automatically publish GitHub releases to SUSE's Open Build Service: to perform a new release, just publish a new GH release. Tags must always follow the [SemVer](https://semver.org/) scheme.

If you wish to produce an OBS working directory locally, having configured [`osc`](https://en.opensuse.org/openSUSE:OSC) already, you can run:
```
Expand All @@ -27,14 +27,14 @@ This will checkout the OBS project and prepare a new OBS commit in the `build/ob

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.

You can use the `OSB_PROJECT`, `REPOSITORY` and `VERSION` environment variables to change the behaviour of OBS-related make targets.
You can use the `OSB_PROJECT`, `REPOSITORY` and `REVISION` environment variables to change the behaviour of OBS-related make targets.

For example, if you were on a feature branch of your own fork, you may want to change these variables, so:
```bash
git push feature/yxz # don't forget to make changes remotely available
export OBS_PROJECT=home:JohnDoe
export REPOSITORY=johndoe/my_forked_repo
export VERSION=feature/yxz
export REVISION=feature/yxz
make exporter-obs-workdir
```
will prepare to commit on OBS into `home:JohnDoe/prometheus-ha_cluster_exporter` by checking out the branch `feature/yxz` from `github.com/johndoe/my_forked_repo`.
Expand Down
2 changes: 1 addition & 1 deletion packaging/obs/grafana-ha-cluster-dashboards/_service
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<service name="tar_scm" mode="disabled">
<param name="url">git://github.com/%%REPOSITORY%%.git</param>
<param name="scm">git</param>
<param name="revision">%%VERSION%%</param>
<param name="revision">%%REVISION%%</param>
<param name="include">dashboards</param>
<param name="include">LICENSE</param>
<param name="versionformat">1.0.0+git.%ct.%h</param>
Expand Down
9 changes: 6 additions & 3 deletions packaging/obs/prometheus-ha_cluster_exporter/_service
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
<service name="tar_scm" mode="disabled">
<param name="url">git://github.com/%%REPOSITORY%%.git</param>
<param name="scm">git</param>
<param name="revision">%%VERSION%%</param>
<param name="exclude">.git,dashboards</param>
<param name="versionformat">@PARENT_TAG@+git.%ct.%h</param>
<param name="revision">%%REVISION%%</param>
<param name="exclude">.git</param>
<param name="exclude">.github</param>
<param name="exclude">dashboards</param>
<param name="exclude">packaging/obs/grafana-ha-cluster-dashboards</param>
<param name="version">%%VERSION%%</param>
<param name="filename">prometheus-ha_cluster_exporter</param>
</service>
<service name="set_version" mode="disabled">
Expand Down