Offload WordPress Static files #594
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: Offload WordPress Static files | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Custom Wordpress Version' | |
| required: false | |
| schedule: | |
| - cron: '0 */3 * * *' | |
| permissions: | |
| contents: write | |
| pages: write | |
| id-token: write | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Get latest WordPress version & check release | |
| id: get_version | |
| run: | | |
| if [ -z "${{ github.event.inputs.version }}" ]; then | |
| VERSION=$(curl -s https://api.wordpress.org/core/version-check/1.7/ | jq -r '.offers[0].current') | |
| else | |
| VERSION='${{ github.event.inputs.version }}' | |
| fi | |
| echo "VERSION=$VERSION" >> $GITHUB_ENV | |
| echo "Latest WordPress version: $VERSION" | |
| if gh release view "v${VERSION}" >/dev/null 2>&1; then | |
| echo "✅ Release v${VERSION} already exists. Skipping build." | |
| exit 0 | |
| fi | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Download WordPress | |
| run: | | |
| curl -LO https://wordpress.org/wordpress-${VERSION}.zip | |
| unzip -q wordpress-${VERSION}.zip | |
| rm wordpress-${VERSION}.zip | |
| - name: Remove unnecessary files | |
| run: | | |
| find wordpress -type f -name "*.php" -delete | |
| rm -rf wordpress/license.txt wordpress/readme.html | |
| rm -rf wordpress/wp-content | |
| - name: Move static files into versioned folder | |
| run: | | |
| rsync -a wordpress/ ./${VERSION} | |
| echo "{ \"version\": \"${VERSION}\" }" > ./${VERSION}/wp-version.json | |
| if [ -z "${{ github.event.inputs.version }}" ]; then | |
| echo "{ \"version\": \"${VERSION}\" }" > wp-version.json | |
| fi | |
| rm -rf wordpress | |
| - name: Commit changes (if any) | |
| run: | | |
| git config --global user.name "STICKnoLOGIC[bot]" | |
| git config --global user.email "[email protected]" | |
| git add -A | |
| git commit -m "Add WP static assets v${VERSION}" || echo "No changes to commit" | |
| git push || true | |
| - name: Create release archive | |
| run: | | |
| zip -r wordpress-static-${VERSION}.zip wp-includes wp-admin | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: "v${{ env.VERSION }}" | |
| name: "WordPress Static v${{ env.VERSION }}" | |
| body: "Auto-generated static build of WordPress core assets for version ${{ env.VERSION }}." | |
| files: wordpress-static-${{ env.VERSION }}.zip | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |