Skip to content

Commit b3ea853

Browse files
committed
test message
1 parent 120e73d commit b3ea853

1 file changed

Lines changed: 52 additions & 9 deletions

File tree

.github/workflows/update-dependencies.yml

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# This workflow updates all dependencies to their latest versions
22
#
33
# It performs the following steps:
4-
# 1. Removes the yarn.lock file
5-
# 2. Updates all dependencies in package.json to use wildcard "*" versions
6-
# 3. Runs yarn install to generate a new lock file with latest versions
7-
# 4. Commits and pushes the changes to the main branch
4+
# 1. Creates a script to check for the latest versions of all dependencies
5+
# 2. Updates package.json with the latest versions
6+
# 3. Removes the yarn.lock file
7+
# 4. Runs yarn install to generate a new lock file with latest versions
8+
# 5. Commits and pushes the changes to the main branch
89
#
910
# To run this workflow:
1011
# 1. Go to Actions tab in the repository
@@ -38,13 +39,55 @@ jobs:
3839
with:
3940
node-version: '18'
4041

41-
- name: Remove lock file
42-
run: rm -f yarn.lock
42+
- name: Create update script
43+
run: |
44+
cat > update-deps.js << 'EOF'
45+
const fs = require('fs');
46+
const { execSync } = require('child_process');
47+
48+
// Read the package.json file
49+
const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
50+
51+
// Function to get the latest version of a package
52+
function getLatestVersion(packageName) {
53+
try {
54+
const output = execSync(`npm view ${packageName} version`).toString().trim();
55+
console.log(`${packageName}: latest version is ${output}`);
56+
return output;
57+
} catch (error) {
58+
console.error(`Error getting latest version for ${packageName}:`, error.message);
59+
return null;
60+
}
61+
}
62+
63+
// Update dependencies
64+
console.log('Updating dependencies...');
65+
for (const dep in packageJson.dependencies) {
66+
const latestVersion = getLatestVersion(dep);
67+
if (latestVersion) {
68+
packageJson.dependencies[dep] = `^${latestVersion}`;
69+
}
70+
}
71+
72+
// Update devDependencies
73+
console.log('\nUpdating devDependencies...');
74+
for (const dep in packageJson.devDependencies) {
75+
const latestVersion = getLatestVersion(dep);
76+
if (latestVersion) {
77+
packageJson.devDependencies[dep] = `^${latestVersion}`;
78+
}
79+
}
80+
81+
// Write the updated package.json
82+
fs.writeFileSync('./package.json', JSON.stringify(packageJson, null, 2) + '\n');
83+
console.log('\nPackage.json updated with latest versions.');
84+
EOF
4385
4486
- name: Update dependencies
45-
run: |
46-
npm pkg set dependencies="$(npm pkg get dependencies | jq 'to_entries | map(.value = "*") | from_entries')"
47-
npm pkg set devDependencies="$(npm pkg get devDependencies | jq 'to_entries | map(.value = "*") | from_entries')"
87+
run: node update-deps.js
88+
89+
- name: Remove lock file
90+
run: rm -f yarn.lock
4891

4992
- name: Install dependencies
5093
run: yarn install

0 commit comments

Comments
 (0)