commit b1490f8516a395a8668ca3dcdad6e1896a5720d1 Author: incureforce Date: Thu Nov 9 21:27:31 2023 +0100 * draft diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..cf14727 --- /dev/null +++ b/action.yml @@ -0,0 +1,49 @@ +name: 'Create a Release' +description: 'Create a release for a tag in your repository' +author: 'GitHub' +inputs: + bin_path: + description: 'BINPATH' + required: true + # tag_name: + # description: 'The name of the tag. This should come from the webhook payload, `github.GITHUB_REF` when a user pushes a new tag' + # required: true + # release_name: + # description: 'The name of the release. For example, `Release v1.0.1`' + # required: true + # body: + # description: 'Text describing the contents of the tag.' + # required: false + # body_path: + # description: 'Path to file with information about the tag.' + # required: false + # draft: + # description: '`true` to create a draft (unpublished) release, `false` to create a published one. Default: `false`' + # required: false + # default: false + # prerelease: + # description: '`true` to identify the release as a prerelease. `false` to identify the release as a full release. Default: `false`' + # required: false + # default: false + # commitish: + # description: 'Any branch or commit SHA the Git tag is created from, unused if the Git tag already exists. Default: SHA of current commit' + # required: false + # owner: + # description: 'Owner of the repository if it is not the current one' + # required: false + # repo: + # description: 'Repository on which to release. Used only if you want to create the release on another repo' + # required: false +outputs: + # id: + # description: 'The ID of the created Release' + # html_url: + # description: 'The URL users can navigate to in order to view the release' + # upload_url: + # description: 'The URL for uploading assets to the release' +runs: + using: 'python' + main: 'scripts/release.py' +branding: + icon: 'tag' + color: 'gray-dark' \ No newline at end of file diff --git a/scripts/release.py b/scripts/release.py new file mode 100644 index 0000000..9bf496f --- /dev/null +++ b/scripts/release.py @@ -0,0 +1,58 @@ +import requests +import zipfile +import os +from pathlib import Path + +# Replace these with your details +GITHUB_SERVER_URL = os.getenv('GITHUB_SERVER_URL') +GITHUB_REPOSITORY = os.getenv('GITHUB_REPOSITORY') + +# Set the path to your bin directory + +bin_path = os.getenv('bin_path') or 'bin' +zip_name = os.getenv('zip_name') or 'release.zip' +rel_name = os.getenv('rel_name') or 'Content Release' +rel_desc = os.getenv('rel_desc') or 'Automatic Content Release from GITEA workflow' + +access_token = os.getenv('access_token') # Make sure to set this to your Gitea access token + +# Zip the files in the bin directory +with zipfile.ZipFile(zip_name, 'w') as zipf: + for root, dirs, files in os.walk(bin_path): + for file in files: + zipf.write(os.path.join(root, file), os.path.relpath(os.path.join(root, file), os.path.join(bin_path, '..'))) + +# Create a release +release_url = f'{GITHUB_SERVER_URL}/api/v1/repos/{GITHUB_REPOSITORY}/releases' +headers = { + 'Authorization': f'token {access_token}' +} +data = { + "body": rel_desc, + "name": rel_name, + "draft": True, + "prerelease": True, + "tag_name": "v1.0.0", + "target_commitish": "master" +} + +response = requests.post(release_url, json=data, headers=headers) + +if response.ok: + release = response.json() + release_id = release['id'] + + # Create a release attachment + attachment_url = f'{GITHUB_SERVER_URL}/api/v1/repos/{GITHUB_REPOSITORY}/releases/{release_id}/assets' + files = { + 'attachment': (zip_name, open(zip_name, 'rb')) + } + + response = requests.post(attachment_url, headers=headers, files=files) + + if response.ok: + print("Attachment uploaded successfully.") + else: + print("Failed to upload attachment:", response.text) +else: + print("Failed to create release:", response.text)