Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
197 changes: 0 additions & 197 deletions .github/workflows/check_pr_template.yml

This file was deleted.

94 changes: 94 additions & 0 deletions .github/workflows/sync_submission.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Sync Submission on Merge

on:
pull_request_target:
types: [closed]

jobs:
sync_on_merge:
# 1. Only run if merged AND title contains [submission]
if: github.event.pull_request.merged == true && contains(github.event.pull_request.title, '[submission]')
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: read

steps:
- name: Checkout Base Branch
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.base.ref }}
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '16'

- name: Install dependencies
run: npm install js-yaml

- name: Extract and Generate File
id: generator
uses: actions/github-script@v6
with:
script: |
const fs = require('fs').promises;
const yaml = require('js-yaml');
const prBody = context.payload.pull_request.body || '';

// Extraction Logic
const normalizedBody = prBody.replace(/\r\n/g, '\n');
const startMarker = '```yaml\n';
const endMarker = '\n```';

const startIndex = normalizedBody.indexOf(startMarker);
const contentStart = startIndex + startMarker.length;
const endIndex = normalizedBody.indexOf(endMarker, contentStart);

if (startIndex === -1 || endIndex === -1) {
console.log('No YAML block found. Skipping.');
return;
}

const yamlContent = normalizedBody.slice(contentStart, endIndex);
let data;

try {
const cleanYaml = yamlContent.split('\n').map(l => l.split('#')[0].trim()).join('\n');
data = yaml.load(cleanYaml);
} catch (error) {
core.setFailed(`YAML parse error: ${error.message}`);
return;
}

// Path Logic for submissions_algorithms
const cleanFolder = data.submission_folder.replace(/^\/+|\/+$/g, '').replace(/^(external_tuning|self_tuning)\//, '');
const subDir = data.ruleset === 'external' ? 'external_tuning' : 'self_tuning';
const finalPath = `submissions/${subDir}/${cleanFolder}`;

core.setOutput('path', finalPath);
core.setOutput('yaml_string', yaml.dump(data));
core.setOutput('should_commit', 'true');

- name: Commit and Push
if: steps.generator.outputs.should_commit == 'true'
run: |
mkdir -p "${{ steps.generator.outputs.path }}"

# Write the validated YAML to the repository
cat <<EOF > "${{ steps.generator.outputs.path }}/submission_info.yml"
${{ steps.generator.outputs.yaml_string }}
EOF

git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add submissions/

if ! git diff --staged --quiet; then
git commit -m "Final submission sync for PR #${{ github.event.pull_request.number }}"
# Pushes directly to your main/base branch
git push origin HEAD:${{ github.event.pull_request.base.ref }}
else
echo "No changes detected."
fi
74 changes: 74 additions & 0 deletions .github/workflows/validate_pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Validate PR Template

on:
pull_request:
types: [opened, edited, synchronize]

jobs:
validate:
# This ensures the script ONLY runs if "[submission]" is in the title
if: contains(github.event.pull_request.title, '[submission]')
runs-on: ubuntu-latest
permissions:
pull-requests: write

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '16'

- name: Install dependencies
run: npm install js-yaml

- name: Validate YAML
uses: actions/github-script@v6
with:
script: |
const yaml = require('js-yaml');
const prBody = context.payload.pull_request.body || '';

// 1. Extraction
const normalizedBody = prBody.replace(/\r\n/g, '\n');
const startMarker = '```yaml\n';
const endMarker = '\n```';

const startIndex = normalizedBody.indexOf(startMarker);
const contentStart = startIndex + startMarker.length;
const endIndex = normalizedBody.indexOf(endMarker, contentStart);

if (startIndex === -1 || endIndex === -1) {
core.setFailed('No YAML block found. Please use the [submission] template.');
return;
}

// 2. Parsing & Field Check
let data;
try {
const yamlContent = normalizedBody.slice(contentStart, endIndex);
const cleanYaml = yamlContent.split('\n').map(l => l.split('#')[0].trim()).join('\n');
data = yaml.load(cleanYaml);
} catch (e) {
core.setFailed(`YAML Syntax Error: ${e.message}`);
return;
}

const requiredFields = ['submission_name', 'submission_folder', 'authors', 'ruleset'];
const emptyFields = requiredFields.filter(f => !data?.[f] || data[f].toString().trim() === '');

if (emptyFields.length > 0) {
const errorMsg = `⚠️ Missing required fields: ${emptyFields.join(', ')}`;

// Post a comment so the user knows exactly what to fix
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: errorMsg
});

core.setFailed(errorMsg);
}
Loading
Loading