woocommerce-paypal-payments/.github/workflows/weekly-builds.yml
2026-01-13 16:16:47 +02:00

133 lines
5.9 KiB
YAML

name: 'Weekly builds'
on:
schedule:
- cron: '0 11 * * 2' # Run every Tuesday at 11 AM UTC (12pm CET)
workflow_dispatch:
env:
SOURCE_REF: dev/develop
jobs:
create-tag:
if: github.repository_owner == 'woocommerce'
name: Create weekly tag
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
weekly_tag: ${{ steps.create_release.outputs.weekly_tag }}
release_upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Create weekly tag and release
id: create_release
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const sourceRef = process.env.SOURCE_REF;
const latestRelease = await github.rest.repos.getLatestRelease({
...context.repo
});
const latestTag = latestRelease.data.tag_name;
// Generate tag name
const now = new Date();
const month = String(now.getMonth() + 1).padStart(2, '0');
const day = String(now.getDate()).padStart(2, '0');
const year = String(now.getFullYear());
const weeklyTag = `${latestTag}-alpha${year}${month}${day}`;
const branchData = await github.rest.repos.getBranch({
...context.repo,
branch: sourceRef,
});
await github.rest.git.createRef({
...context.repo,
ref: `refs/tags/${weeklyTag}`,
sha: branchData.data.commit.sha,
});
// Create a new release
const release = await github.rest.repos.createRelease({
...context.repo,
tag_name: weeklyTag,
name: `Weekly Build ${year}-${month}-${day}`,
body: `Weekly builds are autogenerated every Tuesday at 12pm CET
▶️ [Test it on WordPress Playground](https://playground.wordpress.net/#%7B%22landingPage%22:%22/wp-admin/admin.php?page=wc-settings&tab=advanced&section=blueprint&activate-multi=true%22,%22preferredVersions%22:%7B%22php%22:%228.0%22,%22wp%22:%22latest%22%7D,%22phpExtensionBundles%22:%5B%22kitchen-sink%22%5D,%22features%22:%7B%22networking%22:true%7D,%22steps%22:%5B%7B%22step%22:%22installPlugin%22,%22pluginData%22:%7B%22resource%22:%22wordpress.org/plugins%22,%22slug%22:%22woocommerce%22%7D,%22options%22:%7B%22activate%22:true%7D%7D,%7B%22step%22:%22installPlugin%22,%22pluginZipFile%22:%7B%22resource%22:%22url%22,%22url%22:%22https://github.com/woocommerce/woocommerce-paypal-payments/releases/download/${weeklyTag}/woocommerce-paypal-payments-${weeklyTag}.zip%22%7D,%22options%22:%7B%22activate%22:true%7D%7D,%7B%22step%22:%22setSiteOptions%22,%22options%22:%7B%22woocommerce_onboarding_profile%22:%7B%22skipped%22:true%7D%7D%7D,%7B%22step%22:%22setSiteOptions%22,%22options%22:%7B%22woocommerce_coming_soon%22:%22yes%22%7D%7D,%7B%22step%22:%22login%22,%22username%22:%22admin%22,%22password%22:%22password%22%7D%5D,%22plugins%22:%5B%5D%7D)
`,
draft: false,
prerelease: true,
});
core.setOutput('weekly_tag', weeklyTag);
core.setOutput('upload_url', release.data.upload_url);
build:
if: github.repository_owner == 'woocommerce'
name: Build package
needs: create-tag
uses: inpsyde/reusable-workflows/.github/workflows/build-and-distribute.yml@main
secrets:
GITHUB_USER_EMAIL: ${{ secrets.DEPLOYBOT_EMAIL }}
GITHUB_USER_NAME: ${{ secrets.DEPLOYBOT_USER }}
GITHUB_USER_SSH_KEY: ${{ secrets.DEPLOYBOT_SSH_PRIVATE_KEY }}
GITHUB_USER_SSH_PUBLIC_KEY: ${{ secrets.DEPLOYBOT_SSH_PUBLIC_KEY }}
with:
PACKAGE_VERSION: ${{ needs.create-tag.outputs.weekly_tag }}
NODE_VERSION: 22
deploy:
if: github.repository_owner == 'woocommerce'
name: Upload weekly build
runs-on: ubuntu-latest
needs: [create-tag, build]
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: woocommerce-paypal-payments-${{ needs.create-tag.outputs.weekly_tag }}
path: ./artifacts
- name: Create and upload zip file
working-directory: ./artifacts
run: |
zip -r ./woocommerce-paypal-payments-${{ needs.create-tag.outputs.weekly_tag }}.zip ./woocommerce-paypal-payments
- name: Upload to release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create-tag.outputs.release_upload_url }}
asset_path: ./artifacts/woocommerce-paypal-payments-${{ needs.create-tag.outputs.weekly_tag }}.zip
asset_name: woocommerce-paypal-payments-${{ needs.create-tag.outputs.weekly_tag }}.zip
asset_content_type: application/zip
notify-slack:
if: always() && github.repository_owner == 'woocommerce'
name: Send Slack notification
runs-on: ubuntu-latest
needs: [ create-tag, build, deploy ]
steps:
- name: Send success message to Slack
if: needs.deploy.result == 'success'
uses: slackapi/slack-github-action@v2.1.1
with:
webhook: ${{ secrets.WEEKLY_RELEASE_SLACK_HOOK }}
webhook-type: webhook-trigger
payload: |
"status": "🎉 A new Weekly Pre Release has been uploaded",
"workflow": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
- name: Send failure message to Slack
if: needs.deploy.result == 'failure' || needs.build.result == 'failure' || needs.create-tag.result == 'failure'
uses: slackapi/slack-github-action@v2.1.1
with:
webhook: ${{ secrets.WEEKLY_RELEASE_SLACK_HOOK }}
webhook-type: webhook-trigger
payload: |
"status": "😰 Ups! It was an error uploading the Weekly Pre Release",
"workflow": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"