|
1 | 1 | # This workflow updates all dependencies to their latest versions |
2 | 2 | # |
3 | 3 | # 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 |
8 | 9 | # |
9 | 10 | # To run this workflow: |
10 | 11 | # 1. Go to Actions tab in the repository |
@@ -38,13 +39,55 @@ jobs: |
38 | 39 | with: |
39 | 40 | node-version: '18' |
40 | 41 |
|
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 |
43 | 85 |
|
44 | 86 | - 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 |
48 | 91 |
|
49 | 92 | - name: Install dependencies |
50 | 93 | run: yarn install |
|
0 commit comments