55 - cron : " 0 */6 * * *" # Runs every 6 hours
66 workflow_dispatch : # Allows manual triggering
77
8+ permissions :
9+ contents : read
10+
811jobs :
912 update-draft-hips :
10- if : github.ref == 'refs/heads/main' # Only run on main branch
11- runs-on : improvement-proposals-linux-medium
13+ if : ${{ github.ref == 'refs/heads/main' }} # Only run on main branch
14+ runs-on : hiero- improvement-proposals-linux-medium
1215 permissions :
1316 contents : write
1417 pull-requests : read
1518 steps :
19+ - name : Harden the runner (Audit all outbound calls)
20+ uses : step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
21+ with :
22+ egress-policy : audit
23+
1624 - name : Checkout Code
17- uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
25+ uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
1826 with :
1927 token : ${{ secrets.GH_ACCESS_TOKEN }}
28+ ref : ' main'
2029
2130 - name : Import GPG Key
2231 id : gpg_importer
23- uses : step-security/ghaction-import-gpg@6c8fe4d0126a59d57c21f87c9ae5dd3451fa3cca # v6.1 .0
32+ uses : step-security/ghaction-import-gpg@c86c374c0659a6c2d1284bccf8af889e73ce8fe0 # v6.3 .0
2433 with :
2534 git_commit_gpgsign : true
2635 git_tag_gpgsign : true
2938 passphrase : ${{ secrets.GPG_KEY_PASSPHRASE }}
3039
3140 - name : Setup Node.js
32- uses : actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1 .0
41+ uses : actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4 .0
3342 with :
3443 node-version : " 20"
3544
3847 mkdir -p _data
3948 cat << 'EOF' > fetch-draft-hips.js
4049 const https = require('https');
50+ const fs = require('fs');
4151
4252 async function makeGraphQLRequest(query, token) {
4353 return new Promise((resolve, reject) => {
6777 async function getAllPRs() {
6878 const query = `
6979 query {
70- repository(name: "hedera -improvement-proposal ", owner: "hashgraph ") {
80+ repository(name: "hiero -improvement-proposals ", owner: "hiero-ledger ") {
7181 pullRequests(first: 100, states: [OPEN], orderBy: {field: CREATED_AT, direction: DESC}) {
7282 nodes {
7383 title
7888 edges {
7989 node {
8090 path
91+ changeType
8192 additions
8293 deletions
8394 }
@@ -97,6 +108,12 @@ jobs:
97108
98109 if (result.errors) {
99110 console.error('GraphQL errors:', result.errors);
111+ process.exit(1);
112+ }
113+
114+ // Check if data and the expected path to nodes exist
115+ if (!result.data || !result.data.repository || !result.data.repository.pullRequests || !result.data.repository.pullRequests.nodes) {
116+ console.error('Unexpected GraphQL response structure:', result);
100117 process.exit(1);
101118 }
102119
@@ -108,11 +125,31 @@ jobs:
108125 }
109126
110127 // Run the main function
111- getAllPRs().then(prs => {
112- const fs = require('fs');
113- fs.writeFileSync('_data/draft_hips.json', JSON.stringify(prs, null, 2));
128+ getAllPRs().then(allPRs => {
129+ const draftHIPPRs = allPRs.filter(pr => {
130+ if (!pr.files || !pr.files.edges) {
131+ return false;
132+ }
133+ const hipFiles = pr.files.edges.filter(edge => {
134+ const fileNode = edge.node;
135+ const isNewHIPFile = /^HIP\/hip-[a-zA-Z0-9-]+\.md$/.test(fileNode.path);
136+ return fileNode.changeType === 'ADDED' && isNewHIPFile;
137+ }).map(edge => edge.node);
138+
139+ return hipFiles.length > 0;
140+ });
141+
142+ const outputPath = '_data/draft_hips.json';
143+
144+ if (fs.existsSync(outputPath)) {
145+ console.log(`Removing existing file: ${outputPath}`);
146+ fs.unlinkSync(outputPath);
147+ }
148+
149+ console.log(`Writing ${draftHIPPRs.length} filtered PRs to: ${outputPath}`);
150+ fs.writeFileSync(outputPath, JSON.stringify(draftHIPPRs, null, 2));
114151 }).catch(error => {
115- console.error('Failed to fetch PRs:', error);
152+ console.error('Failed to fetch and filter PRs:', error);
116153 process.exit(1);
117154 });
118155 EOF
@@ -124,11 +161,15 @@ jobs:
124161
125162 - name : Commit and Push Changes
126163 env :
127- GITHUB_USER_EMAIL : ${{ secrets .GIT_USER_EMAIL }}
128- GITHUB_USER_NAME : ${{ secrets .GIT_USER_NAME }}
164+ GITHUB_USER_EMAIL : ${{ vars .GIT_USER_EMAIL }}
165+ GITHUB_USER_NAME : ${{ vars .GIT_USER_NAME }}
129166 run : |
167+ set -e
130168 git config --local user.email "$GITHUB_USER_EMAIL"
131169 git config --local user.name "$GITHUB_USER_NAME"
132170 git add _data/draft_hips.json
133- git commit -s -S -m "Update draft HIPs data [skip ci]" || echo "No changes to commit"
134- git push origin main || echo "No changes to push"
171+ git diff --cached --quiet && echo "No changes to commit" && exit 0
172+
173+ git commit -s -S -m "Update draft HIPs data [skip ci]"
174+ git push origin main
175+ set +e
0 commit comments