This commit is contained in:
2023-11-09 21:27:31 +01:00
commit b1490f8516
2 changed files with 107 additions and 0 deletions
+49
View File
@@ -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'
+58
View File
@@ -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)