Merge pull request #35 from codeboxrcodehub/dev #48
This file contains hidden or 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: | |
| tags: | |
| - '*.*.*' | |
| branches: | |
| - master | |
| jobs: | |
| create_release: | |
| if: github.ref == 'refs/heads/master' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 | |
| - name: Find Readme File | |
| id: find_readme | |
| run: | | |
| for file in README.txt README.md Readme.txt Readme.md readme.txt readme.md; do | |
| if [ -f "$file" ]; then | |
| echo "Readme file found: $file" | |
| echo "readme_file=$file" >> $GITHUB_ENV | |
| break | |
| fi | |
| done | |
| # Ensure the variable is available within the current step | |
| source $GITHUB_ENV | |
| if [ -z "$readme_file" ]; then | |
| echo "::error::Readme file not found." | |
| exit 1 | |
| fi | |
| - name: Extract Release Notes | |
| id: release_notes | |
| run: | | |
| changelog_section_start="== Changelog ==" | |
| readme_file="$readme_file" | |
| plugin_version="${{ github.ref_name }}" # Assuming the tag is the version | |
| in_changelog=0 | |
| found_version=0 | |
| release_notes="" | |
| while IFS= read -r line; do | |
| # Start processing after the changelog header | |
| if [[ "$line" == "$changelog_section_start" ]]; then | |
| in_changelog=1 | |
| continue | |
| fi | |
| # Skip if not in changelog section | |
| if [[ $in_changelog -eq 0 ]]; then | |
| continue | |
| fi | |
| # Check for the current version header | |
| if [[ "$line" == "= ${plugin_version} =" ]]; then | |
| found_version=1 | |
| continue | |
| fi | |
| # Stop when another version header is encountered | |
| if [[ $found_version -eq 1 && "$line" =~ ^=.+=$ ]]; then | |
| break | |
| fi | |
| # Collect lines starting with '*' if we are in the current version section | |
| if [[ $found_version -eq 1 && "$line" =~ ^\* ]]; then | |
| release_notes+="${line}\n" | |
| fi | |
| done < "$readme_file" | |
| if [[ -z "$release_notes" ]]; then | |
| echo "::error::Failed to extract release notes for version ${plugin_version}." | |
| exit 1 | |
| fi | |
| # Write the release notes with actual line breaks | |
| echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV | |
| echo -e "$release_notes" >> $GITHUB_ENV | |
| echo "EOF" >> $GITHUB_ENV | |
| - name: Create zip file | |
| run: | | |
| REPO_NAME=$(basename `git rev-parse --show-toplevel`) | |
| zip -r ${REPO_NAME}.zip . -x '*.git*' -x '.github/*' -x '*.distignore*' -x 'CHANGELOG.txt' | |
| echo "repo_name=${REPO_NAME}" >> $GITHUB_ENV | |
| # Source to make repo_name available in subsequent steps | |
| source $GITHUB_ENV | |
| - name: Create Release | |
| id: create_release | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: ${{ github.ref_name }} | |
| release_name: "${{ github.ref_name }}" | |
| body: ${{ env.RELEASE_NOTES }} | |
| draft: false | |
| prerelease: false | |
| - name: Upload Release Asset | |
| uses: actions/upload-release-asset@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| upload_url: ${{ steps.create_release.outputs.upload_url }} | |
| asset_path: ./${{ env.repo_name }}.zip | |
| asset_name: ${{ env.repo_name }}.zip | |
| asset_content_type: application/zip |