-
Notifications
You must be signed in to change notification settings - Fork 33
Add GitHub Action for Build and Release #2693
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1b12b90
5900790
5e9e8ff
913b3e6
3b29a53
7e9cbe5
8ecf783
c75f1dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
| - 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 | ||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.