From 0046bc3ed6426fe11de511f26e561d0bb31a19cd Mon Sep 17 00:00:00 2001 From: unurled Date: Sat, 24 Sep 2022 18:26:19 +0200 Subject: [PATCH] drone ci and git release --- .drone.yml | 92 ++++++++++++++++++++++++++++++-------------------- git_release.py | 47 ++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 36 deletions(-) create mode 100644 git_release.py diff --git a/.drone.yml b/.drone.yml index de7807e..b5a4364 100644 --- a/.drone.yml +++ b/.drone.yml @@ -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 diff --git a/git_release.py b/git_release.py new file mode 100644 index 0000000..38aa546 --- /dev/null +++ b/git_release.py @@ -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) \ No newline at end of file