|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + |
| 8 | +jobs: |
| 9 | + release: |
| 10 | + name: Create Release |
| 11 | + runs-on: ubuntu-latest |
| 12 | + permissions: |
| 13 | + contents: write |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout code |
| 17 | + uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + fetch-depth: 0 # Full history for changelog generation |
| 20 | + |
| 21 | + - name: Get version from tag |
| 22 | + id: get_version |
| 23 | + run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT |
| 24 | + |
| 25 | + - name: Get previous tag |
| 26 | + id: prev_tag |
| 27 | + run: | |
| 28 | + PREV_TAG=$(git tag --sort=-creatordate | sed -n '2p') |
| 29 | + echo "PREV_TAG=${PREV_TAG}" >> $GITHUB_OUTPUT |
| 30 | + echo "Previous tag: ${PREV_TAG}" |
| 31 | +
|
| 32 | + - name: Generate release notes |
| 33 | + id: release_notes |
| 34 | + run: | |
| 35 | + VERSION="${{ steps.get_version.outputs.VERSION }}" |
| 36 | + PREV_TAG="${{ steps.prev_tag.outputs.PREV_TAG }}" |
| 37 | +
|
| 38 | + # Start building release notes |
| 39 | + cat > release_notes.md << 'HEADER' |
| 40 | + ## What's Changed |
| 41 | + HEADER |
| 42 | +
|
| 43 | + # Try CHANGELOG.md first for curated notes |
| 44 | + if [ -f "CHANGELOG.md" ]; then |
| 45 | + CHANGELOG_SECTION=$(awk "/^## \[${VERSION}\]/{found=1; next} /^## \[/{found=0} found" CHANGELOG.md) |
| 46 | + if [ -n "$CHANGELOG_SECTION" ]; then |
| 47 | + echo "" >> release_notes.md |
| 48 | + echo "$CHANGELOG_SECTION" >> release_notes.md |
| 49 | + echo "" >> release_notes.md |
| 50 | + fi |
| 51 | + fi |
| 52 | +
|
| 53 | + # Generate commit log between tags |
| 54 | + if [ -n "$PREV_TAG" ]; then |
| 55 | + echo "### Commits" >> release_notes.md |
| 56 | + echo "" >> release_notes.md |
| 57 | + git log ${PREV_TAG}..HEAD --pretty=format:"- %s (\`%h\`)" --no-merges >> release_notes.md |
| 58 | + echo "" >> release_notes.md |
| 59 | + echo "" >> release_notes.md |
| 60 | +
|
| 61 | + # Stats |
| 62 | + COMMIT_COUNT=$(git rev-list ${PREV_TAG}..HEAD --count --no-merges) |
| 63 | + FILES_CHANGED=$(git diff ${PREV_TAG}..HEAD --stat | tail -1) |
| 64 | + echo "### Stats" >> release_notes.md |
| 65 | + echo "" >> release_notes.md |
| 66 | + echo "- **Commits:** ${COMMIT_COUNT}" >> release_notes.md |
| 67 | + echo "- **Changes:** ${FILES_CHANGED}" >> release_notes.md |
| 68 | + echo "" >> release_notes.md |
| 69 | + fi |
| 70 | +
|
| 71 | + # Plugin info |
| 72 | + PHP_VERSION=$(grep "Requires PHP" functionalities.php | grep -oP '[\d.]+') |
| 73 | + WP_VERSION=$(grep "Requires at least" functionalities.php | grep -oP '[\d.]+') |
| 74 | +
|
| 75 | + echo "### Plugin Info" >> release_notes.md |
| 76 | + echo "" >> release_notes.md |
| 77 | + echo "- **Requires WordPress:** ${WP_VERSION}+" >> release_notes.md |
| 78 | + echo "- **Requires PHP:** ${PHP_VERSION}+" >> release_notes.md |
| 79 | + echo "" >> release_notes.md |
| 80 | +
|
| 81 | + # Install instructions |
| 82 | + cat >> release_notes.md << 'INSTALL' |
| 83 | + ### Installation |
| 84 | +
|
| 85 | + 1. Download `functionalities-pro-*.zip` from the assets below |
| 86 | + 2. Go to **Plugins → Add New → Upload Plugin** in WordPress admin |
| 87 | + 3. Upload the zip file and activate |
| 88 | + INSTALL |
| 89 | +
|
| 90 | + echo "Release notes generated:" |
| 91 | + cat release_notes.md |
| 92 | +
|
| 93 | + - name: Create plugin zip |
| 94 | + run: | |
| 95 | + mkdir -p build/functionalities-pro |
| 96 | +
|
| 97 | + rsync -av \ |
| 98 | + --exclude='.*' \ |
| 99 | + --exclude='build' \ |
| 100 | + --exclude='node_modules' \ |
| 101 | + --exclude='*.log' \ |
| 102 | + --exclude='package-lock.json' \ |
| 103 | + --exclude='composer.lock' \ |
| 104 | + --exclude='release_notes.md' \ |
| 105 | + ./ build/functionalities-pro/ |
| 106 | +
|
| 107 | + cd build |
| 108 | + zip -r functionalities-pro-${{ steps.get_version.outputs.VERSION }}.zip functionalities-pro |
| 109 | + mv functionalities-pro-${{ steps.get_version.outputs.VERSION }}.zip ../ |
| 110 | +
|
| 111 | + - name: Create GitHub Release |
| 112 | + uses: softprops/action-gh-release@v2 |
| 113 | + with: |
| 114 | + name: Functionalities Pro v${{ steps.get_version.outputs.VERSION }} |
| 115 | + body_path: release_notes.md |
| 116 | + draft: false |
| 117 | + prerelease: false |
| 118 | + files: functionalities-pro-${{ steps.get_version.outputs.VERSION }}.zip |
| 119 | + env: |
| 120 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments