-
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.
Merge pull request #2 from renxida/new-architecture
GitHub Actions for Automated Nightly and Official Releases
- Loading branch information
Showing
3 changed files
with
87 additions
and
45 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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# File: .github/workflows/nightly-release.yml | ||
|
||
name: Nightly Release | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
create-nightly: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.x' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install semver | ||
- name: Determine nightly version | ||
id: version | ||
run: | | ||
current_version=$(python -c " | ||
import re | ||
with open('uniclip/__init__.py', 'r') as f: | ||
content = f.read() | ||
match = re.search(r\"__version__\s*=\s*['\\\"]([^'\\\"]*)['\\\"]\", content) | ||
if match: | ||
print(match.group(1)) | ||
else: | ||
print('0.0.0') # fallback version | ||
") | ||
nightly_version=$(python -c "import semver; v = semver.VersionInfo.parse('$current_version'); print(f'{v.major}.{v.minor}.{v.patch}-nightly.{github.run_number}')") | ||
echo "nightly_version=$nightly_version" >> "$GITHUB_OUTPUT" | ||
- name: Create Nightly Release | ||
id: create_release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: nightly-v${{ steps.version.outputs.nightly_version }} | ||
release_name: Nightly Release ${{ steps.version.outputs.nightly_version }} | ||
draft: false | ||
prerelease: true |
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
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,86 +1,73 @@ | ||
name: Release | ||
# File: .github/workflows/release.yml | ||
|
||
name: Official Release | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
release_type: | ||
type: choice | ||
description: 'Type of release' | ||
required: true | ||
options: | ||
- patch | ||
- minor | ||
- major | ||
workflow_dispatch: # This allows manual triggering without inputs | ||
|
||
jobs: | ||
release: | ||
official-release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.x' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install semver | ||
- name: Determine new version | ||
- name: Get latest nightly release | ||
id: latest_nightly | ||
run: | | ||
latest_nightly=$(git describe --tags --match "nightly-v*" --abbrev=0) | ||
echo "latest_nightly=$latest_nightly" >> "$GITHUB_OUTPUT" | ||
- name: Determine official version | ||
id: version | ||
run: | | ||
current_version=$(python -c " | ||
import re | ||
with open('uniclip/__init__.py', 'r') as f: | ||
content = f.read() | ||
match = re.search(r\"__version__\s*=\s*['\\\"]([^'\\\"]*)['\\\"]\", content) | ||
if match: | ||
print(match.group(1)) | ||
else: | ||
print('0.0.0') # fallback version | ||
") | ||
new_version=$(python -c "import semver; print(str(semver.VersionInfo.parse('$current_version').bump_${{ github.event.inputs.release_type }}()))") | ||
echo "Current version: $current_version" | ||
echo "New version will be: $new_version" | ||
echo "new_version=$new_version" >> "$GITHUB_OUTPUT" | ||
nightly_version="${{ steps.latest_nightly.outputs.latest_nightly }}" | ||
official_version=$(echo $nightly_version | sed 's/nightly-v//' | sed 's/-nightly\..*//') | ||
echo "official_version=$official_version" >> "$GITHUB_OUTPUT" | ||
- name: Update version | ||
run: | | ||
sed -i "s/__version__\s*=\s*['\"].*['\"]/__version__ = '${{ steps.version.outputs.new_version }}'/" uniclip/__init__.py | ||
sed -i "s/__version__\s*=\s*['\"].*['\"]/__version__ = '${{ steps.version.outputs.official_version }}'/" uniclip/__init__.py | ||
- name: Commit version update | ||
run: | | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "GitHub Action" | ||
git add uniclip/__init__.py | ||
git commit -m "Bump ${{ github.event.inputs.release_type }} version to ${{ steps.version.outputs.new_version }}" | ||
git commit -m "Bump version to ${{ steps.version.outputs.official_version }}" | ||
- name: Push changes | ||
uses: ad-m/github-push-action@master | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
branch: ${{ github.ref }} | ||
- name: Create Release | ||
|
||
- name: Create Official Release | ||
id: create_release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: v${{ steps.version.outputs.new_version }} | ||
release_name: Release ${{ steps.version.outputs.new_version }} | ||
tag_name: v${{ steps.version.outputs.official_version }} | ||
release_name: Release ${{ steps.version.outputs.official_version }} | ||
draft: false | ||
prerelease: false | ||
|
||
- name: Update README | ||
run: | | ||
sed -i "s/Current version: .*/Current version: ${{ steps.version.outputs.new_version }}/" README.md | ||
sed -i "s/Current version: .*/Current version: ${{ steps.version.outputs.official_version }}/" README.md | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "GitHub Action" | ||
git add README.md | ||
git commit -m "Update version in README to ${{ steps.version.outputs.new_version }}" | ||
git push | ||
git commit -m "Update version in README to ${{ steps.version.outputs.official_version }}" | ||
git push |