Skip to content

Commit a284c93

Browse files
authored
Automatically download missing packages from repo.magento.com every day (#215)
* Additional packages * Additional packages * work * work * work * work * work * work * work * work
1 parent 3a0d015 commit a284c93

File tree

2 files changed

+144
-0
lines changed

2 files changed

+144
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Download missing packages from repo.magento.com
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: '0 0 * * *'
7+
8+
jobs:
9+
download-packages:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Setup PHP
20+
uses: shivammathur/setup-php@v2
21+
with:
22+
php-version: '8.3'
23+
tools: composer
24+
25+
- name: Setup Node.js
26+
uses: actions/setup-node@v4
27+
28+
- name: Configure Git
29+
run: |
30+
git config user.name "GitHub Actions Bot"
31+
git config user.email "github-actions[bot]@users.noreply.github.com"
32+
33+
- name: Run mirror script
34+
run: node src/make/mirror.js --outputDir=build
35+
36+
- name: Run download script
37+
run: php bin/download-all-missing-packages-from-repo-magento-com.php
38+
env:
39+
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
40+
41+
- name: Check for changes
42+
id: git-check
43+
run: |
44+
git add resource/additional-packages
45+
if git diff --staged --quiet; then
46+
echo "No changes detected in resource/additional-packages"
47+
echo "changes=false" >> $GITHUB_OUTPUT
48+
else
49+
echo "Changes detected in resource/additional-packages"
50+
echo "changes=true" >> $GITHUB_OUTPUT
51+
fi
52+
53+
- name: Create Pull Request
54+
if: steps.git-check.outputs.changes == 'true'
55+
run: |
56+
# Create a new branch with timestamp
57+
BRANCH_NAME="update-packages-$(date +%Y%m%d-%H%M%S)"
58+
git checkout -b $BRANCH_NAME
59+
60+
# Commit changes
61+
git commit -m "Add new packages from repo.magento.com"
62+
63+
# Push to the repository
64+
git push origin $BRANCH_NAME
65+
66+
# Create PR using GitHub CLI
67+
gh pr create \
68+
--title "Add new packages from repo.magento.com" \
69+
--body "This PR adds new packages downloaded from repo.magento.com by the automated workflow. Please rebuild the mirror after merging." \
70+
--repo "mage-os/generate-mirror-repo-js" \
71+
--base main \
72+
--head $BRANCH_NAME
73+
env:
74+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
/**
5+
* Script to download the latest Magento packages
6+
* This script:
7+
* 1. Finds the latest version for each major.minor release in resource/history/magento/magento2-base
8+
* 2. Uses composer to create a project with each version
9+
* 3. Uses the download-missing-packages-from-repo-magento-com.php script to download missing packages
10+
* 4. Removes the project directory
11+
*/
12+
13+
// Set error reporting
14+
error_reporting(E_ALL);
15+
ini_set('display_errors', 1);
16+
17+
// Directory containing version files
18+
$versionDir = "resource/history/magento/magento2-base";
19+
20+
// Get all version files
21+
$versionFiles = glob("$versionDir/*.json");
22+
if (empty($versionFiles)) {
23+
echo "Error: No version files found in $versionDir\n";
24+
exit(1);
25+
}
26+
27+
// Collect all versions
28+
$versions = [];
29+
foreach ($versionFiles as $file) {
30+
$versions[] = basename($file, '.json');
31+
}
32+
33+
usort($versions, function($a, $b) {
34+
return version_compare($a, $b);
35+
});
36+
37+
$latestVersions = [];
38+
foreach ($versions as $version) {
39+
$versionAndPatch = explode('-', $version);
40+
$latestVersions[$versionAndPatch[0]] = $version;
41+
}
42+
43+
// Process each version
44+
foreach ($latestVersions as $version) {
45+
echo "Processing version: $version\n";
46+
47+
// Create project directory using composer
48+
echo "Creating Magento project with version $version...\n";
49+
$command = "composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition:$version --ignore-platform-reqs --no-progress -q -n --no-plugins";
50+
passthru($command, $returnCode);
51+
52+
if ($returnCode !== 0) {
53+
echo "Error: Composer command failed with return code $returnCode\n";
54+
continue;
55+
}
56+
57+
// Download missing packages
58+
echo "Downloading missing packages...\n";
59+
$command = "php bin/download-missing-packages-from-repo-magento-com.php project-community-edition/composer.lock build resource/additional-packages";
60+
passthru($command, $returnCode);
61+
62+
// Remove project directory
63+
echo "Cleaning up project directory...\n";
64+
$command = "rm -rf project-community-edition";
65+
passthru($command);
66+
67+
echo "\n\n";
68+
}
69+
70+
echo "Done!\n";

0 commit comments

Comments
 (0)