chore: migrate from gitlab-ci to woodpecker
Some checks failed
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline failed

This commit is contained in:
s3lph 2023-07-29 03:14:41 +02:00
parent 9dc449b334
commit 3469248af1
3 changed files with 52 additions and 166 deletions

View file

@ -1,32 +0,0 @@
---
image: golang:1.19
stages:
- test
- build
- release
compile:
stage: test
script:
- go get -v
- make prometheus-dnssec-exporter .changes
artifacts:
paths:
- prometheus-dnssec-exporter
- .changes
golangci-lint:
stage: test
script:
- go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.2
- golangci-lint run
release:
image: python:3.9
stage: release
script:
- python3 package/release.py
only:
- tags

52
.woodpecker.yml Normal file
View file

@ -0,0 +1,52 @@
---
pipeline:
compile:
image: golang:1.19
group: test
commands:
- go get -v
- make prometheus-dnssec-exporter .changes
golangci-lint:
image: golang:1.19
group: test
commands:
- go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.2
- golangci-lint run
build_debian:
image: debian:bookworm
group: package
when:
- event: tag
commands:
- apt update; apt install -y lintian sudo curl git
- export EXPORTER_VERSION=$(git describe --tags --dirty | sed -re s/^v// | cut -d- -f1)
- mkdir -p package/debian/prometheus-dnssec-exporter/usr/share/doc/prometheus-dnssec-exporter
- |
(for ref in $(git tag --sort=-refname | grep -v v0.0.0); do
echo -e "prometheus-dnssec-exporter ($${ref:1}) stable; urgency=medium\n"
git log --format=' * %s' "$(git describe --tags --abbrev=0 $${ref}^)..$${ref}"
DATE="$(git log --tags --simplify-by-decoration --pretty='format:%aD' "$${ref}^..$${ref}")"
echo -e "\n -- s3lph <s3lph@kabelsalat.ch> $${DATE}\n"
done) > package/debian/prometheus-dnssec-exporter/usr/share/doc/prometheus-dnssec-exporter/changelog
- gzip -9n package/debian/prometheus-dnssec-exporter/usr/share/doc/prometheus-dnssec-exporter/changelog
- mkdir -p package/debian/prometheus-dnssec-exporter/usr/bin
- cp prometheus-dnssec-exporter package/debian/prometheus-dnssec-exporter/usr/bin
- cd package/debian/prometheus-dnssec-exporter
- find . -exec chown root:root {} \;
- find . -type f -exec chmod 0644 {} \;
- find . -type d -exec chmod 755 {} \;
- chmod +x usr/bin/prometheus-dnssec-exporter DEBIAN/postinst DEBIAN/prerm
- sed -re "s/__VERSION__/$${EXPORTER_VERSION}-1/g" -i DEBIAN/control
- cd ..
- dpkg-deb --build prometheus-dnssec-exporter
- mv "prometheus-dnssec-exporter.deb" "prometheus-dnssec-exporter_$${EXPORTER_VERSION}-1_all.deb"
- sudo -u nobody lintian "prometheus-dnssec-exporter_$${EXPORTER_VERSION}-1_all.deb" || true
- >-
curl
--user "$${GITEA_API_USERNAME}:$${GITEA_API_PASSWORD}"
--upload-file "prometheus-dnssec-exporter_$${EXPORTER_VERSION}-1_all.deb"
$${GITEA_API_REPOSITORY_DEB}

View file

@ -1,134 +0,0 @@
#!/usr/bin/env python3
from typing import Any, Dict, List, Optional, Tuple
import os
import sys
import json
import urllib.request
import http.client
from urllib.error import HTTPError
def read_changelog(tag: str) -> Optional[str]:
with open('.changes', 'r') as f:
return f.read()
def fetch_job_ids(project_id: int, pipeline_id: int, api_token: str) -> Dict[str, str]:
url: str = f'https://gitlab.com/api/v4/projects/{project_id}/pipelines/{pipeline_id}/jobs'
headers: Dict[str, str] = {
'Private-Token': api_token,
'User-Agent': 'curl/7.70.0'
}
req = urllib.request.Request(url, headers=headers)
try:
resp: http.client.HTTPResponse = urllib.request.urlopen(req)
except HTTPError as e:
print(e.read().decode())
sys.exit(1)
resp_data: bytes = resp.read()
joblist: List[Dict[str, Any]] = json.loads(resp_data.decode())
jobidmap: Dict[str, str] = {}
for job in joblist:
name: str = job['name']
job_id: str = job['id']
jobidmap[name] = job_id
return jobidmap
def fetch_binary_url(base_url: str, job_ids: Dict[str, str]) -> Optional[Tuple[str, str]]:
mybase: str = f'{base_url}/jobs/{job_ids["compile"]}/artifacts/raw'
binary_url: str = f'{mybase}/{wheel_filename}'
return binary_url
def main():
api_token: Optional[str] = os.getenv('GITLAB_API_TOKEN')
release_tag: Optional[str] = os.getenv('CI_COMMIT_TAG')
project_name: Optional[str] = os.getenv('CI_PROJECT_PATH')
project_id: Optional[str] = os.getenv('CI_PROJECT_ID')
pipeline_id: Optional[str] = os.getenv('CI_PIPELINE_ID')
if api_token is None:
print('GITLAB_API_TOKEN is not set.', file=sys.stderr)
sys.exit(1)
if release_tag is None:
print('CI_COMMIT_TAG is not set.', file=sys.stderr)
sys.exit(1)
if project_name is None:
print('CI_PROJECT_PATH is not set.', file=sys.stderr)
sys.exit(1)
if project_id is None:
print('CI_PROJECT_ID is not set.', file=sys.stderr)
sys.exit(1)
if pipeline_id is None:
print('CI_PIPELINE_ID is not set.', file=sys.stderr)
sys.exit(1)
changelog: Optional[str] = read_changelog(release_tag)
if changelog is None:
print('Changelog could not be parsed.', file=sys.stderr)
sys.exit(1)
job_ids: Dict[str, str] = fetch_job_ids(project_id, pipeline_id, api_token)
base_url: str = f'https://gitlab.com/{project_name}/-'
binary_url = fetch_wheel_url(base_url, job_ids)
augmented_changelog = f'''{changelog.strip()}
### Download
- [prometheus-dnssec-exporter]({binary_url})
'''
post_body: str = json.dumps({
'tag_name': release_tag,
'description': augmented_changelog,
'assets': {
'links': [
{
'name': 'promtheus-dnssec-exporter',
'url': binary_url,
'link_type': 'package'
}
]
}
})
gitlab_release_api_url: str = \
f'https://gitlab.com/api/v4/projects/{project_id}/releases'
headers: Dict[str, str] = {
'Private-Token': api_token,
'Content-Type': 'application/json; charset=utf-8',
'User-Agent': 'curl/7.70.0'
}
request = urllib.request.Request(
gitlab_release_api_url,
post_body.encode('utf-8'),
headers=headers,
method='POST'
)
try:
response: http.client.HTTPResponse = urllib.request.urlopen(request)
except HTTPError as e:
print(e.read().decode())
sys.exit(1)
response_bytes: bytes = response.read()
response_str: str = response_bytes.decode()
response_data: Dict[str, Any] = json.loads(response_str)
if response_data['tag_name'] != release_tag:
print('Something went wrong...', file=sys.stderr)
print(response_str, file=sys.stderr)
sys.exit(1)
print(response_data['description'])
if __name__ == '__main__':
main()