Compare commits

...

54 Commits

Author SHA1 Message Date
Tonye Jack
85c8b8252f chore: improve test coverage (#1430)
Co-authored-by: GitHub Action <action@github.com>
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
2023-08-03 13:25:35 -06:00
Tonye Jack
948fd1aec0 Update README.md 2023-08-03 13:24:56 -06:00
renovate[bot]
213a6fbf71 chore(deps): update dependency prettier to v3.0.1 (#1428)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-03 09:12:04 +00:00
renovate[bot]
c089e392a9 chore(deps): lock file maintenance (#1427)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-03 02:51:06 +00:00
dependabot[bot]
387fa91a19 chore(deps-dev): bump @types/node from 20.4.5 to 20.4.6 (#1426)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-08-03 02:06:04 +00:00
Tonye Jack
bde04d3ec6 Update README.md 2023-08-01 11:03:13 -06:00
renovate[bot]
ce7dceac93 chore(deps): lock file maintenance (#1424)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-01 13:50:52 +00:00
renovate[bot]
18832c2f0d chore(deps): lock file maintenance (#1423)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-01 02:33:46 +00:00
Tonye Jack
3fdcd6b1fa Update README.md 2023-07-31 17:44:57 -06:00
renovate[bot]
2b564ea543 chore(deps): update typescript-eslint monorepo to v6.2.1 (#1422)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
2023-07-31 19:04:38 +00:00
Tonye Jack
6b62acfc40 Update README.md 2023-07-31 12:36:37 -06:00
renovate[bot]
62411c0bbf chore(deps): lock file maintenance (#1421)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-07-31 00:27:03 +00:00
tj-actions[bot]
c10ebdc85f Updated README.md (#1420)
Co-authored-by: jackton1 <jackton1@users.noreply.github.com>
2023-07-30 01:55:31 +00:00
Tonye Jack
1b00b76bc1 Update README.md 2023-07-29 19:40:28 -06:00
renovate[bot]
8ffb34e4db chore(deps): lock file maintenance (#1419)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-07-29 05:29:21 +00:00
tj-actions[bot]
81ce706243 Upgraded to v37.5.1 (#1418)
Co-authored-by: jackton1 <jackton1@users.noreply.github.com>
2023-07-28 22:41:29 +00:00
renovate[bot]
a96679dfee chore(deps): update dependency eslint to v8.46.0 (#1417)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-07-28 19:34:23 +00:00
renovate[bot]
0c659577d4 chore(deps): lock file maintenance (#1416)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-07-27 18:23:35 +00:00
renovate[bot]
ea41e77287 chore(deps): update dependency jest to v29.6.2 (#1415)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-07-27 10:07:05 +00:00
Tonye Jack
ca51c3f430 Update README.md 2023-07-26 17:19:03 -06:00
Tonye Jack
5716c6246f Update README.md 2023-07-26 11:14:14 -06:00
Tonye Jack
f6edf885b4 Update README.md 2023-07-26 11:13:06 -06:00
renovate[bot]
4acaa728bb chore(deps): update dependency @types/lodash to v4.14.196 (#1413)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-07-26 00:22:46 +00:00
Tonye Jack
331d2daf96 Update README.md 2023-07-25 17:08:04 -06:00
tj-actions[bot]
174b246d44 Updated README.md (#1412)
Co-authored-by: jackton1 <jackton1@users.noreply.github.com>
2023-07-25 17:06:54 -06:00
Tonye Jack
0bf83955a9 Update README.md 2023-07-25 17:05:23 -06:00
Tonye Jack
69c6091ee4 Update README.md 2023-07-25 17:05:08 -06:00
renovate[bot]
cf02ab960f chore(deps): update dependency @types/node to v20.4.5 (#1409)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-07-25 20:43:43 +00:00
renovate[bot]
b50d1ab2d1 chore(deps): lock file maintenance (#1408)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-07-25 13:25:55 +00:00
Tonye Jack
ba9054e8d5 Update README.md 2023-07-24 21:58:54 -06:00
Tonye Jack
7e9cc01c54 Update README.md 2023-07-24 21:27:04 -06:00
tj-actions[bot]
0f52c861db Upgraded to v37.5.0 (#1407)
Co-authored-by: jackton1 <jackton1@users.noreply.github.com>
2023-07-24 23:40:13 +00:00
renovate[bot]
920e7b9ae1 chore(deps): lock file maintenance (#1406)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-07-24 22:25:33 +00:00
Tonye Jack
b8e577a274 feat: add support to detect changes for merge group event (#1404)
Co-authored-by: GitHub Action <action@github.com>
2023-07-24 21:40:48 +00:00
Tonye Jack
fc3c551a67 fix: error fetch more history for release events (#1403)
Co-authored-by: GitHub Action <action@github.com>
2023-07-24 20:34:13 +00:00
renovate[bot]
797a722244 chore(deps): update typescript-eslint monorepo to v6.2.0 (#1402)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-07-24 19:57:17 +00:00
renovate[bot]
44790ad9d8 chore(deps): lock file maintenance (#1401)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: GitHub Action <action@github.com>
2023-07-24 00:48:28 +00:00
Tonye Jack
73d266fe29 Update package.json 2023-07-23 13:32:41 -06:00
Tonye Jack
e1ddf02aff Update package.json 2023-07-23 13:31:48 -06:00
Tonye Jack
66d62c97d5 chore: update package.json 2023-07-23 13:30:24 -06:00
renovate[bot]
d44a61ef33 chore(deps): update dependency @types/node to v20.4.4 (#1400)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-07-22 16:16:14 +00:00
renovate[bot]
ef59201f02 chore(deps): update dependency @types/node to v20.4.3 (#1399)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-07-22 01:40:03 +00:00
Tonye Jack
f5439803c2 Update README.md 2023-07-20 18:20:09 -06:00
Tonye Jack
a0a0be0376 Update README.md 2023-07-20 13:54:41 -06:00
tj-actions[bot]
48ce5846c9 Upgraded to v37.4.0 (#1397)
Co-authored-by: jackton1 <jackton1@users.noreply.github.com>
2023-07-20 18:43:39 +00:00
Tonye Jack
de0eba3279 feat: update error handling for yaml inputs (#1395)
Co-authored-by: GitHub Action <action@github.com>
2023-07-20 18:05:55 +00:00
Tonye Jack
bc262c2f61 Update README.md 2023-07-20 11:41:44 -06:00
Tonye Jack
d4389f0f4f Update README.md 2023-07-20 06:48:41 -06:00
tj-actions[bot]
79984462e1 Updated README.md (#1394)
Co-authored-by: jackton1 <jackton1@users.noreply.github.com>
2023-07-19 17:08:30 -06:00
Tonye Jack
c6dcc2a013 Update action.yml 2023-07-19 17:07:28 -06:00
tj-actions[bot]
e6dde3c065 Upgraded to v37.3.0 (#1392)
Co-authored-by: jackton1 <jackton1@users.noreply.github.com>
2023-07-19 08:19:57 +00:00
tj-actions[bot]
39283171ce Updated README.md (#1391)
Co-authored-by: repo-ranger[bot] <repo-ranger[bot]@users.noreply.github.com>
2023-07-19 01:53:16 -06:00
Tonye Jack
33288d37e7 feat: add support for restricting recoverable deleted files via patterns (#1390)
Co-authored-by: GitHub Action <action@github.com>
2023-07-19 07:50:59 +00:00
tj-actions[bot]
b60277dde9 Upgraded to v37.2.0 (#1389)
Co-authored-by: jackton1 <jackton1@users.noreply.github.com>
2023-07-19 05:43:20 +00:00
14 changed files with 1699 additions and 811 deletions

View File

@@ -1,5 +1,129 @@
# Changelog # Changelog
# [37.5.1](https://github.com/tj-actions/changed-files/compare/v37.5.0...v37.5.1) - (2023-07-28)
## <!-- 26 -->🔄 Update
- Update README.md ([ca51c3f](https://github.com/tj-actions/changed-files/commit/ca51c3f4304b9cd96adebaa47025a2014040eb61)) - (Tonye Jack)
- Update README.md ([5716c62](https://github.com/tj-actions/changed-files/commit/5716c6246fcfd7031340a7be53243a6a6b689c3e)) - (Tonye Jack)
- Update README.md ([f6edf88](https://github.com/tj-actions/changed-files/commit/f6edf885b4a59cd97f396367b3e6fe4f26454601)) - (Tonye Jack)
- Update README.md ([331d2da](https://github.com/tj-actions/changed-files/commit/331d2daf96995ca6711e07b13681faa6a55bda62)) - (Tonye Jack)
- Updated README.md ([#1412](https://github.com/tj-actions/changed-files/issues/1412))
Co-authored-by: jackton1 <jackton1@users.noreply.github.com> ([174b246](https://github.com/tj-actions/changed-files/commit/174b246d44adb53ce1a125fc589734fce01e47eb)) - (tj-actions[bot])
- Update README.md ([0bf8395](https://github.com/tj-actions/changed-files/commit/0bf83955a913aa99abe90724dc460e86708af650)) - (Tonye Jack)
- Update README.md ([69c6091](https://github.com/tj-actions/changed-files/commit/69c6091ee4f562b2c6509ded97c4e5330ac95b09)) - (Tonye Jack)
- Update README.md ([ba9054e](https://github.com/tj-actions/changed-files/commit/ba9054e8d5ffe1537ded23c6a65348cb9b78e8c4)) - (Tonye Jack)
- Update README.md ([7e9cc01](https://github.com/tj-actions/changed-files/commit/7e9cc01c5474ea22e06e55ea8a296c8653e64d0c)) - (Tonye Jack)
## <!-- 7 -->⚙️ Miscellaneous Tasks
- **deps:** Update dependency eslint to v8.46.0 ([#1417](https://github.com/tj-actions/changed-files/issues/1417)) ([a96679d](https://github.com/tj-actions/changed-files/commit/a96679dfee2a1e64b1db5a210c0ffaf1f2cb24ce)) - (renovate[bot])
- **deps:** Lock file maintenance ([#1416](https://github.com/tj-actions/changed-files/issues/1416)) ([0c65957](https://github.com/tj-actions/changed-files/commit/0c659577d4b26faf3f99868ea9cabd2775f9b3cb)) - (renovate[bot])
- **deps:** Update dependency jest to v29.6.2 ([#1415](https://github.com/tj-actions/changed-files/issues/1415)) ([ea41e77](https://github.com/tj-actions/changed-files/commit/ea41e772876ff19a8d86e3315c52ceff3dae1941)) - (renovate[bot])
- **deps:** Update dependency @types/lodash to v4.14.196 ([#1413](https://github.com/tj-actions/changed-files/issues/1413)) ([4acaa72](https://github.com/tj-actions/changed-files/commit/4acaa728bbc362e0ced57dad81204885d253a0e6)) - (renovate[bot])
- **deps:** Update dependency @types/node to v20.4.5 ([#1409](https://github.com/tj-actions/changed-files/issues/1409)) ([cf02ab9](https://github.com/tj-actions/changed-files/commit/cf02ab960fc3dee58fc4911fac2c6946f4f64552)) - (renovate[bot])
- **deps:** Lock file maintenance ([#1408](https://github.com/tj-actions/changed-files/issues/1408)) ([b50d1ab](https://github.com/tj-actions/changed-files/commit/b50d1ab2d1388e35e9163a8eb2ae8b903e62ca8e)) - (renovate[bot])
## <!-- 9 -->⬆️ Upgrades
- Upgraded to v37.5.0 ([#1407](https://github.com/tj-actions/changed-files/issues/1407))
Co-authored-by: jackton1 <jackton1@users.noreply.github.com> ([0f52c86](https://github.com/tj-actions/changed-files/commit/0f52c861db7764988bb85cbb66a0b166787f586b)) - (tj-actions[bot])
# [37.5.0](https://github.com/tj-actions/changed-files/compare/v37.4.0...v37.5.0) - (2023-07-24)
## <!-- 0 -->🚀 Features
- Add support to detect changes for merge group event ([#1404](https://github.com/tj-actions/changed-files/issues/1404)) ([b8e577a](https://github.com/tj-actions/changed-files/commit/b8e577a27496ebc04ffb8b3bbca1b30a145001b1)) - (Tonye Jack)
## <!-- 1 -->🐛 Bug Fixes
- Error fetch more history for release events ([#1403](https://github.com/tj-actions/changed-files/issues/1403)) ([fc3c551](https://github.com/tj-actions/changed-files/commit/fc3c551a67c6151b4b7746c157a9c0914f18e129)) - (Tonye Jack)
## <!-- 26 -->🔄 Update
- Update package.json ([73d266f](https://github.com/tj-actions/changed-files/commit/73d266fe29bbb01958506ffe53b575269d8f2b13)) - (Tonye Jack)
- Update package.json ([e1ddf02](https://github.com/tj-actions/changed-files/commit/e1ddf02aff6c4d9a624216633291c52df6630421)) - (Tonye Jack)
- Update README.md ([f543980](https://github.com/tj-actions/changed-files/commit/f5439803c2c02cdb10b325d247c8ccc66cbc2203)) - (Tonye Jack)
- Update README.md ([a0a0be0](https://github.com/tj-actions/changed-files/commit/a0a0be0376b580745f0bd13a6b7ee4e98d028bf3)) - (Tonye Jack)
## <!-- 7 -->⚙️ Miscellaneous Tasks
- **deps:** Lock file maintenance ([#1406](https://github.com/tj-actions/changed-files/issues/1406)) ([920e7b9](https://github.com/tj-actions/changed-files/commit/920e7b9ae1d45913fc81f86c956fee89c77d2e5e)) - (renovate[bot])
- **deps:** Update typescript-eslint monorepo to v6.2.0 ([#1402](https://github.com/tj-actions/changed-files/issues/1402)) ([797a722](https://github.com/tj-actions/changed-files/commit/797a7222448d90d32258966774780cfb39ee4f44)) - (renovate[bot])
- **deps:** Lock file maintenance ([#1401](https://github.com/tj-actions/changed-files/issues/1401)) ([44790ad](https://github.com/tj-actions/changed-files/commit/44790ad9d8b0716d28defa47199281f484931e31)) - (renovate[bot])
- Update package.json ([66d62c9](https://github.com/tj-actions/changed-files/commit/66d62c97d57b2c770a365925793a1e8eb2b1dcd0)) - (Tonye Jack)
- **deps:** Update dependency @types/node to v20.4.4 ([#1400](https://github.com/tj-actions/changed-files/issues/1400)) ([d44a61e](https://github.com/tj-actions/changed-files/commit/d44a61ef339541580efca1a47286b8b9e3b69311)) - (renovate[bot])
- **deps:** Update dependency @types/node to v20.4.3 ([#1399](https://github.com/tj-actions/changed-files/issues/1399)) ([ef59201](https://github.com/tj-actions/changed-files/commit/ef59201f02fa40b09640c053d97cdf5c5dc65391)) - (renovate[bot])
## <!-- 9 -->⬆️ Upgrades
- Upgraded to v37.4.0 ([#1397](https://github.com/tj-actions/changed-files/issues/1397))
Co-authored-by: jackton1 <jackton1@users.noreply.github.com> ([48ce584](https://github.com/tj-actions/changed-files/commit/48ce5846c9a7c7c959b6c60e3afc80aaba4e6b0c)) - (tj-actions[bot])
# [37.4.0](https://github.com/tj-actions/changed-files/compare/v37.3.0...v37.4.0) - (2023-07-20)
## <!-- 0 -->🚀 Features
- Update error handling for yaml inputs ([#1395](https://github.com/tj-actions/changed-files/issues/1395)) ([de0eba3](https://github.com/tj-actions/changed-files/commit/de0eba32790fb9bf87471b32855a30fc8f9d5fc6)) - (Tonye Jack)
## <!-- 26 -->🔄 Update
- Update README.md ([bc262c2](https://github.com/tj-actions/changed-files/commit/bc262c2f61e2fdc75b802ad2213f80fefc98af12)) - (Tonye Jack)
- Update README.md ([d4389f0](https://github.com/tj-actions/changed-files/commit/d4389f0f4fe92065f29aee6519d551c3c5d26583)) - (Tonye Jack)
- Updated README.md ([#1394](https://github.com/tj-actions/changed-files/issues/1394))
Co-authored-by: jackton1 <jackton1@users.noreply.github.com> ([7998446](https://github.com/tj-actions/changed-files/commit/79984462e18db53eaaee1f8d582c2e752d13cf0c)) - (tj-actions[bot])
- Update action.yml ([c6dcc2a](https://github.com/tj-actions/changed-files/commit/c6dcc2a013c3d4f2a21908234845ba52952f2a57)) - (Tonye Jack)
## <!-- 9 -->⬆️ Upgrades
- Upgraded to v37.3.0 ([#1392](https://github.com/tj-actions/changed-files/issues/1392))
Co-authored-by: jackton1 <jackton1@users.noreply.github.com> ([e6dde3c](https://github.com/tj-actions/changed-files/commit/e6dde3c0653441e7c18779d1207fe87efa071f02)) - (tj-actions[bot])
# [37.3.0](https://github.com/tj-actions/changed-files/compare/v37.2.0...v37.3.0) - (2023-07-19)
## <!-- 0 -->🚀 Features
- Add support for restricting recoverable deleted files via patterns ([#1390](https://github.com/tj-actions/changed-files/issues/1390)) ([33288d3](https://github.com/tj-actions/changed-files/commit/33288d37e78121ba601151ba03d8dacaf856777c)) - (Tonye Jack)
## <!-- 26 -->🔄 Update
- Updated README.md ([#1391](https://github.com/tj-actions/changed-files/issues/1391))
Co-authored-by: repo-ranger[bot] <repo-ranger[bot]@users.noreply.github.com> ([3928317](https://github.com/tj-actions/changed-files/commit/39283171cefdf491e0f0d6cf285b86b31eb6f3cd)) - (tj-actions[bot])
## <!-- 9 -->⬆️ Upgrades
- Upgraded to v37.2.0 ([#1389](https://github.com/tj-actions/changed-files/issues/1389))
Co-authored-by: jackton1 <jackton1@users.noreply.github.com> ([b60277d](https://github.com/tj-actions/changed-files/commit/b60277dde98548f8d384a0b92a469fc5d0f46b1f)) - (tj-actions[bot])
# [37.2.0](https://github.com/tj-actions/changed-files/compare/v37.1.2...v37.2.0) - (2023-07-18)
## <!-- 26 -->🔄 Update
- Update README.md ([e3ea6b7](https://github.com/tj-actions/changed-files/commit/e3ea6b7948826820cfd616fda2d9c974a4ead314)) - (Tonye Jack)
## <!-- 7 -->⚙️ Miscellaneous Tasks
- **deps:** Update dependency eslint-plugin-github to v4.9.2 ([#1388](https://github.com/tj-actions/changed-files/issues/1388)) ([68b429d](https://github.com/tj-actions/changed-files/commit/68b429ddc666ea0dba46309e1ee45e06bb408df8)) - (renovate[bot])
- Switch to use the github context ([#1386](https://github.com/tj-actions/changed-files/issues/1386)) ([ec0b6d0](https://github.com/tj-actions/changed-files/commit/ec0b6d0e4c2965e4073849cbd0ab0e6fd3b42d50)) - (Tonye Jack)
- **deps:** Update dependency eslint-plugin-github to v4.9.1 ([#1387](https://github.com/tj-actions/changed-files/issues/1387)) ([8c8be23](https://github.com/tj-actions/changed-files/commit/8c8be234b2ced36de48c003dd2b2b0cd3448985f)) - (renovate[bot])
- **deps:** Update typescript-eslint monorepo to v6.1.0 ([#1385](https://github.com/tj-actions/changed-files/issues/1385)) ([029d6cd](https://github.com/tj-actions/changed-files/commit/029d6cd6b8191709b7e3d2bff0207a58a0c9c272)) - (renovate[bot])
- **deps:** Lock file maintenance ([#1383](https://github.com/tj-actions/changed-files/issues/1383)) ([8fc95ea](https://github.com/tj-actions/changed-files/commit/8fc95ea17520d70ecf9d3141ec0a0d8443780a48)) - (renovate[bot])
- **deps:** Lock file maintenance ([#1382](https://github.com/tj-actions/changed-files/issues/1382)) ([3e2a2ce](https://github.com/tj-actions/changed-files/commit/3e2a2ce2d08798ebef6a1b3b7fd8782820484ea4)) - (renovate[bot])
- **deps:** Update dependency eslint to v8.45.0 ([#1381](https://github.com/tj-actions/changed-files/issues/1381)) ([4aebdaf](https://github.com/tj-actions/changed-files/commit/4aebdafc0bbe1a3beffb6e7f6278d3323c6aabcb)) - (renovate[bot])
## <!-- 9 -->⬆️ Upgrades
- Upgraded to v37.1.2 ([#1378](https://github.com/tj-actions/changed-files/issues/1378))
Co-authored-by: jackton1 <jackton1@users.noreply.github.com> ([2aadab2](https://github.com/tj-actions/changed-files/commit/2aadab2297933ef2a8eaa3a3316ae458aafe4964)) - (tj-actions[bot])
# [37.1.2](https://github.com/tj-actions/changed-files/compare/v37.1.1...v37.1.2) - (2023-07-13) # [37.1.2](https://github.com/tj-actions/changed-files/compare/v37.1.1...v37.1.2) - (2023-07-13)
## <!-- 1 -->🐛 Bug Fixes ## <!-- 1 -->🐛 Bug Fixes

176
README.md
View File

@@ -13,10 +13,6 @@
<!-- ALL-CONTRIBUTORS-BADGE:END --> <!-- ALL-CONTRIBUTORS-BADGE:END -->
<div align="center">
<img width="auto" alt="Screen Shot 2021-11-19 at 4 59 21 PM" src="https://user-images.githubusercontent.com/17484350/229027815-eee0bf22-f3e5-444d-9d90-6409c68a0dc9.png">
</div>
## changed-files ## changed-files
Effortlessly track all changed files and directories relative to a target branch, preceding commit or the last remote commit returning **relative paths** from the project root using this GitHub action. Effortlessly track all changed files and directories relative to a target branch, preceding commit or the last remote commit returning **relative paths** from the project root using this GitHub action.
@@ -48,6 +44,7 @@ Effortlessly track all changed files and directories relative to a target branch
* Facilitates easy debugging. * Facilitates easy debugging.
* Scales to handle large repositories. * Scales to handle large repositories.
* Supports Git submodules. * Supports Git submodules.
* Supports [merge queues](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/configuring-pull-request-merges/managing-a-merge-queue) for pull reequests.
* Generates escaped JSON output for running matrix jobs based on changed files. * Generates escaped JSON output for running matrix jobs based on changed files.
* Lists changed directories. * Lists changed directories.
* Limits matching changed directories to a specified maximum depth. * Limits matching changed directories to a specified maximum depth.
@@ -65,7 +62,7 @@ Effortlessly track all changed files and directories relative to a target branch
* Between the last remote branch commit and the current HEAD. * Between the last remote branch commit and the current HEAD.
* Restricts change detection to a subset of files and directories: * Restricts change detection to a subset of files and directories:
* Provides boolean output indicating changes in specific files. * Provides boolean output indicating changes in specific files.
* Uses [Glob pattern](https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet) matching. * Uses [Glob pattern](https://codepen.io/mrmlnc/pen/OXQjMe) matching.
* Supports Globstar. * Supports Globstar.
* Supports brace expansion. * Supports brace expansion.
* Supports negation. * Supports negation.
@@ -79,11 +76,13 @@ And many more.
> **Warning**: > **Warning**:
> >
> * **IMPORTANT:** For `push` events when configuring [`actions/checkout`](https://github.com/actions/checkout#usage) the `fetch-depth` should be set to either `fetch-depth: 0` **OR** `fetch-depth: 2` depending on your use case. > * For `push` events: When configuring [`actions/checkout`](https://github.com/actions/checkout#usage), make sure to set [`fetch-depth`](https://github.com/actions/checkout#usage) to either `0` or `2`, depending on your use case.
> * For monorepos where pulling all the branch history might not be desired, you can omit [`actions/checkout`](https://github.com/actions/checkout#usage) - `fetch-depth` for `pull_request` events. > * For mono repositories where pulling all branch history might not be desired, you can still use the default [`fetch-depth`](https://github.com/actions/checkout#usage), which is set to `1` for `pull_request` events.
> * All multiline inputs should not use double or single quotes since the value is already a string separated by a newline character. See [Examples](#examples) for more information. > * Avoid using single or double quotes for multiline inputs, as the value is already a string separated by a newline character. See [Examples](#examples) for more information.
> * Ensure that `persist-credentials` is set to `true` when configuring [`actions/checkout`](https://github.com/actions/checkout#usage) if `fetch-depth` isn't set to `0`. > * If [`fetch-depth`](https://github.com/actions/checkout#usage) isn't set to `0`, ensure that `persist-credentials` is set to `true` when configuring [`actions/checkout`](https://github.com/actions/checkout#usage).
> * For repositories that have PRs generated from forks when configuring [`actions/checkout`](https://github.com/actions/checkout#usage) set the `repository` to `${{ github.event.pull_request.head.repo.full_name }}`. See: [Example](https://github.com/tj-actions/changed-files/blob/main/.github/workflows/test.yml#L47-L51) > * For repositories that have PRs generated from forks, when configuring [`actions/checkout`](https://github.com/actions/checkout#usage), set the [`repository`](https://github.com/actions/checkout#usage) to `${{ github.event.pull_request.head.repo.full_name }}`. See [Example](https://github.com/tj-actions/changed-files/blob/main/.github/workflows/test.yml#L47-L51).
Visit the [discussions for more information](https://github.com/tj-actions/changed-files/discussions) or [create a new discussion](https://github.com/tj-actions/changed-files/discussions/new/choose) for usage-related questions.
### On `pull_request` ### On `pull_request`
@@ -110,6 +109,36 @@ jobs:
fetch-depth: 0 # OR "2" -> To retrieve the preceding commit. fetch-depth: 0 # OR "2" -> To retrieve the preceding commit.
# Example 1 # Example 1
- name: Get all test, doc and src files that have changed
id: changed-files-yaml
uses: tj-actions/changed-files@v37
with:
files_yaml: |
doc:
- '**.md'
- docs/**
- docs/README.md
test:
- test/**
- '!test/**.md'
src:
- src/**
# Optionally set `files_yaml_from_source_file` to read the YAML from a file. e.g `files_yaml_from_source_file: .github/changed-files.yml`
- name: Run step if test file(s) change
# NOTE: The key has to start with the same key used above e.g. `test_(...)` | `doc_(...)` | `src_(...)` when trying to access the `any_changed` output.
if: steps.changed-files-yaml.outputs.test_any_changed == 'true'
run: |
echo "One or more test file(s) has changed."
echo "List all the files that have changed: ${{ steps.changed-files-yaml.outputs.test_all_changed_files }}"
- name: Run step if doc file(s) change
if: steps.changed-files-yaml.outputs.doc_any_changed == 'true'
run: |
echo "One or more doc file(s) has changed."
echo "List all the files that have changed: ${{ steps.changed-files-yaml.outputs.doc_all_changed_files }}"
# Example 2
- name: Get changed files - name: Get changed files
id: changed-files id: changed-files
uses: tj-actions/changed-files@v37 uses: tj-actions/changed-files@v37
@@ -124,7 +153,7 @@ jobs:
echo "$file was changed" echo "$file was changed"
done done
# Example 2 # Example 3
- name: Get changed files in the docs folder - name: Get changed files in the docs folder
id: changed-files-specific id: changed-files-specific
uses: tj-actions/changed-files@v37 uses: tj-actions/changed-files@v37
@@ -137,35 +166,6 @@ jobs:
run: | run: |
echo "One or more files in the docs folder has changed." echo "One or more files in the docs folder has changed."
echo "List all the files that have changed: ${{ steps.changed-files-specific.outputs.all_changed_files }}" echo "List all the files that have changed: ${{ steps.changed-files-specific.outputs.all_changed_files }}"
# Example 3
- name: Get all test, doc and src files that have changed
id: changed-files-yaml
uses: tj-actions/changed-files@v37
with:
files_yaml: |
doc:
- **.md
- docs/**
- !docs/README.md
test:
- test/**
- !test/README.md
src:
- src/**
# Optionally set `files_yaml_from_source_file` to read the YAML from a file. e.g `files_yaml_from_source_file: .github/changed-files.yml`
- name: Run step if test file(s) change
if: steps.changed-files-yaml.outputs.test_any_changed == 'true'
run: |
echo "One or more test file(s) has changed."
echo "List all the files that have changed: ${{ steps.changed-files-yaml.outputs.test_all_changed_files }}"
- name: Run step if doc file(s) change
if: steps.changed-files-yaml.outputs.doc_any_changed == 'true'
run: |
echo "One or more doc file(s) has changed."
echo "List all the files that have changed: ${{ steps.changed-files-yaml.outputs.doc_all_changed_files }}"
``` ```
#### Using Github's API #### Using Github's API
@@ -222,7 +222,9 @@ on:
# - cron: '0 0 * * *' # - cron: '0 0 * * *'
# #
# release: # release:
# types: [published] # types: [...]
#
# workflow_dispatch:
# #
# push: # push:
# tags: # tags:
@@ -294,6 +296,10 @@ Support this project with a :star:
| U | Unmerged | | U | Unmerged |
| X | Unknown | | X | Unknown |
> **Warning**:
>
> * When using `files_yaml*` inputs ensure all outputs are prefixed by the key `test_{...}` e.g. `test_added_files`, `test_any_changed`
## Outputs ## Outputs
<!-- AUTO-DOC-OUTPUT:START - Do not remove or modify this section --> <!-- AUTO-DOC-OUTPUT:START - Do not remove or modify this section -->
@@ -343,48 +349,52 @@ Support this project with a :star:
<!-- AUTO-DOC-INPUT:START - Do not remove or modify this section --> <!-- AUTO-DOC-INPUT:START - Do not remove or modify this section -->
| INPUT | TYPE | REQUIRED | DEFAULT | DESCRIPTION | | INPUT | TYPE | REQUIRED | DEFAULT | DESCRIPTION |
|----------------------------------------------|--------|----------|---------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |----------------------------------------------|--------|----------|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| api\_url | string | false | `"${{ github.api_url }}"` | Github API URL. | | api\_url | string | false | `"${{ github.api_url }}"` | Github API URL. |
| base\_sha | string | false | | Specify a different base commit <br>SHA used for comparing changes | | base\_sha | string | false | | Specify a different base commit <br>SHA used for comparing changes |
| diff\_relative | string | false | `"true"` | Exclude changes outside the current <br>directory and show path names <br>relative to it. **NOTE:** This <br>requires you to specify the <br>top level directory via the <br>`path` input. | | diff\_relative | string | false | `"true"` | Exclude changes outside the current <br>directory and show path names <br>relative to it. **NOTE:** This <br>requires you to specify the <br>top level directory via the <br>`path` input. |
| dir\_names | string | false | `"false"` | Output unique changed directories instead <br>of filenames. **NOTE:** This returns <br>`.` for changed files located <br>in the current working directory <br>which defaults to `$GITHUB_WORKSPACE`. | | dir\_names | string | false | `"false"` | Output unique changed directories instead <br>of filenames. **NOTE:** This returns <br>`.` for changed files located <br>in the current working directory <br>which defaults to `$GITHUB_WORKSPACE`. |
| dir\_names\_exclude\_current\_dir | string | false | `"false"` | Exclude the current directory represented <br>by `.` from the output <br>when `dir_names` is set to <br>`true`. | | dir\_names\_exclude\_current\_dir | string | false | `"false"` | Exclude the current directory represented <br>by `.` from the output <br>when `dir_names` is set to <br>`true`. |
| dir\_names\_max\_depth | string | false | | Limit the directory output to <br>a maximum depth e.g `test/test1/test2` <br>with max depth of `2` <br>returns `test/test1`. | | dir\_names\_max\_depth | string | false | | Limit the directory output to <br>a maximum depth e.g `test/test1/test2` <br>with max depth of `2` <br>returns `test/test1`. |
| escape\_json | string | false | `"true"` | Escape JSON output. | | escape\_json | string | false | `"true"` | Escape JSON output. |
| fetch\_depth | string | false | `"50"` | Depth of additional branch history <br>fetched. **NOTE**: This can be <br>adjusted to resolve errors with <br>insufficient history. | | fetch\_depth | string | false | `"50"` | Depth of additional branch history <br>fetched. **NOTE**: This can be <br>adjusted to resolve errors with <br>insufficient history. |
| files | string | false | | File and directory patterns used <br>to detect changes (Defaults to the entire repo if unset) **NOTE:** <br>Multiline file/directory patterns should not <br>include quotes. | | files | string | false | | File and directory patterns used <br>to detect changes (Defaults to the entire repo if unset) **NOTE:** <br>Multiline file/directory patterns should not <br>include quotes. |
| files\_from\_source\_file | string | false | | Source file(s) used to populate <br>the `files` input. | | files\_from\_source\_file | string | false | | Source file(s) used to populate <br>the `files` input. |
| files\_from\_source\_file\_separator | string | false | `"\n"` | Separator used to split the <br>`files_from_source_file` input | | files\_from\_source\_file\_separator | string | false | `"\n"` | Separator used to split the <br>`files_from_source_file` input |
| files\_ignore | string | false | | Ignore changes to these file(s) <br>**NOTE:** Multiline file/directory patterns should <br>not include quotes. | | files\_ignore | string | false | | Ignore changes to these file(s) <br>**NOTE:** Multiline file/directory patterns should <br>not include quotes. |
| files\_ignore\_from\_source\_file | string | false | | Source file(s) used to populate <br>the `files_ignore` input | | files\_ignore\_from\_source\_file | string | false | | Source file(s) used to populate <br>the `files_ignore` input |
| files\_ignore\_from\_source\_file\_separator | string | false | `"\n"` | Separator used to split the <br>`files_ignore_from_source_file` input | | files\_ignore\_from\_source\_file\_separator | string | false | `"\n"` | Separator used to split the <br>`files_ignore_from_source_file` input |
| files\_ignore\_separator | string | false | `"\n"` | Separator used to split the <br>`files_ignore` input | | files\_ignore\_separator | string | false | `"\n"` | Separator used to split the <br>`files_ignore` input |
| files\_ignore\_yaml | string | false | | YAML used to define a <br>set of file patterns to <br>ignore changes | | files\_ignore\_yaml | string | false | | YAML used to define a <br>set of file patterns to <br>ignore changes |
| files\_ignore\_yaml\_from\_source\_file | string | false | | Source file(s) used to populate <br>the `files_ignore_yaml` input. [Example](https://github.com/tj-actions/changed-files/blob/main/test/changed-files.yml) | | files\_ignore\_yaml\_from\_source\_file | string | false | | Source file(s) used to populate <br>the `files_ignore_yaml` input. [Example](https://github.com/tj-actions/changed-files/blob/main/test/changed-files.yml) |
| files\_ignore\_yaml\_from\_source\_file\_separator | string | false | `"\n"` | Separator used to split the <br>`files_ignore_yaml_from_source_file` input | | files\_ignore\_yaml\_from\_source\_file\_separator | string | false | `"\n"` | Separator used to split the <br>`files_ignore_yaml_from_source_file` input |
| files\_separator | string | false | `"\n"` | Separator used to split the <br>`files` input | | files\_separator | string | false | `"\n"` | Separator used to split the <br>`files` input |
| files\_yaml | string | false | | YAML used to define a <br>set of file patterns to <br>detect changes | | files\_yaml | string | false | | YAML used to define a <br>set of file patterns to <br>detect changes |
| files\_yaml\_from\_source\_file | string | false | | Source file(s) used to populate <br>the `files_yaml` input. [Example](https://github.com/tj-actions/changed-files/blob/main/test/changed-files.yml) | | files\_yaml\_from\_source\_file | string | false | | Source file(s) used to populate <br>the `files_yaml` input. [Example](https://github.com/tj-actions/changed-files/blob/main/test/changed-files.yml) |
| files\_yaml\_from\_source\_file\_separator | string | false | `"\n"` | Separator used to split the <br>`files_yaml_from_source_file` input | | files\_yaml\_from\_source\_file\_separator | string | false | `"\n"` | Separator used to split the <br>`files_yaml_from_source_file` input |
| include\_all\_old\_new\_renamed\_files | string | false | `"false"` | Include `all_old_new_renamed_files` output. Note this <br>can generate a large output <br>See: [#501](https://github.com/tj-actions/changed-files/issues/501). | | include\_all\_old\_new\_renamed\_files | string | false | `"false"` | Include `all_old_new_renamed_files` output. Note this <br>can generate a large output <br>See: [#501](https://github.com/tj-actions/changed-files/issues/501). |
| json | string | false | `"false"` | Output list of changed files <br>in a JSON formatted string <br>which can be used for <br>matrix jobs. | | json | string | false | `"false"` | Output list of changed files <br>in a JSON formatted string <br>which can be used for <br>matrix jobs. |
| old\_new\_files\_separator | string | false | `" "` | Split character for old and <br>new renamed filename pairs. | | old\_new\_files\_separator | string | false | `" "` | Split character for old and <br>new renamed filename pairs. |
| old\_new\_separator | string | false | `","` | Split character for old and <br>new filename pairs. | | old\_new\_separator | string | false | `","` | Split character for old and <br>new filename pairs. |
| output\_dir | string | false | `".github/outputs"` | Directory to store output files. | | output\_dir | string | false | `".github/outputs"` | Directory to store output files. |
| output\_renamed\_files\_as\_deleted\_and\_added | string | false | `"false"` | Output renamed files as deleted <br>and added files. | | output\_renamed\_files\_as\_deleted\_and\_added | string | false | `"false"` | Output renamed files as deleted <br>and added files. |
| path | string | false | `"."` | Specify a relative path under <br>`$GITHUB_WORKSPACE` to locate the repository. | | path | string | false | `"."` | Specify a relative path under <br>`$GITHUB_WORKSPACE` to locate the repository. |
| quotepath | string | false | `"true"` | Use non-ascii characters to match <br>files and output the filenames <br>completely verbatim by setting this <br>to `false` | | quotepath | string | false | `"true"` | Use non-ascii characters to match <br>files and output the filenames <br>completely verbatim by setting this <br>to `false` |
| recover\_deleted\_files | string | false | `"false"` | Recover deleted files. | | recover\_deleted\_files | string | false | `"false"` | Recover deleted files. |
| recover\_deleted\_files\_to\_destination | string | false | | Recover deleted files to a <br>new destination directory, defaults to <br>the original location. | | recover\_deleted\_files\_to\_destination | string | false | | Recover deleted files to a <br>new destination directory, defaults to <br>the original location. |
| separator | string | false | `" "` | Split character for output strings | | recover\_files | string | false | | File and directory patterns used <br>to recover deleted files, defaults <br>to the patterns provided via <br>the `files`, `files_from_source_file`, `files_ignore` and <br>`files_ignore_from_source_file` inputs or all deleted <br>files if no patterns are <br>provided. |
| sha | string | false | | Specify a different commit SHA <br>used for comparing changes | | recover\_files\_ignore | string | false | | File and directory patterns to <br>ignore when recovering deleted files. |
| since | string | false | | Get changed files for commits <br>whose timestamp is older than <br>the given time. | | recover\_files\_ignore\_separator | string | false | `"\n"` | Separator used to split the <br>`recover_files_ignore` input |
| since\_last\_remote\_commit | string | false | `"false"` | Use the last commit on <br>the remote branch as the <br>`base_sha`. Defaults to the last <br>non-merge commit on the target <br>branch for pull request events <br>and the previous remote commit <br>of the current branch for <br>push events. | | recover\_files\_separator | string | false | `"\n"` | Separator used to split the <br>`recover_files` input |
| skip\_initial\_fetch | string | false | `"false"` | Skip the initial fetch to <br>improve performance for shallow repositories. <br>**NOTE**: This could lead to <br>errors with missing history and <br>the intended use is limited <br>to when you've fetched the <br>history necessary to perform the <br>diff. | | separator | string | false | `" "` | Split character for output strings |
| token | string | false | `"${{ github.token }}"` | Github token used to fetch <br>changed files from Github's API. | | sha | string | false | | Specify a different commit SHA <br>used for comparing changes |
| until | string | false | | Get changed files for commits <br>whose timestamp is earlier than <br>the given time. | | since | string | false | | Get changed files for commits <br>whose timestamp is older than <br>the given time. |
| write\_output\_files | string | false | `"false"` | Write outputs to the `output_dir` <br>defaults to `.github/outputs` folder. **NOTE:** <br>This creates a `.txt` file <br>by default and a `.json` <br>file if `json` is set <br>to `true`. | | since\_last\_remote\_commit | string | false | `"false"` | Use the last commit on <br>the remote branch as the <br>`base_sha`. Defaults to the last <br>non-merge commit on the target <br>branch for pull request events <br>and the previous remote commit <br>of the current branch for <br>push events. |
| skip\_initial\_fetch | string | false | `"false"` | Skip the initial fetch to <br>improve performance for shallow repositories. <br>**NOTE**: This could lead to <br>errors with missing history and <br>the intended use is limited <br>to when you've fetched the <br>history necessary to perform the <br>diff. |
| token | string | false | `"${{ github.token }}"` | Github token used to fetch <br>changed files from Github's API. |
| until | string | false | | Get changed files for commits <br>whose timestamp is earlier than <br>the given time. |
| write\_output\_files | string | false | `"false"` | Write outputs to the `output_dir` <br>defaults to `.github/outputs` folder. **NOTE:** <br>This creates a `.txt` file <br>by default and a `.json` <br>file if `json` is set <br>to `true`. |
<!-- AUTO-DOC-INPUT:END --> <!-- AUTO-DOC-INPUT:END -->

View File

@@ -152,6 +152,22 @@ inputs:
description: "Recover deleted files to a new destination directory, defaults to the original location." description: "Recover deleted files to a new destination directory, defaults to the original location."
required: false required: false
default: "" default: ""
recover_files:
description: "File and directory patterns used to recover deleted files, defaults to the patterns provided via the `files`, `files_from_source_file`, `files_ignore` and `files_ignore_from_source_file` inputs or all deleted files if no patterns are provided."
required: false
default: ""
recover_files_separator:
description: "Separator used to split the `recover_files` input"
default: "\n"
required: false
recover_files_ignore:
description: "File and directory patterns to ignore when recovering deleted files."
required: false
default: ""
recover_files_ignore_separator:
description: "Separator used to split the `recover_files_ignore` input"
default: "\n"
required: false
token: token:
description: "Github token used to fetch changed files from Github's API." description: "Github token used to fetch changed files from Github's API."
required: false required: false

426
dist/index.js generated vendored
View File

@@ -153,16 +153,16 @@ exports.getAllDiffFiles = getAllDiffFiles;
function* getChangeTypeFilesGenerator({ inputs, changedFiles, changeTypes }) { function* getChangeTypeFilesGenerator({ inputs, changedFiles, changeTypes }) {
for (const changeType of changeTypes) { for (const changeType of changeTypes) {
const files = changedFiles[changeType] || []; const files = changedFiles[changeType] || [];
for (const file of files) { for (const filePath of files) {
if (inputs.dirNames) { if (inputs.dirNames) {
yield (0, utils_1.getDirnameMaxDepth)({ yield (0, utils_1.getDirnameMaxDepth)({
pathStr: file, relativePath: filePath,
dirNamesMaxDepth: inputs.dirNamesMaxDepth, dirNamesMaxDepth: inputs.dirNamesMaxDepth,
excludeCurrentDir: inputs.dirNamesExcludeCurrentDir excludeCurrentDir: inputs.dirNamesExcludeCurrentDir
}); });
} }
else { else {
yield file; yield filePath;
} }
} }
} }
@@ -184,16 +184,16 @@ const getChangeTypeFiles = ({ inputs, changedFiles, changeTypes }) => __awaiter(
}); });
exports.getChangeTypeFiles = getChangeTypeFiles; exports.getChangeTypeFiles = getChangeTypeFiles;
function* getAllChangeTypeFilesGenerator({ inputs, changedFiles }) { function* getAllChangeTypeFilesGenerator({ inputs, changedFiles }) {
for (const file of (0, flatten_1.default)(Object.values(changedFiles))) { for (const filePath of (0, flatten_1.default)(Object.values(changedFiles))) {
if (inputs.dirNames) { if (inputs.dirNames) {
yield (0, utils_1.getDirnameMaxDepth)({ yield (0, utils_1.getDirnameMaxDepth)({
pathStr: file, relativePath: filePath,
dirNamesMaxDepth: inputs.dirNamesMaxDepth, dirNamesMaxDepth: inputs.dirNamesMaxDepth,
excludeCurrentDir: inputs.dirNamesExcludeCurrentDir excludeCurrentDir: inputs.dirNamesExcludeCurrentDir
}); });
} }
else { else {
yield file; yield filePath;
} }
} }
} }
@@ -326,20 +326,12 @@ const utils_1 = __nccwpck_require__(918);
const getOutputKey = (key, outputPrefix) => { const getOutputKey = (key, outputPrefix) => {
return outputPrefix ? `${outputPrefix}_${key}` : key; return outputPrefix ? `${outputPrefix}_${key}` : key;
}; };
const setChangedFilesOutput = ({ allDiffFiles, inputs, workingDirectory, diffResult, filePatterns = [], outputPrefix = '' }) => __awaiter(void 0, void 0, void 0, function* () { const setChangedFilesOutput = ({ allDiffFiles, inputs, filePatterns = [], outputPrefix = '' }) => __awaiter(void 0, void 0, void 0, function* () {
const allFilteredDiffFiles = yield (0, utils_1.getFilteredChangedFiles)({ const allFilteredDiffFiles = yield (0, utils_1.getFilteredChangedFiles)({
allDiffFiles, allDiffFiles,
filePatterns filePatterns
}); });
core.debug(`All filtered diff files: ${JSON.stringify(allFilteredDiffFiles)}`); core.debug(`All filtered diff files: ${JSON.stringify(allFilteredDiffFiles)}`);
if (diffResult) {
yield (0, utils_1.recoverDeletedFiles)({
inputs,
workingDirectory,
deletedFiles: allFilteredDiffFiles[changedFiles_1.ChangeTypeEnum.Deleted],
sha: diffResult.previousSha
});
}
const addedFiles = yield (0, changedFiles_1.getChangeTypeFiles)({ const addedFiles = yield (0, changedFiles_1.getChangeTypeFiles)({
inputs, inputs,
changedFiles: allFilteredDiffFiles, changedFiles: allFilteredDiffFiles,
@@ -675,12 +667,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
}); });
}; };
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getSHAForPullRequestEvent = exports.getSHAForPushEvent = void 0; exports.getSHAForPullRequestEvent = exports.getSHAForNonPullRequestEvent = void 0;
const core = __importStar(__nccwpck_require__(2186)); const core = __importStar(__nccwpck_require__(2186));
const github = __importStar(__nccwpck_require__(5438)); const github = __importStar(__nccwpck_require__(5438));
const utils_1 = __nccwpck_require__(918); const utils_1 = __nccwpck_require__(918);
const getCurrentSHA = ({ inputs, workingDirectory }) => __awaiter(void 0, void 0, void 0, function* () { const getCurrentSHA = ({ inputs, workingDirectory }) => __awaiter(void 0, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f; var _a, _b, _c, _d, _e, _f, _g;
let currentSha = inputs.sha; let currentSha = inputs.sha;
core.debug('Getting current SHA...'); core.debug('Getting current SHA...');
if (inputs.until) { if (inputs.until) {
@@ -714,6 +706,9 @@ const getCurrentSHA = ({ inputs, workingDirectory }) => __awaiter(void 0, void 0
})) === 0) { })) === 0) {
currentSha = (_f = (_e = github.context.payload.pull_request) === null || _e === void 0 ? void 0 : _e.head) === null || _f === void 0 ? void 0 : _f.sha; currentSha = (_f = (_e = github.context.payload.pull_request) === null || _e === void 0 ? void 0 : _e.head) === null || _f === void 0 ? void 0 : _f.sha;
} }
else if (github.context.eventName === 'merge_group') {
currentSha = (_g = github.context.payload.merge_group) === null || _g === void 0 ? void 0 : _g.head_sha;
}
else { else {
currentSha = yield (0, utils_1.getHeadSha)({ cwd: workingDirectory }); currentSha = yield (0, utils_1.getHeadSha)({ cwd: workingDirectory });
} }
@@ -723,16 +718,21 @@ const getCurrentSHA = ({ inputs, workingDirectory }) => __awaiter(void 0, void 0
core.debug(`Current SHA: ${currentSha}`); core.debug(`Current SHA: ${currentSha}`);
return currentSha; return currentSha;
}); });
const getSHAForPushEvent = (inputs, env, workingDirectory, isShallow, hasSubmodule, gitFetchExtraArgs, isTag) => __awaiter(void 0, void 0, void 0, function* () { const getSHAForNonPullRequestEvent = (inputs, env, workingDirectory, isShallow, hasSubmodule, gitFetchExtraArgs, isTag) => __awaiter(void 0, void 0, void 0, function* () {
var _g; var _h, _j, _k;
let targetBranch = env.GITHUB_REF_NAME; let targetBranch = env.GITHUB_REF_NAME;
const currentBranch = targetBranch; const currentBranch = targetBranch;
let initialCommit = false; let initialCommit = false;
if (isShallow && !inputs.skipInitialFetch) { if (isShallow && !inputs.skipInitialFetch) {
core.info('Repository is shallow, fetching more history...'); core.info('Repository is shallow, fetching more history...');
if (isTag) { if (isTag) {
const sourceBranch = github.context.payload.base_ref.replace('refs/heads/', '') || let sourceBranch = '';
((_g = github.context.payload.release) === null || _g === void 0 ? void 0 : _g.target_commitish); if (github.context.payload.base_ref) {
sourceBranch = github.context.payload.base_ref.replace('refs/heads/', '');
}
else if ((_h = github.context.payload.release) === null || _h === void 0 ? void 0 : _h.target_commitish) {
sourceBranch = (_j = github.context.payload.release) === null || _j === void 0 ? void 0 : _j.target_commitish;
}
yield (0, utils_1.gitFetch)({ yield (0, utils_1.gitFetch)({
cwd: workingDirectory, cwd: workingDirectory,
args: [ args: [
@@ -815,10 +815,16 @@ const getSHAForPushEvent = (inputs, env, workingDirectory, isShallow, hasSubmodu
targetBranch = tag; targetBranch = tag;
} }
else { else {
core.debug('Getting previous SHA for last remote commit...'); if (github.context.eventName === 'merge_group') {
if (github.context.payload.forced === 'false' || core.debug('Getting previous SHA for merge group...');
!github.context.payload.forced) { previousSha = (_k = github.context.payload.merge_group) === null || _k === void 0 ? void 0 : _k.base_sha;
previousSha = github.context.payload.before; }
else {
core.debug('Getting previous SHA for last remote commit...');
if (github.context.payload.forced === 'false' ||
!github.context.payload.forced) {
previousSha = github.context.payload.before;
}
} }
if (!previousSha || if (!previousSha ||
previousSha === '0000000000000000000000000000000000000000') { previousSha === '0000000000000000000000000000000000000000') {
@@ -866,11 +872,11 @@ const getSHAForPushEvent = (inputs, env, workingDirectory, isShallow, hasSubmodu
initialCommit initialCommit
}; };
}); });
exports.getSHAForPushEvent = getSHAForPushEvent; exports.getSHAForNonPullRequestEvent = getSHAForNonPullRequestEvent;
const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, hasSubmodule, gitFetchExtraArgs) => __awaiter(void 0, void 0, void 0, function* () { const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, hasSubmodule, gitFetchExtraArgs) => __awaiter(void 0, void 0, void 0, function* () {
var _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x; var _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
let targetBranch = (_j = (_h = github.context.payload.pull_request) === null || _h === void 0 ? void 0 : _h.base) === null || _j === void 0 ? void 0 : _j.ref; let targetBranch = (_m = (_l = github.context.payload.pull_request) === null || _l === void 0 ? void 0 : _l.base) === null || _m === void 0 ? void 0 : _m.ref;
const currentBranch = (_l = (_k = github.context.payload.pull_request) === null || _k === void 0 ? void 0 : _k.head) === null || _l === void 0 ? void 0 : _l.ref; const currentBranch = (_p = (_o = github.context.payload.pull_request) === null || _o === void 0 ? void 0 : _o.head) === null || _p === void 0 ? void 0 : _p.ref;
if (inputs.sinceLastRemoteCommit) { if (inputs.sinceLastRemoteCommit) {
targetBranch = currentBranch; targetBranch = currentBranch;
} }
@@ -883,7 +889,7 @@ const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, has
'-u', '-u',
'--progress', '--progress',
'origin', 'origin',
`pull/${(_m = github.context.payload.pull_request) === null || _m === void 0 ? void 0 : _m.number}/head:${currentBranch}` `pull/${(_q = github.context.payload.pull_request) === null || _q === void 0 ? void 0 : _q.number}/head:${currentBranch}`
] ]
}); });
if (prFetchExitCode !== 0) { if (prFetchExitCode !== 0) {
@@ -948,8 +954,8 @@ const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, has
diff diff
}; };
} }
if (!((_p = (_o = github.context.payload.pull_request) === null || _o === void 0 ? void 0 : _o.base) === null || _p === void 0 ? void 0 : _p.ref) || if (!((_s = (_r = github.context.payload.pull_request) === null || _r === void 0 ? void 0 : _r.base) === null || _s === void 0 ? void 0 : _s.ref) ||
((_r = (_q = github.context.payload.head) === null || _q === void 0 ? void 0 : _q.repo) === null || _r === void 0 ? void 0 : _r.fork) === 'true') { ((_u = (_t = github.context.payload.head) === null || _t === void 0 ? void 0 : _t.repo) === null || _u === void 0 ? void 0 : _u.fork) === 'true') {
diff = '..'; diff = '..';
} }
if (!previousSha) { if (!previousSha) {
@@ -965,7 +971,7 @@ const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, has
}); });
if (!previousSha) { if (!previousSha) {
core.warning('Unable to locate the previous commit in the local history. Falling back to the pull request base sha.'); core.warning('Unable to locate the previous commit in the local history. Falling back to the pull request base sha.');
previousSha = (_t = (_s = github.context.payload.pull_request) === null || _s === void 0 ? void 0 : _s.base) === null || _t === void 0 ? void 0 : _t.sha; previousSha = (_w = (_v = github.context.payload.pull_request) === null || _v === void 0 ? void 0 : _v.base) === null || _w === void 0 ? void 0 : _w.sha;
} }
} }
} }
@@ -975,7 +981,7 @@ const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, has
branch: targetBranch branch: targetBranch
}); });
if (!previousSha) { if (!previousSha) {
previousSha = (_v = (_u = github.context.payload.pull_request) === null || _u === void 0 ? void 0 : _u.base) === null || _v === void 0 ? void 0 : _v.sha; previousSha = (_y = (_x = github.context.payload.pull_request) === null || _x === void 0 ? void 0 : _x.base) === null || _y === void 0 ? void 0 : _y.sha;
} }
if (isShallow) { if (isShallow) {
if (!(yield (0, utils_1.canDiffCommits)({ if (!(yield (0, utils_1.canDiffCommits)({
@@ -1012,7 +1018,7 @@ const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, has
} }
} }
if (!previousSha || previousSha === currentSha) { if (!previousSha || previousSha === currentSha) {
previousSha = (_x = (_w = github.context.payload.pull_request) === null || _w === void 0 ? void 0 : _w.base) === null || _x === void 0 ? void 0 : _x.sha; previousSha = (_0 = (_z = github.context.payload.pull_request) === null || _z === void 0 ? void 0 : _z.base) === null || _0 === void 0 ? void 0 : _0.sha;
} }
} }
if (!(yield (0, utils_1.canDiffCommits)({ if (!(yield (0, utils_1.canDiffCommits)({
@@ -1228,6 +1234,18 @@ const getInputs = () => {
required: false required: false
}); });
const recoverDeletedFilesToDestination = core.getInput('recover_deleted_files_to_destination', { required: false }); const recoverDeletedFilesToDestination = core.getInput('recover_deleted_files_to_destination', { required: false });
const recoverFiles = core.getInput('recover_files', { required: false });
const recoverFilesSeparator = core.getInput('recover_files_separator', {
required: false,
trimWhitespace: false
});
const recoverFilesIgnore = core.getInput('recover_files_ignore', {
required: false
});
const recoverFilesIgnoreSeparator = core.getInput('recover_files_ignore_separator', {
required: false,
trimWhitespace: false
});
const token = core.getInput('token', { required: false }); const token = core.getInput('token', { required: false });
const apiUrl = core.getInput('api_url', { required: false }); const apiUrl = core.getInput('api_url', { required: false });
const skipInitialFetch = core.getBooleanInput('skip_initial_fetch', { const skipInitialFetch = core.getBooleanInput('skip_initial_fetch', {
@@ -1260,6 +1278,10 @@ const getInputs = () => {
sinceLastRemoteCommit, sinceLastRemoteCommit,
recoverDeletedFiles, recoverDeletedFiles,
recoverDeletedFilesToDestination, recoverDeletedFilesToDestination,
recoverFiles,
recoverFilesSeparator,
recoverFilesIgnore,
recoverFilesIgnoreSeparator,
includeAllOldNewRenamedFiles, includeAllOldNewRenamedFiles,
oldNewSeparator, oldNewSeparator,
oldNewFilesSeparator, oldNewFilesSeparator,
@@ -1339,6 +1361,40 @@ const commitSha_1 = __nccwpck_require__(8613);
const env_1 = __nccwpck_require__(9763); const env_1 = __nccwpck_require__(9763);
const inputs_1 = __nccwpck_require__(6180); const inputs_1 = __nccwpck_require__(6180);
const utils_1 = __nccwpck_require__(918); const utils_1 = __nccwpck_require__(918);
const changedFilesOutput = ({ filePatterns, allDiffFiles, inputs, yamlFilePatterns }) => __awaiter(void 0, void 0, void 0, function* () {
if (filePatterns.length > 0) {
core.startGroup('changed-files-patterns');
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
allDiffFiles,
filePatterns,
inputs
});
core.info('All Done!');
core.endGroup();
}
if (Object.keys(yamlFilePatterns).length > 0) {
for (const key of Object.keys(yamlFilePatterns)) {
core.startGroup(`changed-files-yaml-${key}`);
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
allDiffFiles,
filePatterns: yamlFilePatterns[key],
outputPrefix: key,
inputs
});
core.info('All Done!');
core.endGroup();
}
}
if (filePatterns.length === 0 && Object.keys(yamlFilePatterns).length === 0) {
core.startGroup('changed-files-all');
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
allDiffFiles,
inputs
});
core.info('All Done!');
core.endGroup();
}
});
const getChangedFilesFromLocalGit = ({ inputs, env, workingDirectory, filePatterns, yamlFilePatterns }) => __awaiter(void 0, void 0, void 0, function* () { const getChangedFilesFromLocalGit = ({ inputs, env, workingDirectory, filePatterns, yamlFilePatterns }) => __awaiter(void 0, void 0, void 0, function* () {
var _a, _b, _c; var _a, _b, _c;
yield (0, utils_1.verifyMinimumGitVersion)(); yield (0, utils_1.verifyMinimumGitVersion)();
@@ -1371,7 +1427,7 @@ const getChangedFilesFromLocalGit = ({ inputs, env, workingDirectory, filePatter
let diffResult; let diffResult;
if (!((_c = (_b = github.context.payload.pull_request) === null || _b === void 0 ? void 0 : _b.base) === null || _c === void 0 ? void 0 : _c.ref)) { if (!((_c = (_b = github.context.payload.pull_request) === null || _b === void 0 ? void 0 : _b.base) === null || _c === void 0 ? void 0 : _c.ref)) {
core.info(`Running on a ${github.context.eventName || 'push'} event...`); core.info(`Running on a ${github.context.eventName || 'push'} event...`);
diffResult = yield (0, commitSha_1.getSHAForPushEvent)(inputs, env, workingDirectory, isShallow, hasSubmodule, gitFetchExtraArgs, isTag); diffResult = yield (0, commitSha_1.getSHAForNonPullRequestEvent)(inputs, env, workingDirectory, isShallow, hasSubmodule, gitFetchExtraArgs, isTag);
} }
else { else {
core.info(`Running on a ${github.context.eventName || 'pull_request'} (${github.context.payload.action}) event...`); core.info(`Running on a ${github.context.eventName || 'pull_request'} (${github.context.payload.action}) event...`);
@@ -1393,44 +1449,26 @@ const getChangedFilesFromLocalGit = ({ inputs, env, workingDirectory, filePatter
core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`); core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`);
core.info('All Done!'); core.info('All Done!');
core.endGroup(); core.endGroup();
if (filePatterns.length > 0) { if (inputs.recoverDeletedFiles) {
core.startGroup('changed-files-patterns'); let recoverPatterns = (0, utils_1.getRecoverFilePatterns)({ inputs });
yield (0, changedFilesOutput_1.setChangedFilesOutput)({ if (recoverPatterns.length > 0 && filePatterns.length > 0) {
allDiffFiles, core.info('No recover patterns found; defaulting to file patterns');
filePatterns, recoverPatterns = filePatterns;
inputs,
workingDirectory,
diffResult
});
core.info('All Done!');
core.endGroup();
}
if (Object.keys(yamlFilePatterns).length > 0) {
for (const key of Object.keys(yamlFilePatterns)) {
core.startGroup(`changed-files-yaml-${key}`);
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
allDiffFiles,
filePatterns: yamlFilePatterns[key],
outputPrefix: key,
inputs,
workingDirectory,
diffResult
});
core.info('All Done!');
core.endGroup();
} }
} yield (0, utils_1.recoverDeletedFiles)({
if (filePatterns.length === 0 && Object.keys(yamlFilePatterns).length === 0) {
core.startGroup('changed-files-all');
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
allDiffFiles,
inputs, inputs,
workingDirectory, workingDirectory,
diffResult deletedFiles: allDiffFiles[changedFiles_1.ChangeTypeEnum.Deleted],
recoverPatterns,
sha: diffResult.previousSha
}); });
core.info('All Done!');
core.endGroup();
} }
yield changedFilesOutput({
filePatterns,
allDiffFiles,
inputs,
yamlFilePatterns
});
if (inputs.includeAllOldNewRenamedFiles) { if (inputs.includeAllOldNewRenamedFiles) {
core.startGroup('changed-files-all-old-new-renamed-files'); core.startGroup('changed-files-all-old-new-renamed-files');
const allOldNewRenamedFiles = yield (0, changedFiles_1.getRenamedFiles)({ const allOldNewRenamedFiles = yield (0, changedFiles_1.getRenamedFiles)({
@@ -1455,47 +1493,18 @@ const getChangedFilesFromLocalGit = ({ inputs, env, workingDirectory, filePatter
core.endGroup(); core.endGroup();
} }
}); });
const getChangedFilesFromRESTAPI = ({ inputs, workingDirectory, filePatterns, yamlFilePatterns }) => __awaiter(void 0, void 0, void 0, function* () { const getChangedFilesFromRESTAPI = ({ inputs, filePatterns, yamlFilePatterns }) => __awaiter(void 0, void 0, void 0, function* () {
const allDiffFiles = yield (0, changedFiles_1.getChangedFilesFromGithubAPI)({ const allDiffFiles = yield (0, changedFiles_1.getChangedFilesFromGithubAPI)({
inputs inputs
}); });
core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`); core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`);
core.info('All Done!'); core.info('All Done!');
if (filePatterns.length > 0) { yield changedFilesOutput({
core.startGroup('changed-files-patterns'); filePatterns,
yield (0, changedFilesOutput_1.setChangedFilesOutput)({ allDiffFiles,
allDiffFiles, inputs,
filePatterns, yamlFilePatterns
inputs, });
workingDirectory
});
core.info('All Done!');
core.endGroup();
}
if (Object.keys(yamlFilePatterns).length > 0) {
for (const key of Object.keys(yamlFilePatterns)) {
core.startGroup(`changed-files-yaml-${key}`);
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
allDiffFiles,
filePatterns: yamlFilePatterns[key],
outputPrefix: key,
inputs,
workingDirectory
});
core.info('All Done!');
core.endGroup();
}
}
if (filePatterns.length === 0 && Object.keys(yamlFilePatterns).length === 0) {
core.startGroup('changed-files-all');
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
allDiffFiles,
inputs,
workingDirectory
});
core.info('All Done!');
core.endGroup();
}
}); });
function run() { function run() {
var _a; var _a;
@@ -1505,8 +1514,7 @@ function run() {
core.debug(`Env: ${JSON.stringify(env, null, 2)}`); core.debug(`Env: ${JSON.stringify(env, null, 2)}`);
const inputs = (0, inputs_1.getInputs)(); const inputs = (0, inputs_1.getInputs)();
core.debug(`Inputs: ${JSON.stringify(inputs, null, 2)}`); core.debug(`Inputs: ${JSON.stringify(inputs, null, 2)}`);
const githubContext = github.context; core.debug(`Github Context: ${JSON.stringify(github.context, null, 2)}`);
core.debug(`Github Context: ${JSON.stringify(githubContext, null, 2)}`);
const workingDirectory = path_1.default.resolve(env.GITHUB_WORKSPACE || process.cwd(), inputs.path); const workingDirectory = path_1.default.resolve(env.GITHUB_WORKSPACE || process.cwd(), inputs.path);
core.debug(`Working directory: ${workingDirectory}`); core.debug(`Working directory: ${workingDirectory}`);
const hasGitDirectory = yield (0, utils_1.hasLocalGitDirectory)({ workingDirectory }); const hasGitDirectory = yield (0, utils_1.hasLocalGitDirectory)({ workingDirectory });
@@ -1542,7 +1550,6 @@ function run() {
} }
yield getChangedFilesFromRESTAPI({ yield getChangedFilesFromRESTAPI({
inputs, inputs,
workingDirectory,
filePatterns, filePatterns,
yamlFilePatterns yamlFilePatterns
}); });
@@ -1635,7 +1642,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod }; return (mod && mod.__esModule) ? mod : { "default": mod };
}; };
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.hasLocalGitDirectory = exports.recoverDeletedFiles = exports.setOutput = exports.getYamlFilePatterns = exports.getFilePatterns = exports.jsonOutput = exports.getDirnameMaxDepth = exports.canDiffCommits = exports.getPreviousGitTag = exports.verifyCommitSha = exports.getParentSha = exports.getRemoteBranchHeadSha = exports.isInsideWorkTree = exports.getHeadSha = exports.gitLog = exports.getFilteredChangedFiles = exports.getAllChangedFiles = exports.gitRenamedFiles = exports.gitSubmoduleDiffSHA = exports.getSubmodulePath = exports.gitFetchSubmodules = exports.gitFetch = exports.submoduleExists = exports.isRepoShallow = exports.updateGitGlobalConfig = exports.verifyMinimumGitVersion = void 0; exports.hasLocalGitDirectory = exports.recoverDeletedFiles = exports.setOutput = exports.getRecoverFilePatterns = exports.getYamlFilePatterns = exports.getFilePatterns = exports.jsonOutput = exports.getDirnameMaxDepth = exports.canDiffCommits = exports.getPreviousGitTag = exports.verifyCommitSha = exports.getParentSha = exports.getRemoteBranchHeadSha = exports.isInsideWorkTree = exports.getHeadSha = exports.gitLog = exports.getFilteredChangedFiles = exports.getAllChangedFiles = exports.gitRenamedFiles = exports.gitSubmoduleDiffSHA = exports.getSubmodulePath = exports.gitFetchSubmodules = exports.gitFetch = exports.submoduleExists = exports.isRepoShallow = exports.updateGitGlobalConfig = exports.verifyMinimumGitVersion = exports.getDirname = exports.normalizeSeparators = exports.isWindows = void 0;
/*global AsyncIterableIterator*/ /*global AsyncIterableIterator*/
const core = __importStar(__nccwpck_require__(2186)); const core = __importStar(__nccwpck_require__(2186));
const exec = __importStar(__nccwpck_require__(1514)); const exec = __importStar(__nccwpck_require__(1514));
@@ -1647,16 +1654,19 @@ const path = __importStar(__nccwpck_require__(1017));
const readline_1 = __nccwpck_require__(4521); const readline_1 = __nccwpck_require__(4521);
const yaml_1 = __nccwpck_require__(4083); const yaml_1 = __nccwpck_require__(4083);
const changedFiles_1 = __nccwpck_require__(7358); const changedFiles_1 = __nccwpck_require__(7358);
const IS_WINDOWS = process.platform === 'win32';
const MINIMUM_GIT_VERSION = '2.18.0'; const MINIMUM_GIT_VERSION = '2.18.0';
const isWindows = () => {
return process.platform === 'win32';
};
exports.isWindows = isWindows;
/** /**
* Normalize file path separators to '/' on Windows and Linux/macOS * Normalize file path separators to '/' on Linux/macOS and '\\' on Windows
* @param p file path * @param p - file path
* @returns file path with normalized separators * @returns file path with normalized separators
*/ */
const normalizeSeparators = (p) => { const normalizeSeparators = (p) => {
// Windows // Windows
if (IS_WINDOWS) { if ((0, exports.isWindows)()) {
// Convert slashes on Windows // Convert slashes on Windows
p = p.replace(/\//g, '\\'); p = p.replace(/\//g, '\\');
// Remove redundant slashes // Remove redundant slashes
@@ -1666,9 +1676,18 @@ const normalizeSeparators = (p) => {
// Remove redundant slashes // Remove redundant slashes
return p.replace(/\/\/+/g, '/'); return p.replace(/\/\/+/g, '/');
}; };
exports.normalizeSeparators = normalizeSeparators;
/**
* Normalize file path separators to '/' on all platforms
* @param p - file path
* @returns file path with normalized separators
*/
const normalizePath = (p) => {
return p.replace(/\\/g, '/');
};
/** /**
* Trims unnecessary trailing slash from file path * Trims unnecessary trailing slash from file path
* @param p file path * @param p - file path
* @returns file path without unnecessary trailing slash * @returns file path without unnecessary trailing slash
*/ */
const safeTrimTrailingSeparator = (p) => { const safeTrimTrailingSeparator = (p) => {
@@ -1677,7 +1696,7 @@ const safeTrimTrailingSeparator = (p) => {
return ''; return '';
} }
// Normalize separators // Normalize separators
p = normalizeSeparators(p); p = (0, exports.normalizeSeparators)(p);
// No trailing slash // No trailing slash
if (!p.endsWith(path.sep)) { if (!p.endsWith(path.sep)) {
return p; return p;
@@ -1687,31 +1706,51 @@ const safeTrimTrailingSeparator = (p) => {
return p; return p;
} }
// On Windows, avoid trimming the drive root, e.g. C:\ or \\hello // On Windows, avoid trimming the drive root, e.g. C:\ or \\hello
if (IS_WINDOWS && /^[A-Z]:\\$/i.test(p)) { if ((0, exports.isWindows)() && /^[A-Z]:\\$/i.test(p)) {
return p; return p;
} }
// Trim trailing slash // Trim trailing slash
return p.substring(0, p.length - 1); return p.substring(0, p.length - 1);
}; };
const dirname = (p) => { /**
* Gets the dirname of a path, similar to the Node.js path.dirname() function except that this function
* also works for Windows UNC root paths, e.g. \\hello\world
* @param p - file path
* @returns dirname of path
*/
const getDirname = (p) => {
// Normalize slashes and trim unnecessary trailing slash // Normalize slashes and trim unnecessary trailing slash
p = safeTrimTrailingSeparator(p); p = safeTrimTrailingSeparator(p);
// Windows UNC root, e.g. \\hello or \\hello\world // Windows UNC root, e.g. \\hello or \\hello\world
if (IS_WINDOWS && /^\\\\[^\\]+(\\[^\\]+)?$/.test(p)) { if ((0, exports.isWindows)() && /^\\\\[^\\]+(\\[^\\]+)?$/.test(p)) {
return p; return p;
} }
// Get dirname // Get dirname
let result = path.dirname(p); let result = path.dirname(p);
// Trim trailing slash for Windows UNC root, e.g. \\hello\world\ // Trim trailing slash for Windows UNC root, e.g. \\hello\world\
if (IS_WINDOWS && /^\\\\[^\\]+\\[^\\]+\\$/.test(result)) { if ((0, exports.isWindows)() && /^\\\\[^\\]+\\[^\\]+\\$/.test(result)) {
result = safeTrimTrailingSeparator(result); result = safeTrimTrailingSeparator(result);
} }
return result; return result;
}; };
exports.getDirname = getDirname;
/**
* Converts the version string to a number
* @param version - version string
* @returns version number
*/
const versionToNumber = (version) => { const versionToNumber = (version) => {
const [major, minor, patch] = version.split('.').map(Number); const [major, minor, patch] = version.split('.').map(Number);
return major * 1000000 + minor * 1000 + patch; return major * 1000000 + minor * 1000 + patch;
}; };
/**
* Verifies the minimum required git version
* @returns minimum required git version
* @throws Minimum git version requirement is not met
* @throws Git is not installed
* @throws Git is not found in PATH
* @throws An unexpected error occurred
*/
const verifyMinimumGitVersion = () => __awaiter(void 0, void 0, void 0, function* () { const verifyMinimumGitVersion = () => __awaiter(void 0, void 0, void 0, function* () {
const { exitCode, stdout, stderr } = yield exec.getExecOutput('git', ['--version'], { silent: !core.isDebug() }); const { exitCode, stdout, stderr } = yield exec.getExecOutput('git', ['--version'], { silent: !core.isDebug() });
if (exitCode !== 0) { if (exitCode !== 0) {
@@ -1723,6 +1762,11 @@ const verifyMinimumGitVersion = () => __awaiter(void 0, void 0, void 0, function
} }
}); });
exports.verifyMinimumGitVersion = verifyMinimumGitVersion; exports.verifyMinimumGitVersion = verifyMinimumGitVersion;
/**
* Checks if a path exists
* @param filePath - path to check
* @returns path exists
*/
const exists = (filePath) => __awaiter(void 0, void 0, void 0, function* () { const exists = (filePath) => __awaiter(void 0, void 0, void 0, function* () {
try { try {
yield fs_1.promises.access(filePath); yield fs_1.promises.access(filePath);
@@ -1732,6 +1776,11 @@ const exists = (filePath) => __awaiter(void 0, void 0, void 0, function* () {
return false; return false;
} }
}); });
/**
* Generates lines of a file as an async iterable iterator
* @param filePath - path of file to read
* @param excludedFiles - whether to exclude files
*/
function lineOfFileGenerator({ filePath, excludedFiles }) { function lineOfFileGenerator({ filePath, excludedFiles }) {
return __asyncGenerator(this, arguments, function* lineOfFileGenerator_1() { return __asyncGenerator(this, arguments, function* lineOfFileGenerator_1() {
var _a, e_1, _b, _c; var _a, e_1, _b, _c;
@@ -1773,6 +1822,11 @@ function lineOfFileGenerator({ filePath, excludedFiles }) {
} }
}); });
} }
/**
* Gets the file patterns from a source file
* @param filePaths - paths of files to read
* @param excludedFiles - whether to exclude the file patterns
*/
const getFilesFromSourceFile = ({ filePaths, excludedFiles = false }) => __awaiter(void 0, void 0, void 0, function* () { const getFilesFromSourceFile = ({ filePaths, excludedFiles = false }) => __awaiter(void 0, void 0, void 0, function* () {
var _b, e_2, _c, _d; var _b, e_2, _c, _d;
const lines = []; const lines = [];
@@ -1795,6 +1849,12 @@ const getFilesFromSourceFile = ({ filePaths, excludedFiles = false }) => __await
} }
return lines; return lines;
}); });
/**
* Sets the global git configs
* @param name - name of config
* @param value - value of config
* @throws Couldn't update git global config
*/
const updateGitGlobalConfig = ({ name, value }) => __awaiter(void 0, void 0, void 0, function* () { const updateGitGlobalConfig = ({ name, value }) => __awaiter(void 0, void 0, void 0, function* () {
const { exitCode, stderr } = yield exec.getExecOutput('git', ['config', '--global', name, value], { const { exitCode, stderr } = yield exec.getExecOutput('git', ['config', '--global', name, value], {
ignoreReturnCode: true, ignoreReturnCode: true,
@@ -1806,6 +1866,11 @@ const updateGitGlobalConfig = ({ name, value }) => __awaiter(void 0, void 0, voi
} }
}); });
exports.updateGitGlobalConfig = updateGitGlobalConfig; exports.updateGitGlobalConfig = updateGitGlobalConfig;
/**
* Checks if a git repository is shallow
* @param cwd - working directory
* @returns repository is shallow
*/
const isRepoShallow = ({ cwd }) => __awaiter(void 0, void 0, void 0, function* () { const isRepoShallow = ({ cwd }) => __awaiter(void 0, void 0, void 0, function* () {
const { stdout } = yield exec.getExecOutput('git', ['rev-parse', '--is-shallow-repository'], { const { stdout } = yield exec.getExecOutput('git', ['rev-parse', '--is-shallow-repository'], {
cwd, cwd,
@@ -1814,6 +1879,11 @@ const isRepoShallow = ({ cwd }) => __awaiter(void 0, void 0, void 0, function* (
return stdout.trim() === 'true'; return stdout.trim() === 'true';
}); });
exports.isRepoShallow = isRepoShallow; exports.isRepoShallow = isRepoShallow;
/**
* Checks if a submodule exists
* @param cwd - working directory
* @returns submodule exists
*/
const submoduleExists = ({ cwd }) => __awaiter(void 0, void 0, void 0, function* () { const submoduleExists = ({ cwd }) => __awaiter(void 0, void 0, void 0, function* () {
const { stdout, exitCode, stderr } = yield exec.getExecOutput('git', ['submodule', 'status'], { const { stdout, exitCode, stderr } = yield exec.getExecOutput('git', ['submodule', 'status'], {
cwd, cwd,
@@ -1827,6 +1897,11 @@ const submoduleExists = ({ cwd }) => __awaiter(void 0, void 0, void 0, function*
return stdout.trim() !== ''; return stdout.trim() !== '';
}); });
exports.submoduleExists = submoduleExists; exports.submoduleExists = submoduleExists;
/**
* Fetches the git repository
* @param args - arguments for fetch command
* @param cwd - working directory
*/
const gitFetch = ({ args, cwd }) => __awaiter(void 0, void 0, void 0, function* () { const gitFetch = ({ args, cwd }) => __awaiter(void 0, void 0, void 0, function* () {
const { exitCode } = yield exec.getExecOutput('git', ['fetch', '-q', ...args], { const { exitCode } = yield exec.getExecOutput('git', ['fetch', '-q', ...args], {
cwd, cwd,
@@ -1836,6 +1911,11 @@ const gitFetch = ({ args, cwd }) => __awaiter(void 0, void 0, void 0, function*
return exitCode; return exitCode;
}); });
exports.gitFetch = gitFetch; exports.gitFetch = gitFetch;
/**
* Fetches the git repository submodules
* @param args - arguments for fetch command
* @param cwd - working directory
*/
const gitFetchSubmodules = ({ args, cwd }) => __awaiter(void 0, void 0, void 0, function* () { const gitFetchSubmodules = ({ args, cwd }) => __awaiter(void 0, void 0, void 0, function* () {
const { exitCode, stderr } = yield exec.getExecOutput('git', ['submodule', 'foreach', 'git', 'fetch', '-q', ...args], { const { exitCode, stderr } = yield exec.getExecOutput('git', ['submodule', 'foreach', 'git', 'fetch', '-q', ...args], {
cwd, cwd,
@@ -1848,9 +1928,10 @@ const gitFetchSubmodules = ({ args, cwd }) => __awaiter(void 0, void 0, void 0,
} }
}); });
exports.gitFetchSubmodules = gitFetchSubmodules; exports.gitFetchSubmodules = gitFetchSubmodules;
const normalizePath = (p) => { /**
return p.replace(/\\/g, '/'); * Retrieves all the submodule paths
}; * @param cwd - working directory
*/
const getSubmodulePath = ({ cwd }) => __awaiter(void 0, void 0, void 0, function* () { const getSubmodulePath = ({ cwd }) => __awaiter(void 0, void 0, void 0, function* () {
const { exitCode, stdout, stderr } = yield exec.getExecOutput('git', ['submodule', 'status'], { const { exitCode, stdout, stderr } = yield exec.getExecOutput('git', ['submodule', 'status'], {
cwd, cwd,
@@ -1867,9 +1948,17 @@ const getSubmodulePath = ({ cwd }) => __awaiter(void 0, void 0, void 0, function
.map((line) => normalizePath(line.trim().split(' ')[1])); .map((line) => normalizePath(line.trim().split(' ')[1]));
}); });
exports.getSubmodulePath = getSubmodulePath; exports.getSubmodulePath = getSubmodulePath;
/**
* Retrieves commit sha of a submodule from a parent commit
* @param cwd - working directory
* @param parentSha1 - parent commit sha
* @param parentSha2 - parent commit sha
* @param submodulePath - path of submodule
* @param diff - diff type between parent commits (`..` or `...`)
*/
const gitSubmoduleDiffSHA = ({ cwd, parentSha1, parentSha2, submodulePath, diff }) => __awaiter(void 0, void 0, void 0, function* () { const gitSubmoduleDiffSHA = ({ cwd, parentSha1, parentSha2, submodulePath, diff }) => __awaiter(void 0, void 0, void 0, function* () {
var _h, _j, _k, _l; var _h, _j, _k, _l;
const { stdout } = yield exec.getExecOutput('git', ['diff', parentSha1, parentSha2, '--', submodulePath], { const { stdout } = yield exec.getExecOutput('git', ['diff', `${parentSha1}${diff}${parentSha2}`, '--', submodulePath], {
cwd, cwd,
silent: !core.isDebug() silent: !core.isDebug()
}); });
@@ -1923,6 +2012,16 @@ const gitRenamedFiles = ({ cwd, sha1, sha2, diff, oldNewSeparator, isSubmodule =
}); });
}); });
exports.gitRenamedFiles = gitRenamedFiles; exports.gitRenamedFiles = gitRenamedFiles;
/**
* Retrieves all the changed files between two commits
* @param cwd - working directory
* @param sha1 - commit sha
* @param sha2 - commit sha
* @param diff - diff type between parent commits (`..` or `...`)
* @param isSubmodule - is the repo a submodule
* @param parentDir - parent directory of the submodule
* @param outputRenamedFilesAsDeletedAndAdded - output renamed files as deleted and added
*/
const getAllChangedFiles = ({ cwd, sha1, sha2, diff, isSubmodule = false, parentDir = '', outputRenamedFilesAsDeletedAndAdded = false }) => __awaiter(void 0, void 0, void 0, function* () { const getAllChangedFiles = ({ cwd, sha1, sha2, diff, isSubmodule = false, parentDir = '', outputRenamedFilesAsDeletedAndAdded = false }) => __awaiter(void 0, void 0, void 0, function* () {
const { exitCode, stdout, stderr } = yield exec.getExecOutput('git', [ const { exitCode, stdout, stderr } = yield exec.getExecOutput('git', [
'diff', 'diff',
@@ -1981,6 +2080,11 @@ const getAllChangedFiles = ({ cwd, sha1, sha2, diff, isSubmodule = false, parent
return changedFiles; return changedFiles;
}); });
exports.getAllChangedFiles = getAllChangedFiles; exports.getAllChangedFiles = getAllChangedFiles;
/**
* Filters the changed files by the file patterns
* @param allDiffFiles - all the changed files
* @param filePatterns - file patterns to filter by
*/
const getFilteredChangedFiles = ({ allDiffFiles, filePatterns }) => __awaiter(void 0, void 0, void 0, function* () { const getFilteredChangedFiles = ({ allDiffFiles, filePatterns }) => __awaiter(void 0, void 0, void 0, function* () {
const changedFiles = { const changedFiles = {
[changedFiles_1.ChangeTypeEnum.Added]: [], [changedFiles_1.ChangeTypeEnum.Added]: [],
@@ -1998,7 +2102,7 @@ const getFilteredChangedFiles = ({ allDiffFiles, filePatterns }) => __awaiter(vo
if (hasFilePatterns) { if (hasFilePatterns) {
changedFiles[changeType] = (0, micromatch_1.default)(files, filePatterns, { changedFiles[changeType] = (0, micromatch_1.default)(files, filePatterns, {
dot: true, dot: true,
windows: IS_WINDOWS, windows: (0, exports.isWindows)(),
noext: true noext: true
}); });
} }
@@ -2106,8 +2210,8 @@ const canDiffCommits = ({ cwd, sha1, sha2, diff }) => __awaiter(void 0, void 0,
return true; return true;
}); });
exports.canDiffCommits = canDiffCommits; exports.canDiffCommits = canDiffCommits;
const getDirnameMaxDepth = ({ pathStr, dirNamesMaxDepth, excludeCurrentDir }) => { const getDirnameMaxDepth = ({ relativePath, dirNamesMaxDepth, excludeCurrentDir }) => {
const pathArr = dirname(pathStr).split(path.sep); const pathArr = (0, exports.getDirname)(relativePath).split(path.sep);
const maxDepth = Math.min(dirNamesMaxDepth || pathArr.length, pathArr.length); const maxDepth = Math.min(dirNamesMaxDepth || pathArr.length, pathArr.length);
let output = pathArr[0]; let output = pathArr[0];
for (let i = 1; i < maxDepth; i++) { for (let i = 1; i < maxDepth; i++) {
@@ -2166,7 +2270,7 @@ const getFilePatterns = ({ inputs, workingDirectory }) => __awaiter(void 0, void
core.debug(`files ignore from source files patterns: ${filesIgnoreFromSourceFiles}`); core.debug(`files ignore from source files patterns: ${filesIgnoreFromSourceFiles}`);
filePatterns = filePatterns.concat('\n', filesIgnoreFromSourceFiles); filePatterns = filePatterns.concat('\n', filesIgnoreFromSourceFiles);
} }
if (IS_WINDOWS) { if ((0, exports.isWindows)()) {
filePatterns = filePatterns.replace(/\r\n/g, '\n'); filePatterns = filePatterns.replace(/\r\n/g, '\n');
filePatterns = filePatterns.replace(/\r/g, '\n'); filePatterns = filePatterns.replace(/\r/g, '\n');
} }
@@ -2208,18 +2312,18 @@ const getYamlFilePatternsFromContents = ({ content = '', filePath = '', excluded
const doc = (0, yaml_1.parseDocument)(source, { merge: true, schema: 'failsafe' }); const doc = (0, yaml_1.parseDocument)(source, { merge: true, schema: 'failsafe' });
if (doc.errors.length > 0) { if (doc.errors.length > 0) {
if (filePath) { if (filePath) {
core.warning(`YAML errors in ${filePath}: ${doc.errors}`); throw new Error(`YAML errors in ${filePath}: ${doc.errors}`);
} }
else { else {
core.warning(`YAML errors: ${doc.errors}`); throw new Error(`YAML errors: ${doc.errors}`);
} }
} }
if (doc.warnings.length > 0) { if (doc.warnings.length > 0) {
if (filePath) { if (filePath) {
core.warning(`YAML warnings in ${filePath}: ${doc.warnings}`); throw new Error(`YAML warnings in ${filePath}: ${doc.warnings}`);
} }
else { else {
core.warning(`YAML warnings: ${doc.warnings}`); throw new Error(`YAML warnings: ${doc.warnings}`);
} }
} }
const yamlObject = doc.toJS(); const yamlObject = doc.toJS();
@@ -2303,6 +2407,23 @@ const getYamlFilePatterns = ({ inputs, workingDirectory }) => __awaiter(void 0,
return filePatterns; return filePatterns;
}); });
exports.getYamlFilePatterns = getYamlFilePatterns; exports.getYamlFilePatterns = getYamlFilePatterns;
const getRecoverFilePatterns = ({ inputs }) => {
let filePatterns = inputs.recoverFiles.split(inputs.recoverFilesSeparator);
if (inputs.recoverFilesIgnore) {
const ignoreFilePatterns = inputs.recoverFilesIgnore.split(inputs.recoverFilesSeparator);
filePatterns = filePatterns.concat(ignoreFilePatterns.map(p => {
if (p.startsWith('!')) {
return p;
}
else {
return `!${p}`;
}
}));
}
core.debug(`recover file patterns: ${filePatterns}`);
return filePatterns.filter(Boolean);
};
exports.getRecoverFilePatterns = getRecoverFilePatterns;
const setOutput = ({ key, value, inputs }) => __awaiter(void 0, void 0, void 0, function* () { const setOutput = ({ key, value, inputs }) => __awaiter(void 0, void 0, void 0, function* () {
const cleanedValue = value.toString().trim(); const cleanedValue = value.toString().trim();
core.setOutput(key, cleanedValue); core.setOutput(key, cleanedValue);
@@ -2328,31 +2449,38 @@ const getDeletedFileContents = ({ cwd, filePath, sha }) => __awaiter(void 0, voi
} }
return stdout; return stdout;
}); });
const recoverDeletedFiles = ({ inputs, workingDirectory, deletedFiles, sha }) => __awaiter(void 0, void 0, void 0, function* () { const recoverDeletedFiles = ({ inputs, workingDirectory, deletedFiles, recoverPatterns, sha }) => __awaiter(void 0, void 0, void 0, function* () {
if (inputs.recoverDeletedFiles) { let recoverableDeletedFiles = deletedFiles;
for (const deletedFile of deletedFiles) { core.debug(`recoverable deleted files: ${recoverableDeletedFiles}`);
let target = path.join(workingDirectory, deletedFile); if (recoverPatterns.length > 0) {
if (inputs.recoverDeletedFilesToDestination) { recoverableDeletedFiles = (0, micromatch_1.default)(deletedFiles, recoverPatterns, {
target = path.join(workingDirectory, inputs.recoverDeletedFilesToDestination, deletedFile); dot: true,
} windows: (0, exports.isWindows)(),
const deletedFileContents = yield getDeletedFileContents({ noext: true
cwd: workingDirectory, });
filePath: deletedFile, core.debug(`filtered recoverable deleted files: ${recoverableDeletedFiles}`);
sha }
}); for (const deletedFile of recoverableDeletedFiles) {
if (!(yield exists(path.dirname(target)))) { let target = path.join(workingDirectory, deletedFile);
yield fs_1.promises.mkdir(path.dirname(target), { recursive: true }); if (inputs.recoverDeletedFilesToDestination) {
} target = path.join(workingDirectory, inputs.recoverDeletedFilesToDestination, deletedFile);
yield fs_1.promises.writeFile(target, deletedFileContents);
} }
const deletedFileContents = yield getDeletedFileContents({
cwd: workingDirectory,
filePath: deletedFile,
sha
});
if (!(yield exists(path.dirname(target)))) {
yield fs_1.promises.mkdir(path.dirname(target), { recursive: true });
}
yield fs_1.promises.writeFile(target, deletedFileContents);
} }
}); });
exports.recoverDeletedFiles = recoverDeletedFiles; exports.recoverDeletedFiles = recoverDeletedFiles;
const hasLocalGitDirectory = ({ workingDirectory }) => __awaiter(void 0, void 0, void 0, function* () { const hasLocalGitDirectory = ({ workingDirectory }) => __awaiter(void 0, void 0, void 0, function* () {
const insideWorkTree = yield (0, exports.isInsideWorkTree)({ return yield (0, exports.isInsideWorkTree)({
cwd: workingDirectory cwd: workingDirectory
}); });
return insideWorkTree;
}); });
exports.hasLocalGitDirectory = hasLocalGitDirectory; exports.hasLocalGitDirectory = hasLocalGitDirectory;

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@@ -1,7 +1,7 @@
{ {
"name": "@tj-actions/glob", "name": "@tj-actions/changed-files",
"version": "17.2.5", "version": "37.4.0",
"description": "Glob pattern matching github action", "description": "Github action to retrieve all (added, copied, modified, deleted, renamed, type changed, unmerged, unknown) files and directories.",
"main": "lib/main.js", "main": "lib/main.js",
"publishConfig": { "publishConfig": {
"registry": "https://npm.pkg.github.com" "registry": "https://npm.pkg.github.com"
@@ -18,7 +18,7 @@
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/tj-actions/glob.git" "url": "git+https://github.com/tj-actions/changed-files.git"
}, },
"keywords": [ "keywords": [
"actions", "actions",
@@ -28,9 +28,9 @@
"author": "Tonye Jack", "author": "Tonye Jack",
"license": "MIT", "license": "MIT",
"bugs": { "bugs": {
"url": "https://github.com/tj-actions/glob/issues" "url": "https://github.com/tj-actions/changed-files/issues"
}, },
"homepage": "https://github.com/tj-actions/glob#readme", "homepage": "https://github.com/tj-actions/changed-files#readme",
"dependencies": { "dependencies": {
"@actions/core": "^1.10.0", "@actions/core": "^1.10.0",
"@actions/exec": "^1.1.1", "@actions/exec": "^1.1.1",

425
src/__tests__/utils.test.ts Normal file
View File

@@ -0,0 +1,425 @@
import {ChangeTypeEnum} from '../changedFiles'
import {
getDirname,
getDirnameMaxDepth,
getFilteredChangedFiles,
normalizeSeparators
} from '../utils'
const originalPlatform = process.platform
function mockedPlatform(platform: string): void {
Object.defineProperty(process, 'platform', {
value: platform
})
}
describe('utils test', () => {
afterEach(() => {
Object.defineProperty(process, 'platform', {
value: originalPlatform
})
})
describe('getDirnameMaxDepth_function', () => {
// Tests that the function returns the correct dirname when the relative path has multiple directories
it('test_multiple_directories', () => {
const result = getDirnameMaxDepth({
relativePath: 'path/to/some/file',
dirNamesMaxDepth: 2,
excludeCurrentDir: false
})
expect(result).toEqual('path/to')
})
// Tests that the function returns the correct dirname when the relative path has only one directory
it('test_single_directory', () => {
const result = getDirnameMaxDepth({
relativePath: 'path/to',
dirNamesMaxDepth: 1,
excludeCurrentDir: false
})
expect(result).toEqual('path')
})
// Tests that the function returns the correct dirname when the relative path has no directories
it('test_no_directories', () => {
const result = getDirnameMaxDepth({
relativePath: 'file.txt',
dirNamesMaxDepth: 1,
excludeCurrentDir: false
})
expect(result).toEqual('.')
})
// Tests that the function returns the correct dirname when dirNamesMaxDepth is set to a value less than the number of directories in the relative path
it('test_dirnames_max_depth_less_than_num_directories', () => {
const result = getDirnameMaxDepth({
relativePath: 'path/to/some/file',
dirNamesMaxDepth: 1,
excludeCurrentDir: false
})
expect(result).toEqual('path')
})
// Tests that the function returns an empty string when excludeCurrentDir is true and the output is '.'
it('test_exclude_current_dir_is_true_and_output_is_dot', () => {
const result = getDirnameMaxDepth({
relativePath: '.',
dirNamesMaxDepth: 1,
excludeCurrentDir: true
})
expect(result).toEqual('')
})
// Tests that the function returns the correct dirname when the relative path is a Windows drive root and excludeCurrentDir is true
it('test_windows_drive_root_and_exclude_current_dir_is_true', () => {
const result = getDirnameMaxDepth({
relativePath: 'C:\\',
dirNamesMaxDepth: 1,
excludeCurrentDir: true
})
expect(result).toEqual('')
})
// Tests that getDirnameMaxDepth handles a relative path with a trailing separator correctly
it('test_trailing_separator', () => {
const input = {
relativePath: 'path/to/dir/',
dirNamesMaxDepth: 2,
excludeCurrentDir: true
}
const expectedOutput = 'path/to'
const actualOutput = getDirnameMaxDepth(input)
expect(actualOutput).toEqual(expectedOutput)
})
// Tests that getDirnameMaxDepth returns an empty string when excludeCurrentDir is true and the output is '.'
it('test_trailing_separator_exclude_current_dir', () => {
const input = {
relativePath: 'file',
excludeCurrentDir: true
}
const expectedOutput = ''
const actualOutput = getDirnameMaxDepth(input)
expect(actualOutput).toEqual(expectedOutput)
})
// Tests that getDirnameMaxDepth returns the correct output for a Windows UNC root path
it('test_windows_unc_root', () => {
const input = {
relativePath: '\\hello',
dirNamesMaxDepth: 2,
excludeCurrentDir: true
}
const expectedOutput = ''
expect(getDirnameMaxDepth(input)).toEqual(expectedOutput)
})
// Tests that getDirnameMaxDepth returns an empty string when given a Windows UNC root and excludeCurrentDir is true
it('test_windows_unc_root_exclude_current_dir', () => {
const relativePath = '\\hello'
const result = getDirnameMaxDepth({
relativePath,
excludeCurrentDir: true
})
expect(result).toEqual('')
})
// Tests that getDirnameMaxDepth returns the correct dirname with a relative path that contains both forward and backward slashes
it('test_relative_path_with_slashes', () => {
const relativePath = 'path/to\file'
const expectedOutput = 'path'
const actualOutput = getDirnameMaxDepth({relativePath})
expect(actualOutput).toEqual(expectedOutput)
})
// Tests that getDirnameMaxDepth returns the correct dirname for a relative path that contains special characters
it('test_special_characters', () => {
const relativePath =
'path/with/special/characters/!@#$%^&*()_+{}|:<>?[];,./'
const expectedDirname = 'path/with/special/characters'
const actualDirname = getDirnameMaxDepth({relativePath})
expect(actualDirname).toEqual(expectedDirname)
})
})
describe('getDirname_function', () => {
// Tests that the function returns the correct dirname for a valid path
it('test valid path', () => {
expect(getDirname('/path/to/file')).toEqual('/path/to')
})
// Tests that the function returns the correct dirname for a valid Windows UNC root path
it('test windows unc root path', () => {
expect(getDirname('\\helloworld')).toEqual('.')
})
// Tests that the function returns the correct dirname for a path with a trailing slash
it('test path with trailing slash', () => {
expect(getDirname('/path/to/file/')).toEqual('/path/to')
})
// Tests that the function returns the correct dirname for a Windows UNC root path with a trailing slash
it('test windows unc root path with trailing slash', () => {
expect(getDirname('\\hello\\world\\')).toEqual('.')
})
// Tests that the function returns the correct dirname for a path with multiple slashes
it('test path with multiple slashes', () => {
expect(getDirname('/path//to/file')).toEqual('/path/to')
})
// Tests that the function returns the correct dirname for a Windows UNC root path with multiple slashes
it('test windows unc root path with multiple slashes', () => {
expect(getDirname('\\hello\\world')).toEqual('.')
})
})
describe('normalizeSeparators_function', () => {
// Tests that forward slashes are normalized on Linux
it('test forward slashes linux', () => {
const input = 'path/to/file'
const expectedOutput = 'path/to/file'
const actualOutput = normalizeSeparators(input)
expect(actualOutput).toEqual(expectedOutput)
})
// Tests that backslashes are normalized on Windows
it('test backslashes windows', () => {
mockedPlatform('win32')
const input = 'path\\to\\file'
const expectedOutput = 'path\\to\\file'
const actualOutput = normalizeSeparators(input)
expect(actualOutput).toEqual(expectedOutput)
})
// Tests that mixed slashes are normalized on Windows
it('test mixed slashes windows', () => {
mockedPlatform('win32')
const input = 'path\\to/file'
const expectedOutput = 'path\\to\\file'
const actualOutput = normalizeSeparators(input)
expect(actualOutput).toEqual(expectedOutput)
})
// Tests that an empty string returns an empty string
it('test empty string', () => {
const input = ''
const expectedOutput = ''
const actualOutput = normalizeSeparators(input)
expect(actualOutput).toEqual(expectedOutput)
})
// Tests that multiple consecutive slashes are removed
it('test multiple consecutive slashes', () => {
const input = 'path//to//file'
const expectedOutput = 'path/to/file'
const actualOutput = normalizeSeparators(input)
expect(actualOutput).toEqual(expectedOutput)
})
// Tests that UNC format is preserved on Windows
it('test unc format windows', () => {
const input = '\\\\hello\\world'
const expectedOutput = '\\\\hello\\world'
const actualOutput = normalizeSeparators(input)
expect(actualOutput).toEqual(expectedOutput)
})
// Tests that a drive root is preserved on Windows
it('test drive root windows', () => {
const input = 'C:\\'
const expectedOutput = 'C:\\'
const actualOutput = normalizeSeparators(input)
expect(actualOutput).toEqual(expectedOutput)
})
})
// Generated by CodiumAI
describe('getFilteredChangedFiles', () => {
// Tests that the function returns an empty object when allDiffFiles and filePatterns are empty
it('should return an empty object when allDiffFiles and filePatterns are empty', async () => {
const result = await getFilteredChangedFiles({
allDiffFiles: {
[ChangeTypeEnum.Added]: [],
[ChangeTypeEnum.Copied]: [],
[ChangeTypeEnum.Deleted]: [],
[ChangeTypeEnum.Modified]: [],
[ChangeTypeEnum.Renamed]: [],
[ChangeTypeEnum.TypeChanged]: [],
[ChangeTypeEnum.Unmerged]: [],
[ChangeTypeEnum.Unknown]: []
},
filePatterns: []
})
expect(result).toEqual({
[ChangeTypeEnum.Added]: [],
[ChangeTypeEnum.Copied]: [],
[ChangeTypeEnum.Deleted]: [],
[ChangeTypeEnum.Modified]: [],
[ChangeTypeEnum.Renamed]: [],
[ChangeTypeEnum.TypeChanged]: [],
[ChangeTypeEnum.Unmerged]: [],
[ChangeTypeEnum.Unknown]: []
})
})
// Tests that the function returns allDiffFiles when filePatterns is empty
it('should return allDiffFiles when filePatterns is empty', async () => {
const allDiffFiles = {
[ChangeTypeEnum.Added]: ['file1.txt'],
[ChangeTypeEnum.Copied]: [],
[ChangeTypeEnum.Deleted]: [],
[ChangeTypeEnum.Modified]: [],
[ChangeTypeEnum.Renamed]: [],
[ChangeTypeEnum.TypeChanged]: [],
[ChangeTypeEnum.Unmerged]: [],
[ChangeTypeEnum.Unknown]: []
}
const result = await getFilteredChangedFiles({
allDiffFiles,
filePatterns: []
})
expect(result).toEqual(allDiffFiles)
})
// Tests that the function returns an empty object when allDiffFiles is empty
it('should return an empty object when allDiffFiles is empty', async () => {
const result = await getFilteredChangedFiles({
allDiffFiles: {
[ChangeTypeEnum.Added]: [],
[ChangeTypeEnum.Copied]: [],
[ChangeTypeEnum.Deleted]: [],
[ChangeTypeEnum.Modified]: [],
[ChangeTypeEnum.Renamed]: [],
[ChangeTypeEnum.TypeChanged]: [],
[ChangeTypeEnum.Unmerged]: [],
[ChangeTypeEnum.Unknown]: []
},
filePatterns: ['*.txt']
})
expect(result).toEqual({
[ChangeTypeEnum.Added]: [],
[ChangeTypeEnum.Copied]: [],
[ChangeTypeEnum.Deleted]: [],
[ChangeTypeEnum.Modified]: [],
[ChangeTypeEnum.Renamed]: [],
[ChangeTypeEnum.TypeChanged]: [],
[ChangeTypeEnum.Unmerged]: [],
[ChangeTypeEnum.Unknown]: []
})
})
// Tests that the function returns only the files that match the file patterns
it('should return only the files that match the file patterns', async () => {
const allDiffFiles = {
[ChangeTypeEnum.Added]: ['file1.txt', 'file2.md', 'file3.txt'],
[ChangeTypeEnum.Copied]: [],
[ChangeTypeEnum.Deleted]: [],
[ChangeTypeEnum.Modified]: [],
[ChangeTypeEnum.Renamed]: [],
[ChangeTypeEnum.TypeChanged]: [],
[ChangeTypeEnum.Unmerged]: [],
[ChangeTypeEnum.Unknown]: []
}
const result = await getFilteredChangedFiles({
allDiffFiles,
filePatterns: ['*.txt']
})
expect(result).toEqual({
[ChangeTypeEnum.Added]: ['file1.txt', 'file3.txt'],
[ChangeTypeEnum.Copied]: [],
[ChangeTypeEnum.Deleted]: [],
[ChangeTypeEnum.Modified]: [],
[ChangeTypeEnum.Renamed]: [],
[ChangeTypeEnum.TypeChanged]: [],
[ChangeTypeEnum.Unmerged]: [],
[ChangeTypeEnum.Unknown]: []
})
})
// Tests that the function returns an empty object when there are no files that match the file patterns
it('should return an empty object when there are no files that match the file patterns', async () => {
const allDiffFiles = {
[ChangeTypeEnum.Added]: ['file1.md', 'file2.md', 'file3.md'],
[ChangeTypeEnum.Copied]: [],
[ChangeTypeEnum.Deleted]: [],
[ChangeTypeEnum.Modified]: [],
[ChangeTypeEnum.Renamed]: [],
[ChangeTypeEnum.TypeChanged]: [],
[ChangeTypeEnum.Unmerged]: [],
[ChangeTypeEnum.Unknown]: []
}
const result = await getFilteredChangedFiles({
allDiffFiles,
filePatterns: ['*.txt']
})
expect(result).toEqual({
[ChangeTypeEnum.Added]: [],
[ChangeTypeEnum.Copied]: [],
[ChangeTypeEnum.Deleted]: [],
[ChangeTypeEnum.Modified]: [],
[ChangeTypeEnum.Renamed]: [],
[ChangeTypeEnum.TypeChanged]: [],
[ChangeTypeEnum.Unmerged]: [],
[ChangeTypeEnum.Unknown]: []
})
})
// Tests that the function can handle file names with special characters
it('should handle file names with special characters', async () => {
const allDiffFiles = {
[ChangeTypeEnum.Added]: [
'file1.txt',
'file2 with spaces.txt',
'file3$$.txt'
],
[ChangeTypeEnum.Copied]: [],
[ChangeTypeEnum.Deleted]: [],
[ChangeTypeEnum.Modified]: [],
[ChangeTypeEnum.Renamed]: [],
[ChangeTypeEnum.TypeChanged]: [],
[ChangeTypeEnum.Unmerged]: [],
[ChangeTypeEnum.Unknown]: []
}
const result = await getFilteredChangedFiles({
allDiffFiles,
filePatterns: ['file2*.txt']
})
expect(result).toEqual({
[ChangeTypeEnum.Added]: ['file2 with spaces.txt'],
[ChangeTypeEnum.Copied]: [],
[ChangeTypeEnum.Deleted]: [],
[ChangeTypeEnum.Modified]: [],
[ChangeTypeEnum.Renamed]: [],
[ChangeTypeEnum.TypeChanged]: [],
[ChangeTypeEnum.Unmerged]: [],
[ChangeTypeEnum.Unknown]: []
})
})
// Tests that getFilteredChangedFiles correctly filters files using glob patterns
it('should filter files using glob patterns', async () => {
const allDiffFiles = {
[ChangeTypeEnum.Added]: ['test/migrations/test.sql'],
[ChangeTypeEnum.Copied]: [],
[ChangeTypeEnum.Deleted]: [],
[ChangeTypeEnum.Modified]: [],
[ChangeTypeEnum.Renamed]: [],
[ChangeTypeEnum.TypeChanged]: [],
[ChangeTypeEnum.Unmerged]: [],
[ChangeTypeEnum.Unknown]: []
}
const filePatterns = ['test/migrations/**']
const filteredFiles = await getFilteredChangedFiles({
allDiffFiles,
filePatterns
})
expect(filteredFiles[ChangeTypeEnum.Added]).toEqual([
'test/migrations/test.sql'
])
})
})
})

View File

@@ -166,15 +166,15 @@ function* getChangeTypeFilesGenerator({
}): Generator<string> { }): Generator<string> {
for (const changeType of changeTypes) { for (const changeType of changeTypes) {
const files = changedFiles[changeType] || [] const files = changedFiles[changeType] || []
for (const file of files) { for (const filePath of files) {
if (inputs.dirNames) { if (inputs.dirNames) {
yield getDirnameMaxDepth({ yield getDirnameMaxDepth({
pathStr: file, relativePath: filePath,
dirNamesMaxDepth: inputs.dirNamesMaxDepth, dirNamesMaxDepth: inputs.dirNamesMaxDepth,
excludeCurrentDir: inputs.dirNamesExcludeCurrentDir excludeCurrentDir: inputs.dirNamesExcludeCurrentDir
}) })
} else { } else {
yield file yield filePath
} }
} }
} }
@@ -213,15 +213,15 @@ function* getAllChangeTypeFilesGenerator({
inputs: Inputs inputs: Inputs
changedFiles: ChangedFiles changedFiles: ChangedFiles
}): Generator<string> { }): Generator<string> {
for (const file of flatten(Object.values(changedFiles))) { for (const filePath of flatten(Object.values(changedFiles))) {
if (inputs.dirNames) { if (inputs.dirNames) {
yield getDirnameMaxDepth({ yield getDirnameMaxDepth({
pathStr: file, relativePath: filePath,
dirNamesMaxDepth: inputs.dirNamesMaxDepth, dirNamesMaxDepth: inputs.dirNamesMaxDepth,
excludeCurrentDir: inputs.dirNamesExcludeCurrentDir excludeCurrentDir: inputs.dirNamesExcludeCurrentDir
}) })
} else { } else {
yield file yield filePath
} }
} }
} }

View File

@@ -5,9 +5,8 @@ import {
getAllChangeTypeFiles, getAllChangeTypeFiles,
getChangeTypeFiles getChangeTypeFiles
} from './changedFiles' } from './changedFiles'
import {DiffResult} from './commitSha'
import {Inputs} from './inputs' import {Inputs} from './inputs'
import {getFilteredChangedFiles, recoverDeletedFiles, setOutput} from './utils' import {getFilteredChangedFiles, setOutput} from './utils'
const getOutputKey = (key: string, outputPrefix: string): string => { const getOutputKey = (key: string, outputPrefix: string): string => {
return outputPrefix ? `${outputPrefix}_${key}` : key return outputPrefix ? `${outputPrefix}_${key}` : key
@@ -16,15 +15,11 @@ const getOutputKey = (key: string, outputPrefix: string): string => {
export const setChangedFilesOutput = async ({ export const setChangedFilesOutput = async ({
allDiffFiles, allDiffFiles,
inputs, inputs,
workingDirectory,
diffResult,
filePatterns = [], filePatterns = [],
outputPrefix = '' outputPrefix = ''
}: { }: {
allDiffFiles: ChangedFiles allDiffFiles: ChangedFiles
inputs: Inputs inputs: Inputs
workingDirectory: string
diffResult?: DiffResult
filePatterns?: string[] filePatterns?: string[]
outputPrefix?: string outputPrefix?: string
}): Promise<void> => { }): Promise<void> => {
@@ -34,15 +29,6 @@ export const setChangedFilesOutput = async ({
}) })
core.debug(`All filtered diff files: ${JSON.stringify(allFilteredDiffFiles)}`) core.debug(`All filtered diff files: ${JSON.stringify(allFilteredDiffFiles)}`)
if (diffResult) {
await recoverDeletedFiles({
inputs,
workingDirectory,
deletedFiles: allFilteredDiffFiles[ChangeTypeEnum.Deleted],
sha: diffResult.previousSha
})
}
const addedFiles = await getChangeTypeFiles({ const addedFiles = await getChangeTypeFiles({
inputs, inputs,
changedFiles: allFilteredDiffFiles, changedFiles: allFilteredDiffFiles,

View File

@@ -57,6 +57,8 @@ const getCurrentSHA = async ({
})) === 0 })) === 0
) { ) {
currentSha = github.context.payload.pull_request?.head?.sha currentSha = github.context.payload.pull_request?.head?.sha
} else if (github.context.eventName === 'merge_group') {
currentSha = github.context.payload.merge_group?.head_sha
} else { } else {
currentSha = await getHeadSha({cwd: workingDirectory}) currentSha = await getHeadSha({cwd: workingDirectory})
} }
@@ -78,7 +80,7 @@ export interface DiffResult {
initialCommit?: boolean initialCommit?: boolean
} }
export const getSHAForPushEvent = async ( export const getSHAForNonPullRequestEvent = async (
inputs: Inputs, inputs: Inputs,
env: Env, env: Env,
workingDirectory: string, workingDirectory: string,
@@ -95,9 +97,17 @@ export const getSHAForPushEvent = async (
core.info('Repository is shallow, fetching more history...') core.info('Repository is shallow, fetching more history...')
if (isTag) { if (isTag) {
const sourceBranch = let sourceBranch = ''
github.context.payload.base_ref.replace('refs/heads/', '') ||
github.context.payload.release?.target_commitish if (github.context.payload.base_ref) {
sourceBranch = github.context.payload.base_ref.replace(
'refs/heads/',
''
)
} else if (github.context.payload.release?.target_commitish) {
sourceBranch = github.context.payload.release?.target_commitish
}
await gitFetch({ await gitFetch({
cwd: workingDirectory, cwd: workingDirectory,
args: [ args: [
@@ -189,12 +199,17 @@ export const getSHAForPushEvent = async (
previousSha = sha previousSha = sha
targetBranch = tag targetBranch = tag
} else { } else {
core.debug('Getting previous SHA for last remote commit...') if (github.context.eventName === 'merge_group') {
if ( core.debug('Getting previous SHA for merge group...')
github.context.payload.forced === 'false' || previousSha = github.context.payload.merge_group?.base_sha
!github.context.payload.forced } else {
) { core.debug('Getting previous SHA for last remote commit...')
previousSha = github.context.payload.before if (
github.context.payload.forced === 'false' ||
!github.context.payload.forced
) {
previousSha = github.context.payload.before
}
} }
if ( if (

View File

@@ -38,6 +38,10 @@ export type Inputs = {
outputRenamedFilesAsDeletedAndAdded: boolean outputRenamedFilesAsDeletedAndAdded: boolean
recoverDeletedFiles: boolean recoverDeletedFiles: boolean
recoverDeletedFilesToDestination: string recoverDeletedFilesToDestination: string
recoverFiles: string
recoverFilesSeparator: string
recoverFilesIgnore: string
recoverFilesIgnoreSeparator: string
token: string token: string
apiUrl: string apiUrl: string
skipInitialFetch: boolean skipInitialFetch: boolean
@@ -153,6 +157,21 @@ export const getInputs = (): Inputs => {
'recover_deleted_files_to_destination', 'recover_deleted_files_to_destination',
{required: false} {required: false}
) )
const recoverFiles = core.getInput('recover_files', {required: false})
const recoverFilesSeparator = core.getInput('recover_files_separator', {
required: false,
trimWhitespace: false
})
const recoverFilesIgnore = core.getInput('recover_files_ignore', {
required: false
})
const recoverFilesIgnoreSeparator = core.getInput(
'recover_files_ignore_separator',
{
required: false,
trimWhitespace: false
}
)
const token = core.getInput('token', {required: false}) const token = core.getInput('token', {required: false})
const apiUrl = core.getInput('api_url', {required: false}) const apiUrl = core.getInput('api_url', {required: false})
const skipInitialFetch = core.getBooleanInput('skip_initial_fetch', { const skipInitialFetch = core.getBooleanInput('skip_initial_fetch', {
@@ -186,6 +205,10 @@ export const getInputs = (): Inputs => {
sinceLastRemoteCommit, sinceLastRemoteCommit,
recoverDeletedFiles, recoverDeletedFiles,
recoverDeletedFilesToDestination, recoverDeletedFilesToDestination,
recoverFiles,
recoverFilesSeparator,
recoverFilesIgnore,
recoverFilesIgnoreSeparator,
includeAllOldNewRenamedFiles, includeAllOldNewRenamedFiles,
oldNewSeparator, oldNewSeparator,
oldNewFilesSeparator, oldNewFilesSeparator,

View File

@@ -2,6 +2,8 @@ import * as core from '@actions/core'
import * as github from '@actions/github' import * as github from '@actions/github'
import path from 'path' import path from 'path'
import { import {
ChangedFiles,
ChangeTypeEnum,
getAllDiffFiles, getAllDiffFiles,
getChangedFilesFromGithubAPI, getChangedFilesFromGithubAPI,
getRenamedFiles getRenamedFiles
@@ -10,22 +12,71 @@ import {setChangedFilesOutput} from './changedFilesOutput'
import { import {
DiffResult, DiffResult,
getSHAForPullRequestEvent, getSHAForPullRequestEvent,
getSHAForPushEvent getSHAForNonPullRequestEvent
} from './commitSha' } from './commitSha'
import {Env, getEnv} from './env' import {Env, getEnv} from './env'
import {getInputs, Inputs} from './inputs' import {getInputs, Inputs} from './inputs'
import { import {
getFilePatterns, getFilePatterns,
getRecoverFilePatterns,
getSubmodulePath, getSubmodulePath,
getYamlFilePatterns, getYamlFilePatterns,
hasLocalGitDirectory, hasLocalGitDirectory,
isRepoShallow, isRepoShallow,
recoverDeletedFiles,
setOutput, setOutput,
submoduleExists, submoduleExists,
updateGitGlobalConfig, updateGitGlobalConfig,
verifyMinimumGitVersion verifyMinimumGitVersion
} from './utils' } from './utils'
const changedFilesOutput = async ({
filePatterns,
allDiffFiles,
inputs,
yamlFilePatterns
}: {
filePatterns: string[]
allDiffFiles: ChangedFiles
inputs: Inputs
yamlFilePatterns: Record<string, string[]>
}): Promise<void> => {
if (filePatterns.length > 0) {
core.startGroup('changed-files-patterns')
await setChangedFilesOutput({
allDiffFiles,
filePatterns,
inputs
})
core.info('All Done!')
core.endGroup()
}
if (Object.keys(yamlFilePatterns).length > 0) {
for (const key of Object.keys(yamlFilePatterns)) {
core.startGroup(`changed-files-yaml-${key}`)
await setChangedFilesOutput({
allDiffFiles,
filePatterns: yamlFilePatterns[key],
outputPrefix: key,
inputs
})
core.info('All Done!')
core.endGroup()
}
}
if (filePatterns.length === 0 && Object.keys(yamlFilePatterns).length === 0) {
core.startGroup('changed-files-all')
await setChangedFilesOutput({
allDiffFiles,
inputs
})
core.info('All Done!')
core.endGroup()
}
}
const getChangedFilesFromLocalGit = async ({ const getChangedFilesFromLocalGit = async ({
inputs, inputs,
env, env,
@@ -79,7 +130,7 @@ const getChangedFilesFromLocalGit = async ({
if (!github.context.payload.pull_request?.base?.ref) { if (!github.context.payload.pull_request?.base?.ref) {
core.info(`Running on a ${github.context.eventName || 'push'} event...`) core.info(`Running on a ${github.context.eventName || 'push'} event...`)
diffResult = await getSHAForPushEvent( diffResult = await getSHAForNonPullRequestEvent(
inputs, inputs,
env, env,
workingDirectory, workingDirectory,
@@ -125,47 +176,30 @@ const getChangedFilesFromLocalGit = async ({
core.info('All Done!') core.info('All Done!')
core.endGroup() core.endGroup()
if (filePatterns.length > 0) { if (inputs.recoverDeletedFiles) {
core.startGroup('changed-files-patterns') let recoverPatterns = getRecoverFilePatterns({inputs})
await setChangedFilesOutput({
allDiffFiles,
filePatterns,
inputs,
workingDirectory,
diffResult
})
core.info('All Done!')
core.endGroup()
}
if (Object.keys(yamlFilePatterns).length > 0) { if (recoverPatterns.length > 0 && filePatterns.length > 0) {
for (const key of Object.keys(yamlFilePatterns)) { core.info('No recover patterns found; defaulting to file patterns')
core.startGroup(`changed-files-yaml-${key}`) recoverPatterns = filePatterns
await setChangedFilesOutput({
allDiffFiles,
filePatterns: yamlFilePatterns[key],
outputPrefix: key,
inputs,
workingDirectory,
diffResult
})
core.info('All Done!')
core.endGroup()
} }
}
if (filePatterns.length === 0 && Object.keys(yamlFilePatterns).length === 0) { await recoverDeletedFiles({
core.startGroup('changed-files-all')
await setChangedFilesOutput({
allDiffFiles,
inputs, inputs,
workingDirectory, workingDirectory,
diffResult deletedFiles: allDiffFiles[ChangeTypeEnum.Deleted],
recoverPatterns,
sha: diffResult.previousSha
}) })
core.info('All Done!')
core.endGroup()
} }
await changedFilesOutput({
filePatterns,
allDiffFiles,
inputs,
yamlFilePatterns
})
if (inputs.includeAllOldNewRenamedFiles) { if (inputs.includeAllOldNewRenamedFiles) {
core.startGroup('changed-files-all-old-new-renamed-files') core.startGroup('changed-files-all-old-new-renamed-files')
const allOldNewRenamedFiles = await getRenamedFiles({ const allOldNewRenamedFiles = await getRenamedFiles({
@@ -193,12 +227,10 @@ const getChangedFilesFromLocalGit = async ({
const getChangedFilesFromRESTAPI = async ({ const getChangedFilesFromRESTAPI = async ({
inputs, inputs,
workingDirectory,
filePatterns, filePatterns,
yamlFilePatterns yamlFilePatterns
}: { }: {
inputs: Inputs inputs: Inputs
workingDirectory: string
filePatterns: string[] filePatterns: string[]
yamlFilePatterns: Record<string, string[]> yamlFilePatterns: Record<string, string[]>
}): Promise<void> => { }): Promise<void> => {
@@ -208,43 +240,12 @@ const getChangedFilesFromRESTAPI = async ({
core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`) core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`)
core.info('All Done!') core.info('All Done!')
if (filePatterns.length > 0) { await changedFilesOutput({
core.startGroup('changed-files-patterns') filePatterns,
await setChangedFilesOutput({ allDiffFiles,
allDiffFiles, inputs,
filePatterns, yamlFilePatterns
inputs, })
workingDirectory
})
core.info('All Done!')
core.endGroup()
}
if (Object.keys(yamlFilePatterns).length > 0) {
for (const key of Object.keys(yamlFilePatterns)) {
core.startGroup(`changed-files-yaml-${key}`)
await setChangedFilesOutput({
allDiffFiles,
filePatterns: yamlFilePatterns[key],
outputPrefix: key,
inputs,
workingDirectory
})
core.info('All Done!')
core.endGroup()
}
}
if (filePatterns.length === 0 && Object.keys(yamlFilePatterns).length === 0) {
core.startGroup('changed-files-all')
await setChangedFilesOutput({
allDiffFiles,
inputs,
workingDirectory
})
core.info('All Done!')
core.endGroup()
}
} }
export async function run(): Promise<void> { export async function run(): Promise<void> {
@@ -256,8 +257,7 @@ export async function run(): Promise<void> {
const inputs = getInputs() const inputs = getInputs()
core.debug(`Inputs: ${JSON.stringify(inputs, null, 2)}`) core.debug(`Inputs: ${JSON.stringify(inputs, null, 2)}`)
const githubContext = github.context core.debug(`Github Context: ${JSON.stringify(github.context, null, 2)}`)
core.debug(`Github Context: ${JSON.stringify(githubContext, null, 2)}`)
const workingDirectory = path.resolve( const workingDirectory = path.resolve(
env.GITHUB_WORKSPACE || process.cwd(), env.GITHUB_WORKSPACE || process.cwd(),
@@ -306,7 +306,6 @@ export async function run(): Promise<void> {
} }
await getChangedFilesFromRESTAPI({ await getChangedFilesFromRESTAPI({
inputs, inputs,
workingDirectory,
filePatterns, filePatterns,
yamlFilePatterns yamlFilePatterns
}) })

View File

@@ -12,17 +12,20 @@ import {ChangedFiles, ChangeTypeEnum} from './changedFiles'
import {Inputs} from './inputs' import {Inputs} from './inputs'
const IS_WINDOWS = process.platform === 'win32'
const MINIMUM_GIT_VERSION = '2.18.0' const MINIMUM_GIT_VERSION = '2.18.0'
export const isWindows = (): boolean => {
return process.platform === 'win32'
}
/** /**
* Normalize file path separators to '/' on Windows and Linux/macOS * Normalize file path separators to '/' on Linux/macOS and '\\' on Windows
* @param p file path * @param p - file path
* @returns file path with normalized separators * @returns file path with normalized separators
*/ */
const normalizeSeparators = (p: string): string => { export const normalizeSeparators = (p: string): string => {
// Windows // Windows
if (IS_WINDOWS) { if (isWindows()) {
// Convert slashes on Windows // Convert slashes on Windows
p = p.replace(/\//g, '\\') p = p.replace(/\//g, '\\')
@@ -35,9 +38,18 @@ const normalizeSeparators = (p: string): string => {
return p.replace(/\/\/+/g, '/') return p.replace(/\/\/+/g, '/')
} }
/**
* Normalize file path separators to '/' on all platforms
* @param p - file path
* @returns file path with normalized separators
*/
const normalizePath = (p: string): string => {
return p.replace(/\\/g, '/')
}
/** /**
* Trims unnecessary trailing slash from file path * Trims unnecessary trailing slash from file path
* @param p file path * @param p - file path
* @returns file path without unnecessary trailing slash * @returns file path without unnecessary trailing slash
*/ */
const safeTrimTrailingSeparator = (p: string): string => { const safeTrimTrailingSeparator = (p: string): string => {
@@ -60,7 +72,7 @@ const safeTrimTrailingSeparator = (p: string): string => {
} }
// On Windows, avoid trimming the drive root, e.g. C:\ or \\hello // On Windows, avoid trimming the drive root, e.g. C:\ or \\hello
if (IS_WINDOWS && /^[A-Z]:\\$/i.test(p)) { if (isWindows() && /^[A-Z]:\\$/i.test(p)) {
return p return p
} }
@@ -68,12 +80,18 @@ const safeTrimTrailingSeparator = (p: string): string => {
return p.substring(0, p.length - 1) return p.substring(0, p.length - 1)
} }
const dirname = (p: string): string => { /**
* Gets the dirname of a path, similar to the Node.js path.dirname() function except that this function
* also works for Windows UNC root paths, e.g. \\hello\world
* @param p - file path
* @returns dirname of path
*/
export const getDirname = (p: string): string => {
// Normalize slashes and trim unnecessary trailing slash // Normalize slashes and trim unnecessary trailing slash
p = safeTrimTrailingSeparator(p) p = safeTrimTrailingSeparator(p)
// Windows UNC root, e.g. \\hello or \\hello\world // Windows UNC root, e.g. \\hello or \\hello\world
if (IS_WINDOWS && /^\\\\[^\\]+(\\[^\\]+)?$/.test(p)) { if (isWindows() && /^\\\\[^\\]+(\\[^\\]+)?$/.test(p)) {
return p return p
} }
@@ -81,18 +99,31 @@ const dirname = (p: string): string => {
let result = path.dirname(p) let result = path.dirname(p)
// Trim trailing slash for Windows UNC root, e.g. \\hello\world\ // Trim trailing slash for Windows UNC root, e.g. \\hello\world\
if (IS_WINDOWS && /^\\\\[^\\]+\\[^\\]+\\$/.test(result)) { if (isWindows() && /^\\\\[^\\]+\\[^\\]+\\$/.test(result)) {
result = safeTrimTrailingSeparator(result) result = safeTrimTrailingSeparator(result)
} }
return result return result
} }
/**
* Converts the version string to a number
* @param version - version string
* @returns version number
*/
const versionToNumber = (version: string): number => { const versionToNumber = (version: string): number => {
const [major, minor, patch] = version.split('.').map(Number) const [major, minor, patch] = version.split('.').map(Number)
return major * 1000000 + minor * 1000 + patch return major * 1000000 + minor * 1000 + patch
} }
/**
* Verifies the minimum required git version
* @returns minimum required git version
* @throws Minimum git version requirement is not met
* @throws Git is not installed
* @throws Git is not found in PATH
* @throws An unexpected error occurred
*/
export const verifyMinimumGitVersion = async (): Promise<void> => { export const verifyMinimumGitVersion = async (): Promise<void> => {
const {exitCode, stdout, stderr} = await exec.getExecOutput( const {exitCode, stdout, stderr} = await exec.getExecOutput(
'git', 'git',
@@ -113,6 +144,11 @@ export const verifyMinimumGitVersion = async (): Promise<void> => {
} }
} }
/**
* Checks if a path exists
* @param filePath - path to check
* @returns path exists
*/
const exists = async (filePath: string): Promise<boolean> => { const exists = async (filePath: string): Promise<boolean> => {
try { try {
await fs.access(filePath) await fs.access(filePath)
@@ -122,6 +158,11 @@ const exists = async (filePath: string): Promise<boolean> => {
} }
} }
/**
* Generates lines of a file as an async iterable iterator
* @param filePath - path of file to read
* @param excludedFiles - whether to exclude files
*/
async function* lineOfFileGenerator({ async function* lineOfFileGenerator({
filePath, filePath,
excludedFiles excludedFiles
@@ -153,6 +194,11 @@ async function* lineOfFileGenerator({
} }
} }
/**
* Gets the file patterns from a source file
* @param filePaths - paths of files to read
* @param excludedFiles - whether to exclude the file patterns
*/
const getFilesFromSourceFile = async ({ const getFilesFromSourceFile = async ({
filePaths, filePaths,
excludedFiles = false excludedFiles = false
@@ -169,6 +215,12 @@ const getFilesFromSourceFile = async ({
return lines return lines
} }
/**
* Sets the global git configs
* @param name - name of config
* @param value - value of config
* @throws Couldn't update git global config
*/
export const updateGitGlobalConfig = async ({ export const updateGitGlobalConfig = async ({
name, name,
value value
@@ -191,6 +243,11 @@ export const updateGitGlobalConfig = async ({
} }
} }
/**
* Checks if a git repository is shallow
* @param cwd - working directory
* @returns repository is shallow
*/
export const isRepoShallow = async ({cwd}: {cwd: string}): Promise<boolean> => { export const isRepoShallow = async ({cwd}: {cwd: string}): Promise<boolean> => {
const {stdout} = await exec.getExecOutput( const {stdout} = await exec.getExecOutput(
'git', 'git',
@@ -204,6 +261,11 @@ export const isRepoShallow = async ({cwd}: {cwd: string}): Promise<boolean> => {
return stdout.trim() === 'true' return stdout.trim() === 'true'
} }
/**
* Checks if a submodule exists
* @param cwd - working directory
* @returns submodule exists
*/
export const submoduleExists = async ({ export const submoduleExists = async ({
cwd cwd
}: { }: {
@@ -227,6 +289,11 @@ export const submoduleExists = async ({
return stdout.trim() !== '' return stdout.trim() !== ''
} }
/**
* Fetches the git repository
* @param args - arguments for fetch command
* @param cwd - working directory
*/
export const gitFetch = async ({ export const gitFetch = async ({
args, args,
cwd cwd
@@ -243,6 +310,11 @@ export const gitFetch = async ({
return exitCode return exitCode
} }
/**
* Fetches the git repository submodules
* @param args - arguments for fetch command
* @param cwd - working directory
*/
export const gitFetchSubmodules = async ({ export const gitFetchSubmodules = async ({
args, args,
cwd cwd
@@ -266,10 +338,10 @@ export const gitFetchSubmodules = async ({
} }
} }
const normalizePath = (p: string): string => { /**
return p.replace(/\\/g, '/') * Retrieves all the submodule paths
} * @param cwd - working directory
*/
export const getSubmodulePath = async ({ export const getSubmodulePath = async ({
cwd cwd
}: { }: {
@@ -296,6 +368,14 @@ export const getSubmodulePath = async ({
.map((line: string) => normalizePath(line.trim().split(' ')[1])) .map((line: string) => normalizePath(line.trim().split(' ')[1]))
} }
/**
* Retrieves commit sha of a submodule from a parent commit
* @param cwd - working directory
* @param parentSha1 - parent commit sha
* @param parentSha2 - parent commit sha
* @param submodulePath - path of submodule
* @param diff - diff type between parent commits (`..` or `...`)
*/
export const gitSubmoduleDiffSHA = async ({ export const gitSubmoduleDiffSHA = async ({
cwd, cwd,
parentSha1, parentSha1,
@@ -311,7 +391,7 @@ export const gitSubmoduleDiffSHA = async ({
}): Promise<{previousSha?: string; currentSha?: string}> => { }): Promise<{previousSha?: string; currentSha?: string}> => {
const {stdout} = await exec.getExecOutput( const {stdout} = await exec.getExecOutput(
'git', 'git',
['diff', parentSha1, parentSha2, '--', submodulePath], ['diff', `${parentSha1}${diff}${parentSha2}`, '--', submodulePath],
{ {
cwd, cwd,
silent: !core.isDebug() silent: !core.isDebug()
@@ -408,6 +488,16 @@ export const gitRenamedFiles = async ({
}) })
} }
/**
* Retrieves all the changed files between two commits
* @param cwd - working directory
* @param sha1 - commit sha
* @param sha2 - commit sha
* @param diff - diff type between parent commits (`..` or `...`)
* @param isSubmodule - is the repo a submodule
* @param parentDir - parent directory of the submodule
* @param outputRenamedFilesAsDeletedAndAdded - output renamed files as deleted and added
*/
export const getAllChangedFiles = async ({ export const getAllChangedFiles = async ({
cwd, cwd,
sha1, sha1,
@@ -494,6 +584,11 @@ export const getAllChangedFiles = async ({
return changedFiles return changedFiles
} }
/**
* Filters the changed files by the file patterns
* @param allDiffFiles - all the changed files
* @param filePatterns - file patterns to filter by
*/
export const getFilteredChangedFiles = async ({ export const getFilteredChangedFiles = async ({
allDiffFiles, allDiffFiles,
filePatterns filePatterns
@@ -518,7 +613,7 @@ export const getFilteredChangedFiles = async ({
if (hasFilePatterns) { if (hasFilePatterns) {
changedFiles[changeType as ChangeTypeEnum] = mm(files, filePatterns, { changedFiles[changeType as ChangeTypeEnum] = mm(files, filePatterns, {
dot: true, dot: true,
windows: IS_WINDOWS, windows: isWindows(),
noext: true noext: true
}) })
} else { } else {
@@ -710,15 +805,15 @@ export const canDiffCommits = async ({
} }
export const getDirnameMaxDepth = ({ export const getDirnameMaxDepth = ({
pathStr, relativePath,
dirNamesMaxDepth, dirNamesMaxDepth,
excludeCurrentDir excludeCurrentDir
}: { }: {
pathStr: string relativePath: string
dirNamesMaxDepth?: number dirNamesMaxDepth?: number
excludeCurrentDir?: boolean excludeCurrentDir?: boolean
}): string => { }): string => {
const pathArr = dirname(pathStr).split(path.sep) const pathArr = getDirname(relativePath).split(path.sep)
const maxDepth = Math.min(dirNamesMaxDepth || pathArr.length, pathArr.length) const maxDepth = Math.min(dirNamesMaxDepth || pathArr.length, pathArr.length)
let output = pathArr[0] let output = pathArr[0]
@@ -815,7 +910,7 @@ export const getFilePatterns = async ({
filePatterns = filePatterns.concat('\n', filesIgnoreFromSourceFiles) filePatterns = filePatterns.concat('\n', filesIgnoreFromSourceFiles)
} }
if (IS_WINDOWS) { if (isWindows()) {
filePatterns = filePatterns.replace(/\r\n/g, '\n') filePatterns = filePatterns.replace(/\r\n/g, '\n')
filePatterns = filePatterns.replace(/\r/g, '\n') filePatterns = filePatterns.replace(/\r/g, '\n')
} }
@@ -893,17 +988,17 @@ const getYamlFilePatternsFromContents = async ({
if (doc.errors.length > 0) { if (doc.errors.length > 0) {
if (filePath) { if (filePath) {
core.warning(`YAML errors in ${filePath}: ${doc.errors}`) throw new Error(`YAML errors in ${filePath}: ${doc.errors}`)
} else { } else {
core.warning(`YAML errors: ${doc.errors}`) throw new Error(`YAML errors: ${doc.errors}`)
} }
} }
if (doc.warnings.length > 0) { if (doc.warnings.length > 0) {
if (filePath) { if (filePath) {
core.warning(`YAML warnings in ${filePath}: ${doc.warnings}`) throw new Error(`YAML warnings in ${filePath}: ${doc.warnings}`)
} else { } else {
core.warning(`YAML warnings: ${doc.warnings}`) throw new Error(`YAML warnings: ${doc.warnings}`)
} }
} }
@@ -1028,6 +1123,36 @@ export const getYamlFilePatterns = async ({
return filePatterns return filePatterns
} }
export const getRecoverFilePatterns = ({
inputs
}: {
inputs: Inputs
}): string[] => {
let filePatterns: string[] = inputs.recoverFiles.split(
inputs.recoverFilesSeparator
)
if (inputs.recoverFilesIgnore) {
const ignoreFilePatterns = inputs.recoverFilesIgnore.split(
inputs.recoverFilesSeparator
)
filePatterns = filePatterns.concat(
ignoreFilePatterns.map(p => {
if (p.startsWith('!')) {
return p
} else {
return `!${p}`
}
})
)
}
core.debug(`recover file patterns: ${filePatterns}`)
return filePatterns.filter(Boolean)
}
export const setOutput = async ({ export const setOutput = async ({
key, key,
value, value,
@@ -1084,36 +1209,48 @@ export const recoverDeletedFiles = async ({
inputs, inputs,
workingDirectory, workingDirectory,
deletedFiles, deletedFiles,
recoverPatterns,
sha sha
}: { }: {
inputs: Inputs inputs: Inputs
workingDirectory: string workingDirectory: string
deletedFiles: string[] deletedFiles: string[]
recoverPatterns: string[]
sha: string sha: string
}): Promise<void> => { }): Promise<void> => {
if (inputs.recoverDeletedFiles) { let recoverableDeletedFiles = deletedFiles
for (const deletedFile of deletedFiles) { core.debug(`recoverable deleted files: ${recoverableDeletedFiles}`)
let target = path.join(workingDirectory, deletedFile)
if (inputs.recoverDeletedFilesToDestination) { if (recoverPatterns.length > 0) {
target = path.join( recoverableDeletedFiles = mm(deletedFiles, recoverPatterns, {
workingDirectory, dot: true,
inputs.recoverDeletedFilesToDestination, windows: isWindows(),
deletedFile noext: true
) })
} core.debug(`filtered recoverable deleted files: ${recoverableDeletedFiles}`)
}
const deletedFileContents = await getDeletedFileContents({ for (const deletedFile of recoverableDeletedFiles) {
cwd: workingDirectory, let target = path.join(workingDirectory, deletedFile)
filePath: deletedFile,
sha
})
if (!(await exists(path.dirname(target)))) { if (inputs.recoverDeletedFilesToDestination) {
await fs.mkdir(path.dirname(target), {recursive: true}) target = path.join(
} workingDirectory,
await fs.writeFile(target, deletedFileContents) inputs.recoverDeletedFilesToDestination,
deletedFile
)
} }
const deletedFileContents = await getDeletedFileContents({
cwd: workingDirectory,
filePath: deletedFile,
sha
})
if (!(await exists(path.dirname(target)))) {
await fs.mkdir(path.dirname(target), {recursive: true})
}
await fs.writeFile(target, deletedFileContents)
} }
} }
@@ -1122,9 +1259,7 @@ export const hasLocalGitDirectory = async ({
}: { }: {
workingDirectory: string workingDirectory: string
}): Promise<boolean> => { }): Promise<boolean> => {
const insideWorkTree = await isInsideWorkTree({ return await isInsideWorkTree({
cwd: workingDirectory cwd: workingDirectory
}) })
return insideWorkTree
} }

863
yarn.lock

File diff suppressed because it is too large Load Diff