|
| 1 | +/** |
| 2 | + * AnchoringTrust/anchor-action |
| 3 | + * |
| 4 | + * Thin wrapper around @umarise/cli. |
| 5 | + * Installs the CLI, runs `umarise anchor <file>`, uploads the .proof artifact. |
| 6 | + */ |
| 7 | + |
| 8 | +const core = require('@actions/core'); |
| 9 | +const exec = require('@actions/exec'); |
| 10 | +const { DefaultArtifactClient } = require('@actions/artifact'); |
| 11 | +const path = require('path'); |
| 12 | +const fs = require('fs'); |
| 13 | + |
| 14 | +async function run() { |
| 15 | + try { |
| 16 | + const file = core.getInput('file', { required: true }); |
| 17 | + const uploadArtifact = core.getInput('upload-artifact') !== 'false'; |
| 18 | + |
| 19 | + // Verify file exists |
| 20 | + const absPath = path.resolve(file); |
| 21 | + if (!fs.existsSync(absPath)) { |
| 22 | + throw new Error(`File not found: ${file}`); |
| 23 | + } |
| 24 | + |
| 25 | + // Install @umarise/cli globally |
| 26 | + core.info('Installing @umarise/cli...'); |
| 27 | + await exec.exec('npm', ['install', '-g', '@umarise/cli']); |
| 28 | + |
| 29 | + // Run anchor command |
| 30 | + core.info(`Anchoring ${file}...`); |
| 31 | + let stdout = ''; |
| 32 | + await exec.exec('umarise', ['anchor', file], { |
| 33 | + listeners: { |
| 34 | + stdout: (data) => { stdout += data.toString(); }, |
| 35 | + }, |
| 36 | + }); |
| 37 | + |
| 38 | + // Parse output for origin_id and hash |
| 39 | + const originMatch = stdout.match(/origin_id\s+([a-f0-9-]+)/i); |
| 40 | + const hashMatch = stdout.match(/hash computed:\s+(sha256:[a-f0-9]+)/i); |
| 41 | + const proofPath = `${absPath}.proof`; |
| 42 | + |
| 43 | + if (originMatch) core.setOutput('origin-id', originMatch[1]); |
| 44 | + if (hashMatch) core.setOutput('hash', hashMatch[1]); |
| 45 | + core.setOutput('proof-path', proofPath); |
| 46 | + |
| 47 | + // Upload .proof as artifact |
| 48 | + if (uploadArtifact && fs.existsSync(proofPath)) { |
| 49 | + core.info('Uploading .proof artifact...'); |
| 50 | + const artifactName = `${path.basename(file)}.proof`; |
| 51 | + const client = new DefaultArtifactClient(); |
| 52 | + await client.uploadArtifact(artifactName, [proofPath], path.dirname(proofPath)); |
| 53 | + core.info(`✓ artifact uploaded: ${artifactName}`); |
| 54 | + } |
| 55 | + |
| 56 | + core.info('✓ anchor-action complete'); |
| 57 | + } catch (error) { |
| 58 | + core.setFailed(error.message); |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +run(); |
0 commit comments