-
Notifications
You must be signed in to change notification settings - Fork 149
/
Copy pathupdate.js
71 lines (59 loc) · 2.23 KB
/
update.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env node
import fs from 'fs';
import { execSync } from 'child_process';
const headers = {
'User-Agent': 'shopware tag updater',
}
if (process.env.GITHUB_TOKEN) {
headers['Authorization'] = `Bearer ${process.env.GITHUB_TOKEN}`;
}
/**
* Update Shopware core to latest version
*
* This script:
* 1. Fetches all tags from Shopware core repository
* 2. For each tag, checks if it already exists in the local git repository
* 3. If not, updates composer.json, commits changes, tags, and resets to trunk
*/
async function update() {
try {
// Fetch tags from GitHub
const response = await fetch('https://api.github.com/repos/shopware/core/tags?per_page=50', {
headers
});
const tags = await response.json();
// Process each tag
for (const item of tags) {
try {
// Check if tag already exists in the repo
execSync(`git rev-parse ${item.name}`, { stdio: 'pipe' });
console.log(`Tag ${item.name} already exists, skipping...`);
} catch (error) {
// Tag doesn't exist, proceed with update
console.log(`Processing new tag: ${item.name}`);
// Read composer.json
const composerJsonPath = './composer.json';
let composerJson = JSON.parse(fs.readFileSync(composerJsonPath, 'utf8'));
// Update stability setting
if (item.name.includes('rc')) {
composerJson['minimum-stability'] = 'RC';
} else {
composerJson['minimum-stability'] = 'stable';
}
// Update shopware/core version
composerJson.require['shopware/core'] = item.name;
// Write updated composer.json
fs.writeFileSync(composerJsonPath, JSON.stringify(composerJson, null, 2));
// Git operations
execSync('git add composer.json');
execSync(`git commit -m "Update shopware/core to ${item.name}"`, {stdio: 'inherit'});
execSync(`git tag -m "Release: ${item.name}" ${item.name}`, {stdio: 'inherit'});
execSync('git reset --hard origin/trunk', {stdio: 'inherit'});
console.log(`Successfully processed tag: ${item.name}`);
}
}
} catch (error) {
console.error('An error occurred:', error);
}
}
await update();