Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 156 additions & 0 deletions .github/workflows/build-and-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
---
name: Build and Release
on: workflow_dispatch
jobs:
build:
name: Build and Commit
runs-on: ubuntu-20.04
steps:
- name: Checkout the specific branch/ref
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
fetch-depth: 0

- name: Fetch and checkout built branch
run: |
if git ls-remote --exit-code origin built; then
git fetch origin built
git checkout built
git pull origin built
else
git checkout -b built develop
fi

- name: Configure Git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
Comment on lines +25 to +28
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set Git configuration locally.

Consider setting Git configuration locally for this repository instead of globally, to avoid affecting other workflows.

-  git config --global user.name 'github-actions[bot]'
-  git config --global user.email 'github-actions[bot]@users.noreply.github.com'
+  git config user.name 'github-actions[bot]'
+  git config user.email 'github-actions[bot]@users.noreply.github.com'
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Configure Git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Configure Git
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'


- name: Merge current branch into built
run: |
git merge --squash $GITHUB_SHA
git commit -m "Merge $GITHUB_SHA into built" --no-verify

- name: Read .nvmrc
run: echo "NODE_VERSION=$(cat .nvmrc)" >> $GITHUB_ENV

- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4.0.2
with:
node-version: ${{ env.NODE_VERSION }}
cache: npm

- name: Build
run: |
npm ci
npm run build
composer install --no-dev --optimize-autoloader --classmap-authoritative

- name: Get list of changed files
run: |
git status -s

- name: Commit built files
run: |
git add -Af vendor/
git status -s
VERSION=$(jq -r .version < package.json)
git commit -m "Build plugin v$VERSION (${{ github.ref_name }})" --no-verify
git push origin built

tag_and_release:
name: Tag and Release
needs: build
runs-on: ubuntu-20.04
outputs:
VERSION: ${{ steps.get_version.outputs.VERSION }}
steps:
- uses: actions/checkout@v4
with:
ref: built
fetch-depth: 0

- name: Get version from package.json
id: get_version
run: |
VERSION=$(jq -r .version < package.json)
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "The version is $VERSION"

- name: Tag the commit
run: |
git tag ${{ env.VERSION }}
git push origin ${{ env.VERSION }}

- name: Extract Changelog
id: extract_changelog
run: |
set -e
VERSION=${{ env.VERSION }}
START_LINE=$(grep -n "## \[${VERSION}\]" CHANGELOG.md | cut -d: -f1)
if [ -z "$START_LINE" ]; then
echo "Version not found in CHANGELOG.md" >&2
exit 1
fi
TAIL_LINE=$(tail -n +$((START_LINE + 1)) CHANGELOG.md | grep -n "^## " | head -n 1 | cut -d: -f1 || true)
if [ -z "$TAIL_LINE" ]; then
END_LINE=$(wc -l < CHANGELOG.md)
else
END_LINE=$((START_LINE + TAIL_LINE - 1))
fi
sed -n "${START_LINE},${END_LINE}p" CHANGELOG.md | sed '$d' > release_notes.md
cat release_notes.md
shell: bash

- name: Format Changelog
id: format_changelog
run: |
sed -i '1d' release_notes.md # Remove the first line
sed -i 's/###/##/g' release_notes.md # Change headers from ### to ##
shell: bash

- name: Create a GitHub release
id: github_release
uses: ncipollo/release-action@v1
with:
tag: ${{ env.VERSION }}
name: ${{ env.VERSION }}
bodyFile: ./release_notes.md
draft: true
prerelease: false

deploy:
name: Deploy to WordPress.org
needs: tag_and_release
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.tag_and_release.outputs.VERSION }}

- name: WordPress Plugin Deploy
id: wporg_deploy
uses: 10up/action-wordpress-plugin-deploy@stable
with:
dry-run: false
generate-zip: true
env:
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
VERSION: ${{ needs.tag_and_release.outputs.VERSION }}

- name: Update release with ZIP file
uses: ncipollo/release-action@v1
with:
tag: ${{ needs.tag_and_release.outputs.VERSION }}
allowUpdates: true
omitBodyDuringUpdate: true
omitNameDuringUpdate: true
omitDraftDuringUpdate: true
omitPrereleaseDuringUpdate: true
removeArtifacts: true
updateOnlyUnreleased: true
artifacts: ${{ steps.wporg_deploy.outputs.zip-path }}
artifactContentType: application/zip