Skip to content

Commit 3af6272

Browse files
authored
Merge pull request #30 from oidc-mytoken/prerel
0.6
2 parents 3b54513 + 4b05456 commit 3af6272

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+520
-2292
lines changed

Diff for: .github/workflows/go.yml

-38
This file was deleted.

Diff for: .github/workflows/release.yaml

-28
This file was deleted.

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ config/config.yaml
66
config/config-dev.yaml
77
/cmd/test
88
dist/
9+
.cache/

Diff for: .gitlab-ci-scripts/goreleaser.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
mkdir -p ../shared
2+
first=$(grep '^## ' -nm1 CHANGELOG.md | cut -d':' -f1); \
3+
second=$(grep '^## ' -nm2 CHANGELOG.md | tail -n1 | cut -d':' -f1); \
4+
tail -n+$first CHANGELOG.md | head -n$(($second-$first)) > ../shared/release.md
5+
GORELEASER_CONFIG=".goreleaser.yml"
6+
if [ -n "$CI_COMMIT_TAG" ] && echo "$CI_COMMIT_TAG" | grep -qv '~'; then
7+
GORELEASER_CONFIG=".goreleaser-release.yml"
8+
fi
9+
BASEDIR=/go/src/github.com/oidc-mytoken/client
10+
docker run --rm --privileged \
11+
-v "$PWD":"$BASEDIR" \
12+
-w "$BASEDIR" \
13+
-v "${PWD}/../shared":/tmp/shared \
14+
-v /var/run/docker.sock:/var/run/docker.sock \
15+
-e DOCKER_USERNAME -e DOCKER_PASSWORD \
16+
-e GITHUB_TOKEN \
17+
-e GORELEASER_CONFIG \
18+
goreleaser/goreleaser release -f $GORELEASER_CONFIG --release-notes /tmp/shared/release.md
19+
ls -l results

Diff for: .gitlab-ci-scripts/set-prerel-version.sh

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/sh
2+
3+
DEVSTRING="pr"
4+
VERSION_FILE=internal/model/version/VERSION
5+
6+
while [ $# -gt 0 ]; do
7+
case $1 in
8+
--devstring)
9+
DEVSTRING="$2"
10+
shift # past argument
11+
shift # past value
12+
;;
13+
--version_file)
14+
VERSION_FILE="$2"
15+
shift # past argument
16+
shift # past value
17+
;;
18+
--*|-*)
19+
echo "Unknown option $1"
20+
exit 1
21+
;;
22+
esac
23+
done
24+
25+
git config user.email || {
26+
echo "Setting up git in CI"
27+
git config --global --add safe.directory "$PWD"
28+
git config user.email "[email protected]"
29+
git config user.name "cicd"
30+
}
31+
32+
# Get master branch name:
33+
# use origin if exists
34+
# else use last found remote
35+
REMOTES=$(git remote show)
36+
for R in $REMOTES; do
37+
MASTER=master
38+
MASTER_BRANCH="refs/remotes/${R}/${MASTER}"
39+
#echo "Master-branch: ${MASTER_BRANCH}"
40+
[ "x${R}" = "xorigin" ] && break
41+
done
42+
43+
PREREL=$(git rev-list --count HEAD ^"$MASTER_BRANCH")
44+
45+
# use version file:
46+
VERSION=$(cat "$VERSION_FILE")
47+
PR_VERSION="${VERSION}-${DEVSTRING}${PREREL}"
48+
echo "$PR_VERSION" > "$VERSION_FILE"
49+
echo "$PR_VERSION"
50+
51+
echo "$PR_VERSION" > "$VERSION_FILE"
52+
git add "$VERSION_FILE"
53+
git commit -m "dummy prerel version"
54+
git tag "v${PR_VERSION}"

