Skip to content

Commit

Permalink
Update standalone plugins workflow to only deploy if not deployed alr…
Browse files Browse the repository at this point in the history
…eady
  • Loading branch information
thelovekesh committed Mar 18, 2024
1 parent bb98c66 commit 0d5451d
Showing 1 changed file with 49 additions and 2 deletions.
51 changes: 49 additions & 2 deletions .github/workflows/deploy-standalone-plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
fi
# Set the matrix.
echo "::notice::Deploying the following plugins: $PLUGINS"
echo "::notice::Deploying the following plugins: $(echo ${PLUGINS[@]})"
echo "plugins=$(echo $PLUGINS | jq -c .)" >> $GITHUB_OUTPUT
deploy:
Expand Down Expand Up @@ -77,13 +77,36 @@ jobs:
run: |
echo "PLUGIN_VERSION=$(jq -r '."${{ matrix.plugin }}"' manifest.json)" >> $GITHUB_ENV
- name: Check if deployment is needed
id: check-deployment
run: |
PLUGIN_VERSION_WPORG=$(curl -sSL https://api.wordpress.org/plugins/info/1.0/${{ matrix.plugin }}.json --retry 3 --retry-delay 5 --retry-all-errors --fail | jq -r '.version')
echo "::debug::The ${{ matrix.plugin }} plugin is currently at version $PLUGIN_VERSION_WPORG on WordPress.org."
# Bail if the plugin version is not found.
if [ -z "$PLUGIN_VERSION_WPORG" ]; then
echo "::error::Could not retrieve ${{ matrix.plugin }} information from WordPress.org. The plugin may not exist or the API may be down."
exit 1
fi
# Bail if the plugin is already up to date.
if [ "$PLUGIN_VERSION_WPORG" = "$PLUGIN_VERSION" ]; then
echo "::notice::The ${{ matrix.plugin }} plugin is already up to date on WordPress.org. Halting deployment."
exit 0
fi
echo "deploy=true" >> $GITHUB_OUTPUT
- name: Create zip file
if: steps.check-deployment.outputs.deploy == 'true'
run: |
mkdir -p ./build/dist
cd ./build/${{ matrix.plugin }}
zip -r ../dist/${{ matrix.plugin }}.zip .
- name: Generate checksum
if: steps.check-deployment.outputs.deploy == 'true'
working-directory: ./build/dist
run: |
mkdir -p $RUNNER_TEMP/plugin-checksums
Expand All @@ -92,12 +115,14 @@ jobs:
cat $RUNNER_TEMP/plugin-checksums/checksums.txt | while read sum file; do echo "$sum $file" > ${file#\*}.sha256; done
- name: Upload artifact
if: steps.check-deployment.outputs.deploy == 'true'
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.plugin }}
path: ./build/dist

- name: Start deployment
if: steps.check-deployment.outputs.deploy == 'true'
uses: bobheadxi/deployments@v1
id: wporg-deployment
with:
Expand All @@ -106,6 +131,7 @@ jobs:
env: "wp.org plugin: ${{ matrix.plugin }}"

- name: Deploy Plugin - ${{ matrix.plugin }}
if: steps.check-deployment.outputs.deploy == 'true'
uses: 10up/action-wordpress-plugin-deploy@stable
with:
dry-run: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run || false }}
Expand All @@ -118,7 +144,7 @@ jobs:
ASSETS_DIR: ./plugins/${{ matrix.plugin }}/.wordpress-org

- name: Finish deployment
if: always()
if: ${{ steps.wporg-deployment.outputs.deployment_id && always() }}
uses: bobheadxi/deployments@v1
with:
step: finish
Expand All @@ -140,13 +166,34 @@ jobs:
matrix:
plugin: ${{ fromJSON(needs.pre-run.outputs.matrix) }}
steps:
- name: Check artifact existence
id: artifact-existence
uses: actions/github-script@v7
with:
script: |
const getArtifact = await github.request('GET /repos/{owner}/{repo}/actions/runs/{run_id}/artifacts{?name}', {
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.runId,
name: "${{ matrix.plugin }}"
});
if (getArtifact.status !== 200) {
throw new Error(`Invalid response from GitHub API: ${getArtifact.status}`);
}
core.setOutput('exists', getArtifact.data.artifacts.length > 0);
core.debug(`Artifact for ${{ matrix.plugin }} exists: ${core.getInput('exists')} ? "true" : "false"`);
- name: Download artifact
if: steps.artifact-existence.outputs.exists == 'true'
uses: actions/download-artifact@v4
with:
name: ${{ matrix.plugin }}
path: ./build/dist

- name: Upload release assets
if: steps.artifact-existence.outputs.exists == 'true'
uses: softprops/action-gh-release@v1
with:
files: |
Expand Down

0 comments on commit 0d5451d

Please sign in to comment.