drone ci and git release

This commit is contained in:
unurled 2022-09-24 18:26:19 +02:00
parent 4193b3e1d4
commit 0046bc3ed6
2 changed files with 103 additions and 36 deletions

View file

@ -2,52 +2,72 @@ kind: pipeline
type: exec
name: default
platform:
os: linux
arch: amd64
steps:
- name: restore-cache-with-filesystem
image: drillster/drone-volume-cache
settings:
restore: true
mount:
- ./build
- ./.gradle
# Mount the cache volume, needs "Trusted"
volumes:
- name: cache
path: /cache
commands:
- ls -a /tmp/drone/Elixium/Raxen
- ls -a
- cp -r /tmp/drone/Elixium/Raxen $(pwd)/
- ls -a
# settings:
# restore: true
# mount:
# - ./build
# - ./.gradle
# ## Mount the cache volume, needs "Trusted"
# volumes:
# - name: cache
# path: /cache
- name: build
image: gradle:jdk17
commands:
- ls -a
- gradle assemble --stacktrace
- ls -a
- name: gitea_release
image: plugins/gitea-release
settings:
base_url: https://git.unurled.me
files: build/libs/*
api_key:
from_secret: api_key
prerelease: true
when:
event: tag
event:
- tag
commands:
- export PRERELEASE=true
- chmod +x git_release.sh
- python git_release.py --token "$API_KEY" --message "${DRONE_COMMIT_MESSAGE}" --prerelease $PRERELEASE --tag "${DRONE_TAG}"
environment:
API_KEY:
from_secret: api_key
# settings:
# base_url: https://git.unurled.me
# files: build/libs/*
# api_key:
# from_secret: api_key
# prerelease: true
# when:
# event: tag
- name: rebuild-cache-with-filesystem
image: drillster/drone-volume-cache
settings:
rebuild: true
mount:
- ./build
- ./.gradle
# Mount the cache volume, needs "Trusted"
volumes:
- name: cache
path: /cache
volumes:
- name: cache
host:
path: /tmp/cache
# temp: {}
commands:
- ls -a
- mkdir -p /tmp/drone/Elixium/Raxen
- ls -a /tmp/drone/Elixium/Raxen
- mv -f -t $(pwd)/build/classes /tmp/drone/Elixium/Raxen
- mv -f -t $(pwd)/build/generated /tmp/drone/Elixium/Raxen
- mv -f -t $(pwd)/build/resources /tmp/drone/Elixium/Raxen
- mv -f -t $(pwd)/build/tmp /tmp/drone/Elixium/Raxen
- mv -f -t $(pwd)/.gradle /tmp/drone/Elixium/Raxen
- ls -a
- ls -a /tmp/drone/Elixium/Raxen
# image: drillster/drone-volume-cache
# settings:
# rebuild: true
# mount:
# - ./build
# - ./.gradle
# # Mount the cache volume, needs "Trusted"
# volumes:
# - name: cache
# path: /cache

47
git_release.py Normal file
View file

@ -0,0 +1,47 @@
import os
import argparse
import giteapy
from giteapy.rest import ApiException
parser = argparse.ArgumentParser(description="publish to git.unurled.me the release.")
parser.add_argument('--token', type=str, help="a token which have sufficient permission")
parser.add_argument('--message', type=str)
parser.add_argument('--prerelease', type=bool)
parser.add_argument('--tag', type=str)
args = parser.parse_args()
doc = vars(args)
print(doc)
configuration = giteapy.Configuration()
configuration.api_key['access_token'] = doc['token']
configuration.host = 'https://git.unurled.me/api/v1'
api_instance = giteapy.RepositoryApi(giteapy.ApiClient(configuration))
owner = "Elixium"
repo = "Raxen"
body = giteapy.CreateReleaseOption(body=doc['message'], draft=False, name=doc['tag'], prerelease=doc['prerelease'], tag_name=doc['tag'], target_commitish="string")
attachments = []
for file in os.listdir(os.getcwd() +"/build/libs"):
if file.endswith('.jar'):
if file.startswith('raxen'):
attachments.append(os.getcwd() + '/build/libs/' + file)
print(attachments)
attachment1 = attachments[0]
attachment2 = attachments[1]
attachment3 = attachments[2]
name1 = attachments[0].split("libs/")[1]
name2 = attachments[1].split("libs/")[1]
name3 = attachments[2].split("libs/")[1]
try:
# Create a release
api_response = api_instance.repo_create_release(owner, repo, body=body)
print(api_response.id)
attachement_response = api_instance.repo_create_release_attachment(owner, repo, api_response.id, attachment=attachment1, name=name1)
attachement_response = api_instance.repo_create_release_attachment(owner, repo, api_response.id, attachment=attachment2, name=name2)
attachement_response = api_instance.repo_create_release_attachment(owner, repo, api_response.id, attachment=attachment3, name=name3)
print(attachement_response)
except ApiException as e:
print("Exception when calling RepositoryApi->repo_create_release: %s\n" % e)