Diff for: .gitlab-ci-scripts/upload.sh

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
REPO_TARGET="/prerel"
3+
if [ -n "$CI_COMMIT_TAG" ] && echo "$CI_COMMIT_TAG" | grep -qv '~'; then
4+
REPO_TARGET="/preprod"
5+
fi
6+
7+
# ssh-key-script
8+
[ -e /tmp/ssh-private-keys/${REPO_USER} ] && {
9+
eval $(ssh-agent -s)
10+
cat /tmp/ssh-private-keys/${REPO_USER} | tr -d '\r' | ssh-add -
11+
test -d ~/.ssh || mkdir -p ~/.ssh
12+
chmod 700 ~/.ssh
13+
}
14+
[ -e /tmp/ssh-private-keys/known_hosts ] && {
15+
test -d ~/.ssh || mkdir -p ~/.ssh
16+
cp /tmp/ssh-private-keys/known_hosts ~/.ssh/known_hosts
17+
chmod 644 ~/.ssh/known_hosts
18+
}
19+
ssh-add -l
20+
ssh -o StrictHostKeyChecking=no "${REPO_USER}@${REPO_HOST}" "hostname -f"
21+
22+
# sign-repo function
23+
sign_repos() {
24+
ssh "${REPO_USER}@${REPO_HOST}" "~/ci-voodoo/ci-tools/sign-all-repos.sh -t ${REPO_TARGET}"
25+
}
26+
27+
upload_files() {
28+
UPLOAD_DIR=/tmp/package-upload
29+
ssh "${REPO_USER}@${REPO_HOST}" "rm -rf $UPLOAD_DIR && mkdir -p $UPLOAD_DIR"
30+
scp results/* "${REPO_USER}@${REPO_HOST}:${UPLOAD_DIR}"
31+
}
32+
33+
distribute_files() {
34+
ssh "${REPO_USER}@${REPO_HOST}" "~/ci-voodoo/ci-tools/distribute-local-packages.sh -t ${REPO_TARGET} -w mytoken"
35+
}
36+
37+
38+
# upload and sign
39+
upload_files
40+
distribute_files
41+
sign_repos

Diff for: .gitlab-ci.yml

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
image: golang:1.16
2+
stages:
3+
- build
4+
- test
5+
- lint
6+
- release
7+
8+
default:
9+
tags:
10+
- linux
11+
cache:
12+
paths:
13+
- .cache
14+
15+
16+
before_script:
17+
- mkdir -p .cache
18+
- export GOPATH=${CI_PROJECT_DIR}/.cache
19+
20+
test:
21+
stage: test
22+
script:
23+
- go test -v ./...
24+
25+
test_race:
26+
stage: test
27+
script:
28+
- go test -race -v ./...
29+
30+
staticcheck:
31+
image: golang:1.19
32+
stage: lint
33+
before_script:
34+
- go install honnef.co/go/tools/cmd/staticcheck@latest
35+
script:
36+
- staticcheck ./...
37+
38+
vet:
39+
stage: lint
40+
script:
41+
- go vet ./...
42+
43+
build:
44+
stage: build
45+
script:
46+
- go build github.com/oidc-mytoken/client/cmd/mytoken
47+
48+
prerelease:
49+
stage: release
50+
image:
51+
name: docker:stable
52+
services:
53+
- docker:dind
54+
only:
55+
refs:
56+
- tags
57+
- prerel
58+
tags:
59+
- linux
60+
variables:
61+
GIT_STRATEGY: clone
62+
GIT_DEPTH: 0
63+
REPO_HOST: repo.data.kit.edu
64+
REPO_USER: cicd
65+
script:
66+
- if [ -z "$CI_COMMIT_TAG" ]; then docker run --rm -v $PWD:/tmp/mytoken -w /tmp/mytoken bitnami/git .gitlab-ci-scripts/set-prerel-version.sh; fi;
67+
- .gitlab-ci-scripts/goreleaser.sh
68+
- .gitlab-ci-scripts/upload.sh
69+
after_script:
70+
- docker run --rm curlimages/curl -d "repo=github.com/oidc-mytoken/client" https://goreportcard.com/checks

Diff for: .goreleaser-release.yml

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
project_name: mytoken
2+
before:
3+
hooks:
4+
- go mod tidy
5+
dist: results
6+
builds:
7+
- id: client
8+
main: ./cmd/mytoken/main.go
9+
binary: mytoken
10+
env:
11+
- CGO_ENABLED=0
12+
goos:
13+
- linux
14+
- windows
15+
- darwin
16+
ignore:
17+
- goos: windows
18+
goarch: arm64
19+
flags:
20+
- -trimpath
21+
mod_timestamp: '{{ .CommitTimestamp }}'
22+
archives:
23+
- replacements:
24+
darwin: macOS
25+
386: 32-bit
26+
amd64: 64-bit
27+
format_overrides:
28+
- goos: windows
29+
format: zip
30+
nfpms:
31+
- id: client-pkg
32+
package_name: mytoken
33+
replacements:
34+
386: i386
35+
file_name_template: "{{ .PackageName }}_{{ .Version }}_{{ .Arch }}"
36+
builds:
37+
- client
38+
homepage: https://mytoken-docs.data.kit.edu/
39+
maintainer: Gabriel Zachmann <[email protected]>
40+
description: Mytoken is a command line client for the central web service mytoken. It can be used to easily obtain OpenID Connect access tokens across devices.
41+
license: MIT
42+
formats:
43+
- deb
44+
- rpm
45+
release: 1
46+
section: misc
47+
bindir: /usr/bin
48+
contents:
49+
- src: config/example-config.yaml
50+
dst: /etc/mytoken/example-config.yaml
51+
type: config
52+
overrides:
53+
rpm:
54+
replacements:
55+
amd64: x86_64
56+
file_name_template: "{{ .PackageName }}-{{ .Version }}.{{ .Arch }}"
57+
dockers:
58+
- goos: linux
59+
goarch: amd64
60+
ids:
61+
- client
62+
image_templates:
63+
- "oidcmytoken/mytoken:latest"
64+
- "oidcmytoken/mytoken:{{ .Tag }}"
65+
- "oidcmytoken/mytoken:{{ .Major }}"
66+
- "oidcmytoken/mytoken:{{ .Major }}.{{ .Minor }}"
67+
dockerfile: cmd/mytoken/Dockerfile
68+
build_flag_templates:
69+
- "--pull"
70+
- "--label=org.opencontainers.image.created={{.Date}}"
71+
- "--label=org.opencontainers.image.title=mytoken"
72+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
73+
- "--label=org.opencontainers.image.version={{.Version}}"
74+
75+
checksum:
76+
name_template: 'checksums.txt'
77+
snapshot:
78+
name_template: "{{ .Tag }}-next"
79+
release:
80+
disable: true
81+
prerelease: auto
82+
draft: true
83+
github:
84+
owner: oidc-mytoken
85+
name: client
86+
name_template: "{{.ProjectName}} {{.Version}}"
87+
changelog:
88+
sort: asc
89+
filters:
90+
exclude:
91+
- '^docs:'
92+
- '^test:'

0 commit comments

Comments
 (0)