-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
776ea71
commit 9060abe
Showing
2 changed files
with
91 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
on: | ||
push: | ||
tags: | ||
- "v[0-9]+.[0-9]+.[0-9]+" | ||
workflow_dispatch: | ||
inputs: | ||
tag: | ||
description: "Tag of the release - should be in v[0-9]+.[0-9]+.[0.9]+" | ||
required: True | ||
|
||
jobs: | ||
create-release: | ||
|
@@ -11,26 +13,37 @@ jobs: | |
- name: Create artifacts directory | ||
run: mkdir artifacts | ||
|
||
- name: Get the release version from the tag | ||
if: env.VERSION == '' | ||
run: | | ||
echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV | ||
echo "version is: ${{ env.VERSION }}" | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.x' | ||
|
||
- name: Install dependancies | ||
run: | | ||
pip install requests | ||
pip install GitPython | ||
- name: Generate body | ||
env: | ||
TAG: ${{ github.event.inputs.tag }} | ||
run: | | ||
python release.py | ||
- name: Create GitHub release | ||
id: release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: ${{ env.VERSION }} | ||
release_name: ${{ env.VERSION }} | ||
tag_name: ${{ github.event.inputs.tag }} | ||
release_name: ${{ github.event.inputs.tag }} | ||
body_path: ./body | ||
|
||
- name: Save release upload URL to artifact | ||
run: echo "${{ steps.release.outputs.upload_url }}" > artifacts/release-upload-url | ||
|
||
- name: Save version number to artifact | ||
run: echo "${{ env.VERSION }}" > artifacts/release-version | ||
run: echo "${{ github.event.inputs.tag }}" > artifacts/release-version | ||
|
||
- name: Upload artifacts | ||
uses: actions/upload-artifact@v1 | ||
|
@@ -115,10 +128,10 @@ jobs: | |
run: | | ||
if [ "${{ matrix.build }}" = "windows" ]; then | ||
echo "ASSET=target/${{ matrix.target }}/release/ntfs-undelete.exe" >> $GITHUB_ENV | ||
echo "ASSET_NAME=ntfs-undelete-${{ env.RELEASE_VERSION }}.exe" >> $GITHUB_ENV | ||
echo "ASSET_NAME=ntfs-undelete-${{ github.event.inputs.tag }}.exe" >> $GITHUB_ENV | ||
else | ||
echo "ASSET=target/${{ matrix.target }}/release/ntfs-undelete" >> $GITHUB_ENV | ||
echo "ASSET_NAME=ntfs-undelete-${{ env.RELEASE_VERSION }}-${{ matrix.target }}" >> $GITHUB_ENV | ||
echo "ASSET_NAME=ntfs-undelete-${{ github.event.inputs.tag }}-${{ matrix.target }}" >> $GITHUB_ENV | ||
fi | ||
- name: Upload release archive | ||
uses: actions/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import git | ||
import requests | ||
import os | ||
|
||
def get_github_releases(repo_owner='NikolaMilosa', repo_name='ntfs-undelete', github_token=None): | ||
# GitHub API endpoint for releases | ||
url = f'https://api.github.com/repos/{repo_owner}/{repo_name}/releases' | ||
|
||
headers = {} | ||
if github_token: | ||
headers['Authorization'] = f'Bearer {github_token}' | ||
|
||
# Make a request to the GitHub API | ||
response = requests.get(url, headers=headers) | ||
|
||
# Check if the request was successful (status code 200) | ||
if response.status_code == 200: | ||
releases = response.json() | ||
return releases | ||
else: | ||
# Print an error message if the request was not successful | ||
return None | ||
|
||
def get_commits_since_tag(repo_path='.', tag_name=None): | ||
repo = git.Repo(repo_path) | ||
|
||
if tag_name: | ||
# If tag_name is provided, get the commit associated with the tag | ||
try: | ||
commit = repo.commit(tag_name) | ||
except git.exc.GitCommandError: | ||
return None | ||
else: | ||
# If tag_name is None, get the latest commit | ||
commit = repo.head.commit | ||
|
||
# Get all commits from the specified commit until the latest commit | ||
commits = list(repo.iter_commits(commit, max_count=repo.git.rev_list('HEAD', count=True), reverse=True)) | ||
|
||
return commits | ||
|
||
commit_prefix = 'https://github.com/NikolaMilosa/ntfs-undelete/commit/' | ||
author_prefix = 'https://github.com/' | ||
|
||
github_token = os.environ['GITHUB_TOKEN'] | ||
current_tag = os.environ['TAG'] | ||
|
||
releases = get_github_releases() | ||
tag_name = None | ||
if len(releases) != 0: | ||
tag_name = sorted(releases, lambda x: x['created_at'])[-1]['tag_name'] | ||
|
||
release_text = f""" | ||
# Release {current_tag} | ||
### Changelog: | ||
""" | ||
|
||
commits = get_commits_since_tag(tag_name=tag_name) | ||
for commit in reversed(commits): | ||
username = commit.author.email.split('+')[1].split('@')[0] | ||
release_text += f"* [{commit.hexsha[:7]}]({commit_prefix}{commit.hexsha}) [Author: [{username}]({author_prefix}{username})] - {commit.message.splitlines()[0]}\n" | ||
|
||
with open('body', 'w') as f: | ||
f.write(release_text) |