generated from layer5io/layer5-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 83
85 lines (70 loc) · 2.83 KB
/
feature-list.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
name: Feature List Update
on:
schedule:
- cron: '0 0 * * *' # Run every night at midnight UTC
workflow_dispatch:
permissions:
contents: write
actions: read
jobs:
check-and-update-features:
runs-on: ubuntu-latest
env:
FEATURES_FILE: 'data/features.json'
steps:
- name: Checkout current repository
uses: actions/checkout@v4
- name: Restore cache
id: cache-sha
uses: actions/cache@v3
with:
path: .sha-cache
key: feature-data-sha
restore-keys: |
feature-data-sha
- name: Check for updates in source repository
id: check-updates
uses: actions/github-script@v7
with:
script: |
const { data: sourceFile } = await github.rest.repos.getContent({
owner: 'layer5labs',
repo: 'meshery-extensions-packages',
path: 'feature_data.json',
ref: 'master'
});
// Store the latest commit SHA
const latestSHA = sourceFile.sha;
const fs = require('fs');
// Check if we have a previous SHA
let hasUpdates = true;
const shaCachePath = '.sha-cache/latest-sha';
if (fs.existsSync(shaCachePath)) {
const lastSHA = fs.readFileSync(shaCachePath, 'utf8');
hasUpdates = lastSHA !== latestSHA;
}
if (hasUpdates) {
// Save the new SHA
fs.mkdirSync('.sha-cache', { recursive: true });
fs.writeFileSync(shaCachePath, latestSHA);
// Decode and save the content
const content = Buffer.from(sourceFile.content, 'base64').toString('utf8');
// Create data directory if it doesn't exist
fs.mkdirSync('data', { recursive: true });
// Write the new content
fs.writeFileSync(process.env.FEATURES_FILE, content);
core.setOutput('has-updates', 'true');
} else {
core.setOutput('has-updates', 'false');
}
- name: Commit changes
if: steps.check-updates.outputs.has-updates == 'true'
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Updated feature data from source repository"
file_pattern: ${{ env.FEATURES_FILE }}
branch: master
commit_options: "--signoff"
commit_user_name: l5io
commit_user_email: [email protected]
commit_author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>