File size: 1,120 Bytes
c5bf270
 
ef41f13
c5bf270
 
 
 
 
ef41f13
c5bf270
 
 
 
 
 
 
 
 
 
ef41f13
 
 
 
 
 
 
 
c5bf270
ef41f13
 
c5bf270
ef41f13
c5bf270
 
 
ef41f13
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
require('dotenv/config')
const { exec } = require('child_process');
const { promisify } = require('util');

const execPromise = promisify(exec);

const execute = (command) => {
  return execPromise(command).then(({ stdout, stderr }) => {
    if (stderr && !stderr.includes('nothing to commit')) {
      console.warn(`Stderr: ${stderr}`);
    }
    return stdout;
  }).catch((error) => {
    throw new Error(`Error: ${error.message}`);
  });
};

const push = async (username) => {
  try {
    const token = process.env.TOKEN;
    const repo = process.env.REPO_NAME;
    const repoUrl = `https://huggingface.co/spaces/${username}/${repo}`;
    const remoteUrl = `https://${username}:${token}@huggingface.co/spaces/${username}/${repo}`;

    await execute('git config --global --add safe.directory "$(pwd)"');
    
    await execute('git commit --allow-empty -m "trigger rebuild"');

    await execute(`git push ${remoteUrl} main`);
    console.log('✅ Rebuild triggered via empty commit.');
  } catch (error) {
    console.error(`❌ Failed to push: ${error.message}`);
  }
};

push("termai").then(() => process.exit());