Skip to content

Commit

Permalink
Added logging
Browse files Browse the repository at this point in the history
  • Loading branch information
obany committed Feb 17, 2020
1 parent a8874af commit ffd6ed3
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
steps:
- name: Tangle Release
id: tangle_release
uses: iotaledger/gh-tangle-release@v0.5.2
uses: iotaledger/gh-tangle-release@v0.5.3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
IOTA_SEED: ${{ secrets.IOTA_SEED }}
Expand Down
22 changes: 22 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,7 @@ module.exports = function createError(message, config, code, request, response)
const run = __webpack_require__(885);

if (require.main === require.cache[eval('__filename')]) {
console.log(`Tangle Release Startup`);
run();
}

Expand Down Expand Up @@ -15320,13 +15321,15 @@ async function attachToTangle(provider, depth, mwm, seed, addressIndex, tag, pay
const json = JSON.stringify(payload);
const ascii = encodeNonASCII(json);
const message = asciiToTrytes(ascii);
console.log(`Message Trytes Length: ${message.length}`);

const iota = composeAPI({
provider
});

const address = generateAddress(seed, addressIndex);

console.log("Preparing transfer");
const trytes = await iota.prepareTransfers('9'.repeat(81), [
{
address,
Expand All @@ -15336,6 +15339,7 @@ async function attachToTangle(provider, depth, mwm, seed, addressIndex, tag, pay
}
]);

console.log("Sending trytes");
const bundles = await iota.sendTrytes(trytes, depth, mwm);

return bundles[0].hash;
Expand Down Expand Up @@ -31860,6 +31864,8 @@ async function run() {
let depth = parseInt(process.env.IOTA_DEPTH, 10);
let mwm = parseInt(process.env.IOTA_MWM, 10);

console.log(`Parameters Initialized`);

if (!seed) {
throw new Error('You must provide the IOTA_SEED env variable');
}
Expand All @@ -31879,17 +31885,28 @@ async function run() {
const { owner, repo } = context.repo;

const tagName = core.getInput('tag_name', { required: true });
console.log(`Tag Name Retrieved`);

const comment = core.getInput('comment', { required: false });
console.log(`Comment Retrieved`);

const release = await github.repos.getReleaseByTag({
owner,
repo,
tag: tagName.replace('refs/tags/', '')
});

if (!release) {
throw new Error("Unable to retrieve release");
}

console.log(`Downloading tarball`);
const tarBallHash = await downloadAndHash(release.data.tarball_url);

console.log(`Downloading zipball`);
const zipBallHash = await downloadAndHash(release.data.zipball_url);

console.log(`Constructing payload`);
const payload = {
owner,
repo,
Expand All @@ -31902,7 +31919,9 @@ async function run() {
zipball_url: release.data.zipball_url,
zipball_sig: zipBallHash
};
console.log(payload);

console.log("Processing assets");
if (release.data.assets && release.data.assets.length > 0) {
payload.assets = [];
// eslint-disable-next-line no-plusplus
Expand All @@ -31918,13 +31937,16 @@ async function run() {
}
}

console.log("Attaching to tangle");
const txHash = await attachToTangle(provider, depth, mwm, seed, addressIndex, tag, payload);
const exploreUrl = tangleExplorer.replace(':hash', txHash);
console.log(`You can view the transaction on the tangle at ${exploreUrl}`);
core.setOutput('tx_hash', txHash);
core.setOutput('tx_explore_url', exploreUrl);
} catch (error) {
core.setFailed(error.message);
console.log(`Failed`);
console.log(error.message);
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gh-tangle-release",
"version": "0.5.2",
"version": "0.5.3",
"description": "Create a release and adds metadata to the IOTA Tangle",
"main": "dist/index.js",
"scripts": {
Expand Down
3 changes: 3 additions & 0 deletions src/iota.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ async function attachToTangle(provider, depth, mwm, seed, addressIndex, tag, pay
const json = JSON.stringify(payload);
const ascii = encodeNonASCII(json);
const message = asciiToTrytes(ascii);
console.log(`Message Trytes Length: ${message.length}`);

const iota = composeAPI({
provider
});

const address = generateAddress(seed, addressIndex);

console.log("Preparing transfer");
const trytes = await iota.prepareTransfers('9'.repeat(81), [
{
address,
Expand All @@ -27,6 +29,7 @@ async function attachToTangle(provider, depth, mwm, seed, addressIndex, tag, pay
}
]);

console.log("Sending trytes");
const bundles = await iota.sendTrytes(trytes, depth, mwm);

return bundles[0].hash;
Expand Down
1 change: 1 addition & 0 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const run = require('./tangle-release');

if (require.main === module) {
console.log(`Tangle Release Startup`);
run();
}
18 changes: 18 additions & 0 deletions src/tangle-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ async function run() {
let depth = parseInt(process.env.IOTA_DEPTH, 10);
let mwm = parseInt(process.env.IOTA_MWM, 10);

console.log(`Parameters Initialized`);

if (!seed) {
throw new Error('You must provide the IOTA_SEED env variable');
}
Expand All @@ -35,17 +37,28 @@ async function run() {
const { owner, repo } = context.repo;

const tagName = core.getInput('tag_name', { required: true });
console.log(`Tag Name Retrieved`);

const comment = core.getInput('comment', { required: false });
console.log(`Comment Retrieved`);

const release = await github.repos.getReleaseByTag({
owner,
repo,
tag: tagName.replace('refs/tags/', '')
});

if (!release) {
throw new Error("Unable to retrieve release");
}

console.log(`Downloading tarball`);
const tarBallHash = await downloadAndHash(release.data.tarball_url);

console.log(`Downloading zipball`);
const zipBallHash = await downloadAndHash(release.data.zipball_url);

console.log(`Constructing payload`);
const payload = {
owner,
repo,
Expand All @@ -58,7 +71,9 @@ async function run() {
zipball_url: release.data.zipball_url,
zipball_sig: zipBallHash
};
console.log(payload);

console.log("Processing assets");
if (release.data.assets && release.data.assets.length > 0) {
payload.assets = [];
// eslint-disable-next-line no-plusplus
Expand All @@ -74,13 +89,16 @@ async function run() {
}
}

console.log("Attaching to tangle");
const txHash = await attachToTangle(provider, depth, mwm, seed, addressIndex, tag, payload);
const exploreUrl = tangleExplorer.replace(':hash', txHash);
console.log(`You can view the transaction on the tangle at ${exploreUrl}`);
core.setOutput('tx_hash', txHash);
core.setOutput('tx_explore_url', exploreUrl);
} catch (error) {
core.setFailed(error.message);
console.log(`Failed`);
console.log(error.message);
}
}

Expand Down

0 comments on commit ffd6ed3

Please sign in to comment.