Skip to content

readme file adjust

readme file adjust #6

Workflow file for this run

name: Deploy to GitHub
on:
push:
branches:
- master
tags:
- "*"
jobs:
tag:
name: Prepare Release
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get latest commit SHA
id: sha
if: github.ref == 'refs/heads/master'
run: echo "::set-output name=sha::$(git rev-parse HEAD)"
- name: Create Tag (if needed)
id: create_tag
if: github.ref == 'refs/heads/master' && !startsWith(github.event.head_commit.message, 'Merge pull request')
run: |
TAG_NAME="v$(date +%Y%m%d%H%M%S)-${{ steps.sha.outputs.sha }}"
git config --global user.name 'GitHub Actions'
git config --global user.email '[email protected]'
git tag -a "$TAG_NAME" -m "Release from master ${{ steps.sha.outputs.sha }}"
git push origin --tags
echo "::set-output name=tag::$TAG_NAME"
- name: Extract Release Notes
id: release_notes
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/'))
run: |
changelog_section_start="== Changelog =="
current_tag="${{ steps.create_tag.outputs.tag || github.ref_name }}"
readme_file="readme.txt" # Directly set the filename
if [ ! -f "$readme_file" ]; then # Check if the file exists
echo "::error::Readme file not found: $readme_file"
exit 1
fi
echo "Readme file: $readme_file"
version=${current_tag#refs/tags/}
in_changelog=0
capturing_version=0
release_notes=""
while IFS= read -r line; do
if [[ "$line" == "$changelog_section_start" ]]; then
in_changelog=1
continue
fi
if [[ $in_changelog -eq 0 ]]; then
continue
fi
if [[ "$line" =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then
capturing_version=1
if [[ "$line" == "$version" ]]; then
release_notes+="$line\n"
fi
continue
fi
if [[ $capturing_version -eq 1 && "$line" =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then
break
fi
if [[ $capturing_version -eq 1 ]]; then
release_notes+="$line\n"
fi
done < "$readme_file"
if [[ -z "$release_notes" ]]; then
echo "::error::Failed to extract release notes for version $version."
exit 1
fi
echo "Extracted release notes for version $version:"
printf "%b" "$release_notes"
echo "::set-output name=notes::$(printf "%b" "$release_notes")"
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/'))
with:
tag_name: ${{ steps.create_tag.outputs.tag || github.ref_name }}
body: ${{ steps.release_notes.outputs.notes }}
files: ${{github.workspace}}/${{ github.event.repository.name }}.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}