Create Release on Push or Manual Trigger #6
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
name: Create Release on Push or Manual Trigger | |
on: | |
push: | |
branches: | |
- master | |
paths: | |
- 'bin/Release/**' # Only run the workflow when files in this path are pushed | |
workflow_dispatch: | |
env: | |
REPO_NAME: ${{ github.event.repository.name }} | |
jobs: | |
create-release: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up GitHub CLI | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y gh | |
- name: Find setup file and extract version | |
id: get_version | |
run: | | |
SETUP_FILE=$(ls ./bin/Release/${{ env.REPO_NAME }}_setup-*.exe | tail -n 1) | |
if [ -z "$SETUP_FILE" ]; then | |
echo "Setup file not found!" | |
exit 1 | |
fi | |
VERSION=$(basename "$SETUP_FILE" | sed -E "s/${{ env.REPO_NAME }}_setup-(.*)\.exe/\1/") | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
echo "Setup file is: $SETUP_FILE" | |
echo "Version extracted: $VERSION" | |
- name: Delete existing tag | |
run: | | |
git tag -d ${{ env.VERSION }} || true | |
git push --delete origin ${{ env.VERSION }} || true | |
env: | |
VERSION: ${{ env.VERSION }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Delete existing release | |
run: | | |
gh release delete ${{ env.VERSION }} -y || true | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
VERSION: ${{ env.VERSION }} | |
- name: Read README.md | |
id: read_readme | |
run: | | |
# Read the README.md file and store its content in an environment variable | |
echo "README_CONTENT<<EOF" >> $GITHUB_ENV | |
cat README.md >> $GITHUB_ENV | |
echo "EOF" >> $GITHUB_ENV | |
- name: Capture commit message | |
id: capture_commit_message | |
if: github.event_name == 'push' | |
run: echo "COMMIT_MESSAGE=$(git log -1 --pretty=%B)" >> $GITHUB_ENV | |
- name: Create release | |
id: create_release | |
uses: actions/create-release@v1 | |
with: | |
tag_name: ${{ env.VERSION }} | |
release_name: Release ${{ env.VERSION }} | |
draft: false | |
prerelease: false | |
body: | | |
${{ github.event_name == 'push' && env.COMMIT_MESSAGE || 'Automatic release' }} | |
${{ env.README_CONTENT }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Upload <reponame>.exe | |
uses: actions/upload-release-asset@v1 | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./bin/Release/${{ env.REPO_NAME }}.exe | |
asset_name: ${{ env.REPO_NAME }}.exe | |
asset_content_type: application/octet-stream | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Upload <reponame>_setup-<version>.exe | |
uses: actions/upload-release-asset@v1 | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./bin/Release/${{ env.REPO_NAME }}_setup-${{ env.VERSION }}.exe | |
asset_name: ${{ env.REPO_NAME }}_setup-${{ env.VERSION }}.exe | |
asset_content_type: application/octet-stream | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |