Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

actions-workflows.js 2.0 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
  1. const fs = require('fs')
  2. const path = require('path')
  3. const yaml = require('js-yaml')
  4. const flat = require('flat')
  5. const { chain, difference, get } = require('lodash')
  6. const workflowsDir = path.join(__dirname, '../../.github/workflows')
  7. const workflows = fs.readdirSync(workflowsDir)
  8. .filter(filename => filename.endsWith('.yml') || filename.endsWith('.yaml'))
  9. .map(filename => {
  10. const fullpath = path.join(workflowsDir, filename)
  11. const data = yaml.load(fs.readFileSync(fullpath, 'utf8'), { fullpath })
  12. return { filename, fullpath, data }
  13. })
  14. const allowedActions = require('../../.github/allowed-actions')
  15. function actionsUsedInWorkflow (workflow) {
  16. return Object.keys(flat(workflow))
  17. .filter(key => key.endsWith('.uses'))
  18. .map(key => get(workflow, key))
  19. }
  20. const scheduledWorkflows = workflows
  21. .map(workflow => workflow.data.on.schedule)
  22. .filter(Boolean)
  23. .flat()
  24. .map(schedule => schedule.cron)
  25. const allUsedActions = chain(workflows)
  26. .map(actionsUsedInWorkflow)
  27. .flatten()
  28. .uniq()
  29. .sort()
  30. .value()
  31. describe('GitHub Actions workflows', () => {
  32. test('all used actions are allowed in .github/allowed-actions.js', () => {
  33. expect(allUsedActions.length).toBeGreaterThan(0)
  34. const unusedActions = difference(allowedActions, allUsedActions)
  35. expect(unusedActions).toEqual([])
  36. })
  37. test('all allowed actions by .github/allowed-actions.js are used by at least one workflow', () => {
  38. expect(allowedActions.length).toBeGreaterThan(0)
  39. const disallowedActions = difference(allUsedActions, allowedActions)
  40. expect(disallowedActions).toEqual([])
  41. })
  42. test('no scheduled workflows run on the hour', () => {
  43. const hourlySchedules = scheduledWorkflows.filter(schedule => {
  44. const hour = schedule.split(' ')[0]
  45. // return any minute cron segments that equal 0, 00, 000, etc.
  46. return !/[^0]/.test(hour)
  47. })
  48. expect(hourlySchedules).toEqual([])
  49. })
  50. test('all scheduled workflows run at unique times', () => {
  51. expect(scheduledWorkflows.length).toEqual(new Set(scheduledWorkflows).size)
  52. })
  53. })
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...