Skip to content

Commit deff875

Browse files
authored
Merge pull request #15 from codeboxrcodehub/dev
Version 1.0.9 released
2 parents 7ab7020 + dfb71ee commit deff875

File tree

2 files changed

+57
-105
lines changed

2 files changed

+57
-105
lines changed

.github/workflows/deploy.yml

Lines changed: 56 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,65 @@
1-
name: Deploy to GitHub
1+
name: Create Release
22

33
on:
44
push:
5-
branches:
6-
- master
75
tags:
8-
- "*"
6+
- '*.*.*' # Triggers on tags like 1.0.0
7+
branches:
8+
- master # Ensures it only runs on the master branch
99

1010
jobs:
11-
tag:
12-
name: Prepare Release
11+
create_release:
12+
if: github.ref == 'refs/heads/master' # Ensures the job runs only on master branch
1313
runs-on: ubuntu-latest
14-
if: github.event_name == 'push' # Only run on push events
1514

1615
steps:
17-
- uses: actions/checkout@v3
18-
with:
19-
fetch-depth: 0 # Important: Fetch all history for tags
20-
21-
- name: Get latest commit SHA
22-
id: sha
23-
if: github.ref == 'refs/heads/master' # Only when pushing to master
24-
run: echo "::set-output name=sha::$(git rev-parse HEAD)"
25-
26-
- name: Create Tag (if needed)
27-
id: create_tag
28-
if: github.ref == 'refs/heads/master' && !startsWith(github.event.head_commit.message, 'Merge pull request') #Only on direct pushes to master, not merge commits
29-
run: |
30-
TAG_NAME="v$(date +%Y%m%d%H%M%S)-${{ steps.sha.outputs.sha }}"
31-
git config --global user.name 'GitHub Actions'
32-
git config --global user.email 'actions@github.com'
33-
git tag -a "$TAG_NAME" -m "Release from master ${{ steps.sha.outputs.sha }}"
34-
git push origin --tags
35-
echo "::set-output name=tag::$TAG_NAME"
36-
37-
- name: Extract Release Notes
38-
id: release_notes
39-
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/'))
40-
run: |
41-
# Define variables
42-
changelog_section_start="== Changelog =="
43-
current_tag="${{ steps.create_tag.outputs.tag || github.ref_name }}" # Use created tag or existing tag
44-
readme_file=$(find . -type f -iname "readme.*" | head -n 1)
45-
46-
if [ -z "$readme_file" ]; then
47-
echo "::error::Readme file not found."
48-
exit 1
49-
fi
50-
echo "Readme file: $readme_file"
51-
52-
# Extract version from tag
53-
version=${current_tag#refs/tags/}
54-
55-
# Initialize variables
56-
in_changelog=0
57-
capturing_version=0
58-
release_notes=""
59-
60-
while IFS= read -r line; do
61-
# Start capturing after finding the changelog section
62-
if [[ "$line" == "$changelog_section_start" ]]; then
63-
in_changelog=1
64-
continue
65-
fi
66-
67-
# Skip lines before the changelog section
68-
if [[ $in_changelog -eq 0 ]]; then
69-
continue
70-
fi
71-
72-
# Start capturing if the line starts with a version number (semver format)
73-
if [[ "$line" =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then
74-
capturing_version=1
75-
# Check if the captured version matches the current tag
76-
if [[ "$line" == "$version" ]]; then
77-
release_notes+="$line\n"
78-
fi
79-
continue
80-
fi
81-
82-
# Stop capturing when a new version section is detected
83-
if [[ $capturing_version -eq 1 && "$line" =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then
84-
break
85-
fi
86-
87-
# Add the line to the release notes if capturing the current version
88-
if [[ $capturing_version -eq 1 ]]; then
89-
release_notes+="$line\n"
90-
fi
91-
done < "$readme_file"
92-
93-
# Check if release notes were extracted
94-
if [[ -z "$release_notes" ]]; then
95-
echo "::error::Failed to extract release notes for version $version."
96-
exit 1
97-
fi
98-
99-
# Debug: Print extracted release notes
100-
echo "Extracted release notes for version $version:"
101-
printf "%b" "$release_notes"
102-
103-
# Set output for release notes
104-
echo "::set-output name=notes::$(printf "%b" "$release_notes")"
105-
106-
- name: Create GitHub Release
107-
uses: softprops/action-gh-release@v2
108-
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/'))
109-
with:
110-
tag_name: ${{ steps.create_tag.outputs.tag || github.ref_name }}
111-
body: ${{ steps.release_notes.outputs.notes }}
112-
files: ${{github.workspace}}/${{ github.event.repository.name }}.zip
113-
env:
114-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16+
- name: Checkout repository
17+
uses: actions/checkout@v2
18+
19+
- name: Read version from readme.txt
20+
id: read_version
21+
run: |
22+
VERSION=$(grep -Eo 'Stable tag: [0-9]+\.[0-9]+\.[0-9]+' readme.txt | awk '{print $3}')
23+
echo "plugin_version=$VERSION" >> $GITHUB_ENV
24+
25+
- name: Get latest tag
26+
id: get_latest_tag
27+
run: |
28+
LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
29+
echo "latest_tag=$LATEST_TAG" >> $GITHUB_ENV
30+
31+
- name: Extract Changelog
32+
id: extract_changelog
33+
run: |
34+
START_LINE=$(grep -n "== Changelog ==" readme.txt | cut -d : -f 1)
35+
END_LINE=$(grep -n "= ${{ env.plugin_version }} =" readme.txt | cut -d : -f 1)
36+
sed -n "${START_LINE},${END_LINE}p" readme.txt | sed '1d;$d' > CHANGELOG.txt
37+
echo "changelog=$(cat CHANGELOG.txt)" >> $GITHUB_ENV
38+
39+
- name: Create zip file
40+
run: |
41+
REPO_NAME=$(basename `git rev-parse --show-toplevel`)
42+
zip -r ${REPO_NAME}.zip . -x '*.git*' -x '*.github*' -x '*.distignore*'
43+
echo "repo_name=${REPO_NAME}" >> $GITHUB_ENV
44+
45+
- name: Create Release
46+
id: create_release
47+
uses: actions/create-release@v1
48+
env:
49+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50+
with:
51+
tag_name: ${{ env.latest_tag }}
52+
release_name: "Release ${{ env.plugin_version }}"
53+
body: ${{ env.changelog }}
54+
draft: false
55+
prerelease: false
56+
57+
- name: Upload Release Asset
58+
uses: actions/upload-release-asset@v1
59+
env:
60+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
with:
62+
upload_url: ${{ steps.create_release.outputs.upload_url }}
63+
asset_path: ./${{ env.repo_name }}.zip
64+
asset_name: ${{ env.repo_name }}.zip
65+
asset_content_type: application/zip

README.txt renamed to readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ if ( defined('CBXPHPSPREADSHEET_PLUGIN_NAME') && cbxphpspreadsheet_loadable() )
5252

5353

5454
== Changelog ==
55+
5556
= 1.0.9 =
5657
* Fixed function 'php_version_check'
5758

0 commit comments

Comments
 (0)