From 09d868321dd82e5c8d23789ca4979f1027a79869 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Wed, 13 Sep 2023 14:50:12 +0300 Subject: [PATCH 01/87] code format Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- action.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/action.yml b/action.yml index d400bde..a398881 100644 --- a/action.yml +++ b/action.yml @@ -5,9 +5,11 @@ inputs: description: "Who to greet" required: true default: "World" + label: description: "Optional label" required: false + outputs: time: # id of output description: "The time we greeted you" From 238de599ba125fad45f4d198fe40228d27c47b77 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Wed, 13 Sep 2023 14:52:35 +0300 Subject: [PATCH 02/87] Add label to outputs Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- .github/workflows/main.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 0ba8f2c..750b6f2 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -26,5 +26,8 @@ jobs: with: who-to-greet: "John" label: ${{ github.event.label.name }} + - name: Get the output time - run: echo "The time was ${{ steps.hello.outputs.time }}" + run: | + echo "The time was ${{ steps.hello.outputs.time }}" + echo The label was ${{ steps.hello.outputs.label }} From 9d31be233dcbd88376a103febf49d517ab45280f Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Wed, 13 Sep 2023 14:55:04 +0300 Subject: [PATCH 03/87] Add to outputs Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index eb7669b..05f3d80 100644 --- a/index.js +++ b/index.js @@ -9,6 +9,7 @@ try { console.log(`Hello ${nameToGreet}!`); const time = (new Date()).toTimeString(); + core.setOutput("lable", label); core.setOutput("time", time); const payload = JSON.stringify(github.context.payload, undefined, 2) From 34a9746f3d93283b958f4249b70afb7af0c62578 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Wed, 13 Sep 2023 14:56:14 +0300 Subject: [PATCH 04/87] typo Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 05f3d80..252ed70 100644 --- a/index.js +++ b/index.js @@ -5,11 +5,11 @@ const github = require('@actions/github'); try { const nameToGreet = core.getInput('who-to-greet'); const label = core.getInput('label'); - console.log(`Lable: ${label}`) + console.log(`Label: ${label}`) console.log(`Hello ${nameToGreet}!`); const time = (new Date()).toTimeString(); - core.setOutput("lable", label); + core.setOutput("label", label); core.setOutput("time", time); const payload = JSON.stringify(github.context.payload, undefined, 2) From 283f0c95ff98976ca0b19ad0832ea40ac8949331 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Wed, 13 Sep 2023 14:58:13 +0300 Subject: [PATCH 05/87] Code cleanup Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- .github/workflows/main.yaml | 2 -- action.yml | 5 ----- index.js | 4 ---- 3 files changed, 11 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 750b6f2..2e82159 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -24,10 +24,8 @@ jobs: uses: ./ id: hello with: - who-to-greet: "John" label: ${{ github.event.label.name }} - name: Get the output time run: | - echo "The time was ${{ steps.hello.outputs.time }}" echo The label was ${{ steps.hello.outputs.label }} diff --git a/action.yml b/action.yml index a398881..5bd0eb1 100644 --- a/action.yml +++ b/action.yml @@ -1,11 +1,6 @@ name: "Hello World" description: "Greet someone and record the time" inputs: - who-to-greet: # id of input - description: "Who to greet" - required: true - default: "World" - label: description: "Optional label" required: false diff --git a/index.js b/index.js index 252ed70..adfe235 100644 --- a/index.js +++ b/index.js @@ -3,14 +3,10 @@ const github = require('@actions/github'); try { - const nameToGreet = core.getInput('who-to-greet'); const label = core.getInput('label'); console.log(`Label: ${label}`) - console.log(`Hello ${nameToGreet}!`); - const time = (new Date()).toTimeString(); core.setOutput("label", label); - core.setOutput("time", time); const payload = JSON.stringify(github.context.payload, undefined, 2) From 2ca30dd8d21bccd97cbae6064b598c96d11df391 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Sun, 17 Sep 2023 13:46:26 +0300 Subject: [PATCH 06/87] rename index.js to ts Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js => index.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) rename index.js => index.ts (52%) diff --git a/index.js b/index.ts similarity index 52% rename from index.js rename to index.ts index adfe235..a3e554e 100644 --- a/index.js +++ b/index.ts @@ -1,13 +1,20 @@ -const core = require('@actions/core'); -const github = require('@actions/github'); - - +import * as core from '@actions/core' +import * as github from '@actions/github' +import * as fs from 'fs'; try { const label = core.getInput('label'); console.log(`Label: ${label}`) core.setOutput("label", label); + + fs.readFile('/Readme.md', 'utf8', (err, data) => { + if (err) { + console.error(err); + return; + } + console.log(`File data: ${data}`); + }); const payload = JSON.stringify(github.context.payload, undefined, 2) console.log(`The event payload: ${payload}`); From d0822c2ad74c4f2948a69a9e5a19efd3548dafae Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Sun, 17 Sep 2023 13:46:33 +0300 Subject: [PATCH 07/87] Update package json Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- package-lock.json | 17 ++++++++++++++++- package.json | 6 +++++- tsconfig.json | 11 +++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 tsconfig.json diff --git a/package-lock.json b/package-lock.json index 0d9a52b..80735e9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,11 @@ "license": "ISC", "dependencies": { "@actions/core": "^1.10.0", - "@actions/github": "^5.1.1" + "@actions/github": "^5.1.1", + "@actions/io": "^1.1.3" + }, + "devDependencies": { + "@types/node": "^20.6.2" } }, "node_modules/@actions/core": { @@ -41,6 +45,11 @@ "tunnel": "^0.0.6" } }, + "node_modules/@actions/io": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/@actions/io/-/io-1.1.3.tgz", + "integrity": "sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q==" + }, "node_modules/@octokit/auth-token": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-2.5.0.tgz", @@ -142,6 +151,12 @@ "@octokit/openapi-types": "^12.11.0" } }, + "node_modules/@types/node": { + "version": "20.6.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.6.2.tgz", + "integrity": "sha512-Y+/1vGBHV/cYk6OI1Na/LHzwnlNCAfU3ZNGrc1LdRe/LAIbdDPTTv/HU3M7yXN448aTVDq3eKRm2cg7iKLb8gw==", + "dev": true + }, "node_modules/before-after-hook": { "version": "2.2.3", "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.2.3.tgz", diff --git a/package.json b/package.json index 92a599d..c8e34fe 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,10 @@ "license": "ISC", "dependencies": { "@actions/core": "^1.10.0", - "@actions/github": "^5.1.1" + "@actions/github": "^5.1.1", + "@actions/io": "^1.1.3" + }, + "devDependencies": { + "@types/node": "^20.6.2" } } diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..22e5d27 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "typeRoots": [ + "node_modules/@types", + "src/typings" + ], + "types": [ + "node" + ] + } +} From 014d615688fd0cc72db4c5024384c37109ad5a2c Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Sun, 17 Sep 2023 13:48:49 +0300 Subject: [PATCH 08/87] Update main.yaml Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- .github/workflows/main.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 2e82159..5c57c8a 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -21,7 +21,8 @@ jobs: run: npm install - name: Hello world action step - uses: ./ + uses: ./index.ts + id: hello with: label: ${{ github.event.label.name }} From e7d89e4b8a81b9af48d02bce4880dca20b263bf6 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Sun, 17 Sep 2023 13:52:27 +0300 Subject: [PATCH 09/87] rename index.ts to js Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.ts => index.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename index.ts => index.js (100%) diff --git a/index.ts b/index.js similarity index 100% rename from index.ts rename to index.js From e386f9295f5022add50ebaf0ce366fb1911677ab Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Sun, 17 Sep 2023 13:52:33 +0300 Subject: [PATCH 10/87] fix pipeline Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- .github/workflows/main.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 5c57c8a..0fa1453 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -21,7 +21,7 @@ jobs: run: npm install - name: Hello world action step - uses: ./index.ts + uses: ./ id: hello with: From 5b0b91b542c78bf3de627862787ad0df97a58a7d Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Sun, 17 Sep 2023 13:54:11 +0300 Subject: [PATCH 11/87] Update index Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index a3e554e..70cde83 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ -import * as core from '@actions/core' -import * as github from '@actions/github' -import * as fs from 'fs'; +const core = require('@actions/core') +const github = require('@actions/github') +const fs = require('fs') try { const label = core.getInput('label'); console.log(`Label: ${label}`) @@ -8,7 +8,7 @@ try { core.setOutput("label", label); - fs.readFile('/Readme.md', 'utf8', (err, data) => { + fs.readFile('/README.md', 'utf8', (err, data) => { if (err) { console.error(err); return; From 5c05cd5a1d9c5ae50c77c1a0bdd27329597309f9 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Sun, 17 Sep 2023 13:54:17 +0300 Subject: [PATCH 12/87] delete tsconfig Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- tsconfig.json | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 tsconfig.json diff --git a/tsconfig.json b/tsconfig.json deleted file mode 100644 index 22e5d27..0000000 --- a/tsconfig.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "compilerOptions": { - "typeRoots": [ - "node_modules/@types", - "src/typings" - ], - "types": [ - "node" - ] - } -} From 6751826fdf8cb7386fb026c868a8a57c703aa8fd Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Sun, 17 Sep 2023 13:56:22 +0300 Subject: [PATCH 13/87] trigger pipeline on push Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- .github/workflows/main.yaml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 0fa1453..b15f833 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -1,9 +1,11 @@ name: Test Action on: - pull_request: - types: [labeled] - + # pull_request: + # types: [labeled] + push: + branches: + - main jobs: hello-world-job: runs-on: ubuntu-latest @@ -29,4 +31,6 @@ jobs: - name: Get the output time run: | - echo The label was ${{ steps.hello.outputs.label }} + echo The label was label + +# ${{ steps.hello.outputs.label }} From da0721a5f7a61b770780b55a463aa9d8f741a571 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Sun, 17 Sep 2023 13:56:29 +0300 Subject: [PATCH 14/87] Update index.js Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 70cde83..561eaf9 100644 --- a/index.js +++ b/index.js @@ -8,7 +8,7 @@ try { core.setOutput("label", label); - fs.readFile('/README.md', 'utf8', (err, data) => { + fs.readFile('./README.md', 'utf8', (err, data) => { if (err) { console.error(err); return; From 7fd63572bd23da5d9e0cdbf173f40003de416913 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Sun, 17 Sep 2023 13:56:59 +0300 Subject: [PATCH 15/87] trigger pipeline on push to dev Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- .github/workflows/main.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index b15f833..2821ae4 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -5,7 +5,7 @@ on: # types: [labeled] push: branches: - - main + - dev jobs: hello-world-job: runs-on: ubuntu-latest From 43984c923ba4d6a8a09d9c240cff6d4d59ae970d Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Sun, 17 Sep 2023 13:58:48 +0300 Subject: [PATCH 16/87] log package json version Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 561eaf9..17f9f6d 100644 --- a/index.js +++ b/index.js @@ -7,17 +7,13 @@ try { core.setOutput("label", label); + const version = require('./package.json').version; + + console.log(`Version: ${version}`) - fs.readFile('./README.md', 'utf8', (err, data) => { - if (err) { - console.error(err); - return; - } - console.log(`File data: ${data}`); - }); const payload = JSON.stringify(github.context.payload, undefined, 2) - console.log(`The event payload: ${payload}`); + // console.log(`The event payload: ${payload}`); } catch (error) { core.setFailed(error.message); } From 666e5bd43010659d563352e0602b6894bbdf24cc Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Sun, 17 Sep 2023 14:10:48 +0300 Subject: [PATCH 17/87] Increase nodejs project version Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 17f9f6d..4df124e 100644 --- a/index.js +++ b/index.js @@ -8,8 +8,40 @@ try { core.setOutput("label", label); const version = require('./package.json').version; + // the version is in semantic format, so we can split it by dot + const versionParts = version.substring(1).split('.'); + if (label === 'major') + versionParts[0] = parseInt(versionParts[0]) + 1; + else if (label == 'minor') + versionParts[1] = parseInt(versionParts[1]) + 1; + else if (label == 'patch') + versionParts[2] = parseInt(versionParts[2]) + 1; + + + + // increment the patch version + // join the parts back together + const newVersion = `v${versionParts.join('.')}`; + + // Parse XML to JS Obj + xml2js.parseString(data, function (err, result) { + if (err) { + return console.log(err); + } + // Convert JS obj to JSON + const json = JSON.stringify(result, null, 2); + + // Write JSON to file + fs.writeFile('./project.json', json, 'utf8', function (err) { + if (err) { + return console.log(err); + } + console.log('Created project.json from project.csproj'); + }); + }); + + console.log(`Old version: ${version}. New version: ${newVersion}`) - console.log(`Version: ${version}`) const payload = JSON.stringify(github.context.payload, undefined, 2) From 26a5641775b31b30e670b6a1fdf7a8b3d60d2076 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Sun, 17 Sep 2023 14:12:11 +0300 Subject: [PATCH 18/87] Update label name Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- .github/workflows/main.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 2821ae4..d539160 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -27,8 +27,8 @@ jobs: id: hello with: - label: ${{ github.event.label.name }} - + label: minor + # ${{ github.event.label.name }} - name: Get the output time run: | echo The label was label From ba0d5ef4772b5a7f14fb97398bc4b4bed99e7057 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Sun, 17 Sep 2023 14:12:48 +0300 Subject: [PATCH 19/87] Update index.js Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index 4df124e..7f19dca 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,7 @@ const core = require('@actions/core') const github = require('@actions/github') const fs = require('fs') +const xml2js = require('xml2js') try { const label = core.getInput('label'); console.log(`Label: ${label}`) From 06bb905c8dfe0e125a56df76e038a21869fec155 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Sun, 17 Sep 2023 14:13:52 +0300 Subject: [PATCH 20/87] Code cleanup Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 16 ---------------- package-lock.json | 28 +++++++++++++++++++++++++++- package.json | 3 ++- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/index.js b/index.js index 7f19dca..7369418 100644 --- a/index.js +++ b/index.js @@ -24,22 +24,6 @@ try { // join the parts back together const newVersion = `v${versionParts.join('.')}`; - // Parse XML to JS Obj - xml2js.parseString(data, function (err, result) { - if (err) { - return console.log(err); - } - // Convert JS obj to JSON - const json = JSON.stringify(result, null, 2); - - // Write JSON to file - fs.writeFile('./project.json', json, 'utf8', function (err) { - if (err) { - return console.log(err); - } - console.log('Created project.json from project.csproj'); - }); - }); console.log(`Old version: ${version}. New version: ${newVersion}`) diff --git a/package-lock.json b/package-lock.json index 80735e9..7836c28 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,8 @@ "dependencies": { "@actions/core": "^1.10.0", "@actions/github": "^5.1.1", - "@actions/io": "^1.1.3" + "@actions/io": "^1.1.3", + "xml2js": "^0.6.2" }, "devDependencies": { "@types/node": "^20.6.2" @@ -202,6 +203,11 @@ "wrappy": "1" } }, + "node_modules/sax": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", + "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==" + }, "node_modules/tr46": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", @@ -246,6 +252,26 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" + }, + "node_modules/xml2js": { + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.6.2.tgz", + "integrity": "sha512-T4rieHaC1EXcES0Kxxj4JWgaUQHDk+qwHcYOCFHfiwKz7tOVPLq7Hjq9dM1WCMhylqMEfP7hMcOIChvotiZegA==", + "dependencies": { + "sax": ">=0.6.0", + "xmlbuilder": "~11.0.0" + }, + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/xmlbuilder": { + "version": "11.0.1", + "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz", + "integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==", + "engines": { + "node": ">=4.0" + } } } } diff --git a/package.json b/package.json index c8e34fe..3ff8d4c 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "dependencies": { "@actions/core": "^1.10.0", "@actions/github": "^5.1.1", - "@actions/io": "^1.1.3" + "@actions/io": "^1.1.3", + "xml2js": "^0.6.2" }, "devDependencies": { "@types/node": "^20.6.2" From 35766624843157a4036066f0ad543f8a516591a4 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Sun, 17 Sep 2023 14:15:07 +0300 Subject: [PATCH 21/87] log `versionParts` Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 7369418..ef2a8d9 100644 --- a/index.js +++ b/index.js @@ -19,7 +19,7 @@ try { versionParts[2] = parseInt(versionParts[2]) + 1; - + console.log(versionParts) // increment the patch version // join the parts back together const newVersion = `v${versionParts.join('.')}`; From 51bac3bf731db9b4b48737c9863c68b580acb359 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Sun, 17 Sep 2023 14:16:00 +0300 Subject: [PATCH 22/87] Remove substring Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index ef2a8d9..9f504a2 100644 --- a/index.js +++ b/index.js @@ -10,7 +10,7 @@ try { const version = require('./package.json').version; // the version is in semantic format, so we can split it by dot - const versionParts = version.substring(1).split('.'); + const versionParts = version.split('.'); if (label === 'major') versionParts[0] = parseInt(versionParts[0]) + 1; else if (label == 'minor') From 74f60450b3b0c213d4cf0e9e3bfb8522d05a0957 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Sun, 17 Sep 2023 14:17:21 +0300 Subject: [PATCH 23/87] Update indexjs Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 9f504a2..d3a5c4e 100644 --- a/index.js +++ b/index.js @@ -11,10 +11,17 @@ try { const version = require('./package.json').version; // the version is in semantic format, so we can split it by dot const versionParts = version.split('.'); - if (label === 'major') + if (label === 'major') { versionParts[0] = parseInt(versionParts[0]) + 1; - else if (label == 'minor') + versionParts[1] = 0; + versionParts[2] = 0; + + } + else if (label == 'minor') { versionParts[1] = parseInt(versionParts[1]) + 1; + versionParts[2] = 0; + + } else if (label == 'patch') versionParts[2] = parseInt(versionParts[2]) + 1; From ffd7d9f105446462152bf2c916cee8bef675a408 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Sun, 17 Sep 2023 14:24:56 +0300 Subject: [PATCH 24/87] Add file path as input Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- .github/workflows/main.yaml | 2 ++ index.js | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index d539160..e5db041 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -28,6 +28,8 @@ jobs: id: hello with: label: minor + filePath: /package.json + # ${{ github.event.label.name }} - name: Get the output time run: | diff --git a/index.js b/index.js index d3a5c4e..fe12a4b 100644 --- a/index.js +++ b/index.js @@ -4,11 +4,21 @@ const fs = require('fs') const xml2js = require('xml2js') try { const label = core.getInput('label'); + const filePath = core.getInput('filePath'); + console.log(`Label: ${label}`) + console.log(`File path: ${filePath}`) core.setOutput("label", label); - const version = require('./package.json').version; + // if (project == 'dotnetcore') + // filePath = `${filePath}/.csproj`; + // else if (project == 'nodejs') + // filePath = `${filePath}/package.json`; + + const version = require(filePath).version; + + // the version is in semantic format, so we can split it by dot const versionParts = version.split('.'); if (label === 'major') { From d0f80683e79ce59e399a644bff15923593673619 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Sun, 17 Sep 2023 14:28:22 +0300 Subject: [PATCH 25/87] run pwd Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- .github/workflows/main.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index e5db041..86c47e0 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -22,6 +22,9 @@ jobs: - name: Install dependencies run: npm install + - name: PWD + run: echo $PWD + - name: Hello world action step uses: ./ From ecbf260e57ce04f4471b7e7b5d52fff7036b82d6 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Sun, 17 Sep 2023 14:29:45 +0300 Subject: [PATCH 26/87] Add pwd as prefix Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- .github/workflows/main.yaml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 86c47e0..e1d2bf8 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -22,16 +22,13 @@ jobs: - name: Install dependencies run: npm install - - name: PWD - run: echo $PWD - - name: Hello world action step uses: ./ id: hello with: label: minor - filePath: /package.json + filePath: $PWD/package.json # ${{ github.event.label.name }} - name: Get the output time From 02ad452b5a5ef0d70d3e4ebf385ff875d95e4fba Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Sun, 17 Sep 2023 14:33:53 +0300 Subject: [PATCH 27/87] revert PWD Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- .github/workflows/main.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index e1d2bf8..2074d73 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -28,7 +28,7 @@ jobs: id: hello with: label: minor - filePath: $PWD/package.json + filePath: package.json # ${{ github.event.label.name }} - name: Get the output time From 2e5e9bbd3edcd3af0bb94a99f35c4d9b98288e81 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Sun, 17 Sep 2023 14:34:00 +0300 Subject: [PATCH 28/87] Add path prefix Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index fe12a4b..542dade 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,7 @@ const fs = require('fs') const xml2js = require('xml2js') try { const label = core.getInput('label'); - const filePath = core.getInput('filePath'); + const filePath = `../../${core.getInput('filePath')}`; console.log(`Label: ${label}`) console.log(`File path: ${filePath}`) From 617ad417b7bcf53ab7582bb709429ea97e39acd9 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Sun, 17 Sep 2023 14:40:03 +0300 Subject: [PATCH 29/87] Add CWD --- index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 542dade..747c940 100644 --- a/index.js +++ b/index.js @@ -2,9 +2,11 @@ const core = require('@actions/core') const github = require('@actions/github') const fs = require('fs') const xml2js = require('xml2js') + try { + console.log(`CWD: ${process.cwd()}`) const label = core.getInput('label'); - const filePath = `../../${core.getInput('filePath')}`; + const filePath = `${process.cwd()}/${core.getInput('filePath')}`; console.log(`Label: ${label}`) console.log(`File path: ${filePath}`) From 69dbb8f76a967bf3aa56d283ff96f144d8da843a Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Sun, 17 Sep 2023 14:56:57 +0300 Subject: [PATCH 30/87] Adds filepath Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- action.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/action.yml b/action.yml index 5bd0eb1..ea30340 100644 --- a/action.yml +++ b/action.yml @@ -4,6 +4,9 @@ inputs: label: description: "Optional label" required: false + filePath: + description: "File path of the project info (e.g: package.json) relative to the root directory of the repository." + required: true outputs: time: # id of output From fb31fa8b7f9b5c0c49df9ba165b0acccd759d1c6 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Sun, 17 Sep 2023 15:00:41 +0300 Subject: [PATCH 31/87] Update comment Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 747c940..5d6276d 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,7 @@ try { core.setOutput("label", label); - // if (project == 'dotnetcore') + // if (project == 'dotnet') // filePath = `${filePath}/.csproj`; // else if (project == 'nodejs') // filePath = `${filePath}/package.json`; From 36fbfe335670a1ce3f539c11dc9140cb8b35adcb Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Sun, 17 Sep 2023 16:49:51 +0300 Subject: [PATCH 32/87] Change version and commit changes Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- commit.js | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ index.js | 9 +++++-- 2 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 commit.js diff --git a/commit.js b/commit.js new file mode 100644 index 0000000..97c7c53 --- /dev/null +++ b/commit.js @@ -0,0 +1,81 @@ +const axios = require('axios'); + + + + +export async function commitChanges(filePath) { + const commitMessage = 'Commit message here'; + const newContent = 'New content to be added'; + + + // Get the repository owner and name + const repoFullName = process.env.GITHUB_REPOSITORY; + const [owner, repo] = repoFullName.split('/'); + + // Get the current branch + const branch = process.env.GITHUB_REF.replace('refs/heads/', ''); + + try { + // Get the current commit SHA for the branch + const branchResponse = await axios.get( + `https://api.github.com/repos/${owner}/${repo}/branches/${branch}` + ); + + const baseTreeSha = branchResponse.data.commit.sha; + + // Create a new blob with the updated content + const blobResponse = await axios.post( + `https://api.github.com/repos/${owner}/${repo}/git/blobs`, + { + content: newContent, + encoding: 'utf-8', + } + ); + + const newBlobSha = blobResponse.data.sha; + + // Create a new tree with the updated blob + const treeResponse = await axios.post( + `https://api.github.com/repos/${owner}/${repo}/git/trees`, + { + base_tree: baseTreeSha, + tree: [ + { + path: filePath, + mode: '100644', + type: 'blob', + sha: newBlobSha, + }, + ], + } + ); + + const newTreeSha = treeResponse.data.sha; + + // Create a new commit + const commitResponse = await axios.post( + `https://api.github.com/repos/${owner}/${repo}/git/commits`, + { + message: commitMessage, + tree: newTreeSha, + parents: [baseTreeSha], + } + ); + + const newCommitSha = commitResponse.data.sha; + + // Update the branch reference + await axios.patch( + `https://api.github.com/repos/${owner}/${repo}/git/refs/heads/${branch}`, + { + sha: newCommitSha, + } + ); + + console.log('Changes committed successfully!'); + } catch (error) { + console.error('Error committing changes:', error); + } +} + +commitChanges(); diff --git a/index.js b/index.js index 5d6276d..51db9d3 100644 --- a/index.js +++ b/index.js @@ -1,13 +1,14 @@ const core = require('@actions/core') const github = require('@actions/github') const fs = require('fs') -const xml2js = require('xml2js') +import commitChanges from './commit.js'; try { console.log(`CWD: ${process.cwd()}`) const label = core.getInput('label'); const filePath = `${process.cwd()}/${core.getInput('filePath')}`; + console.log(`Label: ${label}`) console.log(`File path: ${filePath}`) @@ -18,7 +19,8 @@ try { // else if (project == 'nodejs') // filePath = `${filePath}/package.json`; - const version = require(filePath).version; + const packageJson = require(filePath); + const version = packageJson.version; // the version is in semantic format, so we can split it by dot @@ -46,7 +48,10 @@ try { console.log(`Old version: ${version}. New version: ${newVersion}`) + packageJson.version = newVersion; + fs.writeFileSync(filePath, JSON.stringify(packageJson, null, 2)); + commitChanges(); const payload = JSON.stringify(github.context.payload, undefined, 2) // console.log(`The event payload: ${payload}`); From 81f74c5925970f426a540fff805501792266dbd2 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Sun, 17 Sep 2023 16:55:00 +0300 Subject: [PATCH 33/87] Delete commit.js and put everything into index.js Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- commit.js | 81 ------------------------- index.js | 172 +++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 126 insertions(+), 127 deletions(-) delete mode 100644 commit.js diff --git a/commit.js b/commit.js deleted file mode 100644 index 97c7c53..0000000 --- a/commit.js +++ /dev/null @@ -1,81 +0,0 @@ -const axios = require('axios'); - - - - -export async function commitChanges(filePath) { - const commitMessage = 'Commit message here'; - const newContent = 'New content to be added'; - - - // Get the repository owner and name - const repoFullName = process.env.GITHUB_REPOSITORY; - const [owner, repo] = repoFullName.split('/'); - - // Get the current branch - const branch = process.env.GITHUB_REF.replace('refs/heads/', ''); - - try { - // Get the current commit SHA for the branch - const branchResponse = await axios.get( - `https://api.github.com/repos/${owner}/${repo}/branches/${branch}` - ); - - const baseTreeSha = branchResponse.data.commit.sha; - - // Create a new blob with the updated content - const blobResponse = await axios.post( - `https://api.github.com/repos/${owner}/${repo}/git/blobs`, - { - content: newContent, - encoding: 'utf-8', - } - ); - - const newBlobSha = blobResponse.data.sha; - - // Create a new tree with the updated blob - const treeResponse = await axios.post( - `https://api.github.com/repos/${owner}/${repo}/git/trees`, - { - base_tree: baseTreeSha, - tree: [ - { - path: filePath, - mode: '100644', - type: 'blob', - sha: newBlobSha, - }, - ], - } - ); - - const newTreeSha = treeResponse.data.sha; - - // Create a new commit - const commitResponse = await axios.post( - `https://api.github.com/repos/${owner}/${repo}/git/commits`, - { - message: commitMessage, - tree: newTreeSha, - parents: [baseTreeSha], - } - ); - - const newCommitSha = commitResponse.data.sha; - - // Update the branch reference - await axios.patch( - `https://api.github.com/repos/${owner}/${repo}/git/refs/heads/${branch}`, - { - sha: newCommitSha, - } - ); - - console.log('Changes committed successfully!'); - } catch (error) { - console.error('Error committing changes:', error); - } -} - -commitChanges(); diff --git a/index.js b/index.js index 51db9d3..8207b95 100644 --- a/index.js +++ b/index.js @@ -1,60 +1,140 @@ const core = require('@actions/core') const github = require('@actions/github') const fs = require('fs') -import commitChanges from './commit.js'; -try { - console.log(`CWD: ${process.cwd()}`) - const label = core.getInput('label'); - const filePath = `${process.cwd()}/${core.getInput('filePath')}`; +async function run() { + try { + console.log(`CWD: ${process.cwd()}`) + const label = core.getInput('label'); + const filePath = `${process.cwd()}/${core.getInput('filePath')}`; - console.log(`Label: ${label}`) - console.log(`File path: ${filePath}`) + console.log(`Label: ${label}`) + console.log(`File path: ${filePath}`) - core.setOutput("label", label); + core.setOutput("label", label); - // if (project == 'dotnet') - // filePath = `${filePath}/.csproj`; - // else if (project == 'nodejs') - // filePath = `${filePath}/package.json`; + // if (project == 'dotnet') + // filePath = `${filePath}/.csproj`; + // else if (project == 'nodejs') + // filePath = `${filePath}/package.json`; - const packageJson = require(filePath); - const version = packageJson.version; + const packageJson = require(filePath); + const version = packageJson.version; - // the version is in semantic format, so we can split it by dot - const versionParts = version.split('.'); - if (label === 'major') { - versionParts[0] = parseInt(versionParts[0]) + 1; - versionParts[1] = 0; - versionParts[2] = 0; + // the version is in semantic format, so we can split it by dot + const versionParts = version.split('.'); + if (label === 'major') { + versionParts[0] = parseInt(versionParts[0]) + 1; + versionParts[1] = 0; + versionParts[2] = 0; + } + else if (label == 'minor') { + versionParts[1] = parseInt(versionParts[1]) + 1; + versionParts[2] = 0; + + } + else if (label == 'patch') + versionParts[2] = parseInt(versionParts[2]) + 1; + + + console.log(versionParts) + // increment the patch version + // join the parts back together + const newVersion = `v${versionParts.join('.')}`; + + + console.log(`Old version: ${version}. New version: ${newVersion}`) + + packageJson.version = newVersion; + + fs.writeFileSync(filePath, JSON.stringify(packageJson, null, 2)); + + await commitChanges(); + + const payload = JSON.stringify(github.context.payload, undefined, 2) + + // console.log(`The event payload: ${payload}`); + } catch (error) { + core.setFailed(error.message); + } +} + + +// Region functions +async function commitChanges(filePath) { + const commitMessage = 'Commit message here'; + const newContent = 'New content to be added'; + + + // Get the repository owner and name + const repoFullName = process.env.GITHUB_REPOSITORY; + const [owner, repo] = repoFullName.split('/'); + + // Get the current branch + const branch = process.env.GITHUB_REF.replace('refs/heads/', ''); + + try { + // Get the current commit SHA for the branch + const branchResponse = await axios.get( + `https://api.github.com/repos/${owner}/${repo}/branches/${branch}` + ); + + const baseTreeSha = branchResponse.data.commit.sha; + + // Create a new blob with the updated content + const blobResponse = await axios.post( + `https://api.github.com/repos/${owner}/${repo}/git/blobs`, + { + content: newContent, + encoding: 'utf-8', + } + ); + + const newBlobSha = blobResponse.data.sha; + + // Create a new tree with the updated blob + const treeResponse = await axios.post( + `https://api.github.com/repos/${owner}/${repo}/git/trees`, + { + base_tree: baseTreeSha, + tree: [ + { + path: filePath, + mode: '100644', + type: 'blob', + sha: newBlobSha, + }, + ], + } + ); + + const newTreeSha = treeResponse.data.sha; + + // Create a new commit + const commitResponse = await axios.post( + `https://api.github.com/repos/${owner}/${repo}/git/commits`, + { + message: commitMessage, + tree: newTreeSha, + parents: [baseTreeSha], + } + ); + + const newCommitSha = commitResponse.data.sha; + + // Update the branch reference + await axios.patch( + `https://api.github.com/repos/${owner}/${repo}/git/refs/heads/${branch}`, + { + sha: newCommitSha, + } + ); + + console.log('Changes committed successfully!'); + } catch (error) { + console.error('Error committing changes:', error); } - else if (label == 'minor') { - versionParts[1] = parseInt(versionParts[1]) + 1; - versionParts[2] = 0; - - } - else if (label == 'patch') - versionParts[2] = parseInt(versionParts[2]) + 1; - - - console.log(versionParts) - // increment the patch version - // join the parts back together - const newVersion = `v${versionParts.join('.')}`; - - - console.log(`Old version: ${version}. New version: ${newVersion}`) - - packageJson.version = newVersion; - - fs.writeFileSync(filePath, JSON.stringify(packageJson, null, 2)); - commitChanges(); - const payload = JSON.stringify(github.context.payload, undefined, 2) - - // console.log(`The event payload: ${payload}`); -} catch (error) { - core.setFailed(error.message); } From b635f35c0fe76dac48cf3decd1be30582417a0c2 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Sun, 17 Sep 2023 16:56:59 +0300 Subject: [PATCH 34/87] run main function Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.js b/index.js index 8207b95..773d91c 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ const core = require('@actions/core') const github = require('@actions/github') const fs = require('fs') +run(); async function run() { try { console.log(`CWD: ${process.cwd()}`) @@ -138,3 +139,4 @@ async function commitChanges(filePath) { console.error('Error committing changes:', error); } } + From 3ffcf00985d13e9e5d896745516b634bb6d812a7 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Sun, 17 Sep 2023 16:57:46 +0300 Subject: [PATCH 35/87] import axios Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index 773d91c..e4e4aa5 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,7 @@ const core = require('@actions/core') const github = require('@actions/github') const fs = require('fs') +const axios = require('axios'); run(); async function run() { From 67e0f417127adb0a84e17d19a188d6c018240db9 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Sun, 17 Sep 2023 16:59:04 +0300 Subject: [PATCH 36/87] npm i axios Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- package-lock.json | 91 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 92 insertions(+) diff --git a/package-lock.json b/package-lock.json index 7836c28..adac13d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "@actions/core": "^1.10.0", "@actions/github": "^5.1.1", "@actions/io": "^1.1.3", + "axios": "^1.5.0", "xml2js": "^0.6.2" }, "devDependencies": { @@ -158,16 +159,82 @@ "integrity": "sha512-Y+/1vGBHV/cYk6OI1Na/LHzwnlNCAfU3ZNGrc1LdRe/LAIbdDPTTv/HU3M7yXN448aTVDq3eKRm2cg7iKLb8gw==", "dev": true }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + }, + "node_modules/axios": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.5.0.tgz", + "integrity": "sha512-D4DdjDo5CY50Qms0qGQTTw6Q44jl7zRwY7bthds06pUGfChBCTcQs+N743eFWGEd6pRTMd6A+I87aWyFV5wiZQ==", + "dependencies": { + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/before-after-hook": { "version": "2.2.3", "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.2.3.tgz", "integrity": "sha512-NzUnlZexiaH/46WDhANlyR2bXRopNg4F/zuSA3OpZnllCUgRaOF2znDioDWrmbNVsuZk6l9pMquQB38cfBZwkQ==" }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/deprecation": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/deprecation/-/deprecation-2.3.1.tgz", "integrity": "sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ==" }, + "node_modules/follow-redirects": { + "version": "1.15.2", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", + "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, + "node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/is-plain-object": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-5.0.0.tgz", @@ -176,6 +243,25 @@ "node": ">=0.10.0" } }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, "node_modules/node-fetch": { "version": "2.7.0", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", @@ -203,6 +289,11 @@ "wrappy": "1" } }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "node_modules/sax": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", diff --git a/package.json b/package.json index 3ff8d4c..05f823b 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "@actions/core": "^1.10.0", "@actions/github": "^5.1.1", "@actions/io": "^1.1.3", + "axios": "^1.5.0", "xml2js": "^0.6.2" }, "devDependencies": { From 5d6d6473f7a723b0aac940ece3fb24978079bcb6 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Sun, 17 Sep 2023 17:02:38 +0300 Subject: [PATCH 37/87] Add more logs Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/index.js b/index.js index e4e4aa5..e62b348 100644 --- a/index.js +++ b/index.js @@ -84,6 +84,7 @@ async function commitChanges(filePath) { `https://api.github.com/repos/${owner}/${repo}/branches/${branch}` ); + console.log('branchResponse: ' + branchResponse.data) const baseTreeSha = branchResponse.data.commit.sha; // Create a new blob with the updated content @@ -94,6 +95,7 @@ async function commitChanges(filePath) { encoding: 'utf-8', } ); + console.log('blobResponse: ' + blobResponse.data) const newBlobSha = blobResponse.data.sha; @@ -113,6 +115,7 @@ async function commitChanges(filePath) { } ); + console.log('treeResponse: ' + treeResponse.data) const newTreeSha = treeResponse.data.sha; // Create a new commit From 1939c927d85872ed270a6ff2988412ed5cde6edc Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Mon, 18 Sep 2023 14:55:56 +0300 Subject: [PATCH 38/87] Use github token Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- .github/workflows/main.yaml | 2 +- action.yml | 3 +++ index.js | 11 ++++++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 2074d73..3110674 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -24,11 +24,11 @@ jobs: - name: Hello world action step uses: ./ - id: hello with: label: minor filePath: package.json + repo-token: ${{ secrets.GITHUB_TOKEN }} # ${{ github.event.label.name }} - name: Get the output time diff --git a/action.yml b/action.yml index ea30340..b4f9255 100644 --- a/action.yml +++ b/action.yml @@ -7,6 +7,9 @@ inputs: filePath: description: "File path of the project info (e.g: package.json) relative to the root directory of the repository." required: true + repoToken: + description: GitHub repository token + required: true outputs: time: # id of output diff --git a/index.js b/index.js index e62b348..bb70300 100644 --- a/index.js +++ b/index.js @@ -7,6 +7,7 @@ run(); async function run() { try { console.log(`CWD: ${process.cwd()}`) + const label = core.getInput('label'); const filePath = `${process.cwd()}/${core.getInput('filePath')}`; @@ -27,6 +28,7 @@ async function run() { // the version is in semantic format, so we can split it by dot const versionParts = version.split('.'); + // 1.2.3 => [1, 2, 3] if (label === 'major') { versionParts[0] = parseInt(versionParts[0]) + 1; versionParts[1] = 0; @@ -45,7 +47,7 @@ async function run() { console.log(versionParts) // increment the patch version // join the parts back together - const newVersion = `v${versionParts.join('.')}`; + const newVersion = versionParts.join('.'); console.log(`Old version: ${version}. New version: ${newVersion}`) @@ -69,6 +71,7 @@ async function run() { async function commitChanges(filePath) { const commitMessage = 'Commit message here'; const newContent = 'New content to be added'; + const githubToken = core.getInput('githubToken'); // Get the repository owner and name @@ -93,6 +96,12 @@ async function commitChanges(filePath) { { content: newContent, encoding: 'utf-8', + }, + { + headers: { + Accept: 'application/vnd.github.v3+json', + Authorization: `Bearer ${githubToken}`, + }, } ); console.log('blobResponse: ' + blobResponse.data) From dea55b985d6f2ee8f05efff9308c1dcdedfc52d8 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Mon, 18 Sep 2023 14:56:10 +0300 Subject: [PATCH 39/87] Update main Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- .github/workflows/main.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 3110674..bb3cf52 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -28,7 +28,7 @@ jobs: with: label: minor filePath: package.json - repo-token: ${{ secrets.GITHUB_TOKEN }} + repoToken: ${{ secrets.GITHUB_TOKEN }} # ${{ github.event.label.name }} - name: Get the output time From 35faf1fbb896f86ae7e8252e4412922d32a3c82c Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Mon, 18 Sep 2023 15:02:30 +0300 Subject: [PATCH 40/87] print github token Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- .github/workflows/main.yaml | 3 +++ index.js | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index bb3cf52..5fc47fe 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -22,6 +22,9 @@ jobs: - name: Install dependencies run: npm install + - name: Print GitHub token + run: echo ${{ secrets.GITHUB_TOKEN }} + - name: Hello world action step uses: ./ id: hello diff --git a/index.js b/index.js index bb70300..356f40e 100644 --- a/index.js +++ b/index.js @@ -99,8 +99,8 @@ async function commitChanges(filePath) { }, { headers: { - Accept: 'application/vnd.github.v3+json', - Authorization: `Bearer ${githubToken}`, + 'Accept': 'application/vnd.github.v3+json', + 'Authorization': `Bearer ${githubToken}`, }, } ); From ba0a44fe51388ca3e9021fe3ea0ef2707776e63b Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Mon, 18 Sep 2023 15:06:39 +0300 Subject: [PATCH 41/87] test branding Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- action.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/action.yml b/action.yml index b4f9255..86d1e3f 100644 --- a/action.yml +++ b/action.yml @@ -18,3 +18,6 @@ outputs: runs: using: "node20" main: "index.js" +branding: + icon: "mic" + color: "green" From 6a355c1ef186857c03fb68c760bce4e9388c220f Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Mon, 18 Sep 2023 15:08:40 +0300 Subject: [PATCH 42/87] rename repoToken to githubToken Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- .github/workflows/main.yaml | 2 +- action.yml | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 5fc47fe..64dbf44 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -31,7 +31,7 @@ jobs: with: label: minor filePath: package.json - repoToken: ${{ secrets.GITHUB_TOKEN }} + githubToken: ${{ secrets.GITHUB_TOKEN }} # ${{ github.event.label.name }} - name: Get the output time diff --git a/action.yml b/action.yml index 86d1e3f..2561992 100644 --- a/action.yml +++ b/action.yml @@ -7,7 +7,7 @@ inputs: filePath: description: "File path of the project info (e.g: package.json) relative to the root directory of the repository." required: true - repoToken: + githubToken: description: GitHub repository token required: true @@ -18,6 +18,3 @@ outputs: runs: using: "node20" main: "index.js" -branding: - icon: "mic" - color: "green" From 60ade716eb9725671fc8923ad512b4f790a87d4a Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Mon, 18 Sep 2023 15:08:54 +0300 Subject: [PATCH 43/87] Code cleanup Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- .github/workflows/main.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 64dbf44..75e9686 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -22,9 +22,6 @@ jobs: - name: Install dependencies run: npm install - - name: Print GitHub token - run: echo ${{ secrets.GITHUB_TOKEN }} - - name: Hello world action step uses: ./ id: hello From 46425d61c3d04bb646fd84ba44aaaf05c5717f75 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Mon, 18 Sep 2023 15:13:24 +0300 Subject: [PATCH 44/87] Adds Authorization header to create tree request Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/index.js b/index.js index 356f40e..ce99d92 100644 --- a/index.js +++ b/index.js @@ -121,6 +121,11 @@ async function commitChanges(filePath) { sha: newBlobSha, }, ], + }, + { + headers: { + 'Authorization': `Bearer ${githubToken}`, + }, } ); From 5359015c6154b1ee8630fb2f7c7a993c93dece66 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Mon, 18 Sep 2023 15:16:25 +0300 Subject: [PATCH 45/87] Update header for tree request Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index ce99d92..d393a84 100644 --- a/index.js +++ b/index.js @@ -124,6 +124,7 @@ async function commitChanges(filePath) { }, { headers: { + 'Accept': 'application/vnd.github.v3+json', 'Authorization': `Bearer ${githubToken}`, }, } From 1dff45e6ceece5a5c6d798d92a95a2806f756e72 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Mon, 18 Sep 2023 15:16:35 +0300 Subject: [PATCH 46/87] Add header for commit request Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/index.js b/index.js index d393a84..639d9f5 100644 --- a/index.js +++ b/index.js @@ -140,6 +140,12 @@ async function commitChanges(filePath) { message: commitMessage, tree: newTreeSha, parents: [baseTreeSha], + }, + { + headers: { + 'Accept': 'application/vnd.github.v3+json', + 'Authorization': `Bearer ${githubToken}`, + }, } ); From 12a487f9c57f052190bfc7f25e7337930f03baed Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Mon, 18 Sep 2023 15:21:13 +0300 Subject: [PATCH 47/87] send filePath to `commitChanges` function Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 639d9f5..6f7c398 100644 --- a/index.js +++ b/index.js @@ -56,7 +56,7 @@ async function run() { fs.writeFileSync(filePath, JSON.stringify(packageJson, null, 2)); - await commitChanges(); + await commitChanges(filePath); const payload = JSON.stringify(github.context.payload, undefined, 2) From 8d082d9bf8cc6112776573eea81ee33ccc8990bf Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Mon, 18 Sep 2023 15:27:10 +0300 Subject: [PATCH 48/87] Update `Accept` header in tree request Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/index.js b/index.js index 6f7c398..a4c5298 100644 --- a/index.js +++ b/index.js @@ -107,7 +107,6 @@ async function commitChanges(filePath) { console.log('blobResponse: ' + blobResponse.data) const newBlobSha = blobResponse.data.sha; - // Create a new tree with the updated blob const treeResponse = await axios.post( `https://api.github.com/repos/${owner}/${repo}/git/trees`, @@ -124,7 +123,7 @@ async function commitChanges(filePath) { }, { headers: { - 'Accept': 'application/vnd.github.v3+json', + 'Accept': 'application/vnd.github+json', 'Authorization': `Bearer ${githubToken}`, }, } From e99909cbdbbc65a8703b5149c7625c8de3050f0a Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Mon, 18 Sep 2023 15:29:05 +0300 Subject: [PATCH 49/87] Update tree request headers Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index a4c5298..17c1cf2 100644 --- a/index.js +++ b/index.js @@ -125,6 +125,7 @@ async function commitChanges(filePath) { headers: { 'Accept': 'application/vnd.github+json', 'Authorization': `Bearer ${githubToken}`, + 'X-GitHub-Api-Version': '2022-11-28' }, } ); From 6167fab78c311fe9a8189f85a830a0e8adb44e8f Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Mon, 18 Sep 2023 15:35:48 +0300 Subject: [PATCH 50/87] Update commitChanges parameter Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 17c1cf2..c55f075 100644 --- a/index.js +++ b/index.js @@ -56,7 +56,7 @@ async function run() { fs.writeFileSync(filePath, JSON.stringify(packageJson, null, 2)); - await commitChanges(filePath); + await commitChanges(core.getInput('filePath')); const payload = JSON.stringify(github.context.payload, undefined, 2) From 4e6a7aea8839cf07ff3b77551d8385027865198e Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Mon, 18 Sep 2023 15:37:28 +0300 Subject: [PATCH 51/87] Update commit request headers Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index c55f075..5218536 100644 --- a/index.js +++ b/index.js @@ -124,8 +124,7 @@ async function commitChanges(filePath) { { headers: { 'Accept': 'application/vnd.github+json', - 'Authorization': `Bearer ${githubToken}`, - 'X-GitHub-Api-Version': '2022-11-28' + 'Authorization': `Bearer ${githubToken}` }, } ); @@ -143,7 +142,7 @@ async function commitChanges(filePath) { }, { headers: { - 'Accept': 'application/vnd.github.v3+json', + 'Accept': 'application/vnd.github+json', 'Authorization': `Bearer ${githubToken}`, }, } From aeaf77a84e826fe0683a2753ef5c1ad6348e56c6 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Mon, 18 Sep 2023 15:39:37 +0300 Subject: [PATCH 52/87] Update logs Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 5218536..7b7e70e 100644 --- a/index.js +++ b/index.js @@ -104,7 +104,7 @@ async function commitChanges(filePath) { }, } ); - console.log('blobResponse: ' + blobResponse.data) + console.log('blobResponse success') const newBlobSha = blobResponse.data.sha; // Create a new tree with the updated blob @@ -129,7 +129,7 @@ async function commitChanges(filePath) { } ); - console.log('treeResponse: ' + treeResponse.data) + console.log('treeResponse success') const newTreeSha = treeResponse.data.sha; // Create a new commit @@ -148,6 +148,7 @@ async function commitChanges(filePath) { } ); + console.log('commitResponse success') const newCommitSha = commitResponse.data.sha; // Update the branch reference From 7af195f0bc84f0d385d26ce3016691b55724e190 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Mon, 18 Sep 2023 15:41:28 +0300 Subject: [PATCH 53/87] Update patch request headers Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/index.js b/index.js index 7b7e70e..a21a8b2 100644 --- a/index.js +++ b/index.js @@ -156,6 +156,12 @@ async function commitChanges(filePath) { `https://api.github.com/repos/${owner}/${repo}/git/refs/heads/${branch}`, { sha: newCommitSha, + }, + { + headers: { + 'Accept': 'application/vnd.github+json', + 'Authorization': `Bearer ${githubToken}`, + }, } ); From ed64defb13d3de168db4a0491e02c00169a17948 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 18 Sep 2023 12:41:48 +0000 Subject: [PATCH 54/87] Commit message here --- package.json | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/package.json b/package.json index 05f823b..40c602f 100644 --- a/package.json +++ b/package.json @@ -1,22 +1 @@ -{ - "name": "docker-container-action", - "version": "1.0.0", - "description": "This action prints \"Hello World\" or \"Hello\" + the name of a person to greet to the log.", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "keywords": [], - "author": "", - "license": "ISC", - "dependencies": { - "@actions/core": "^1.10.0", - "@actions/github": "^5.1.1", - "@actions/io": "^1.1.3", - "axios": "^1.5.0", - "xml2js": "^0.6.2" - }, - "devDependencies": { - "@types/node": "^20.6.2" - } -} +New content to be added \ No newline at end of file From 383094e32dea8aef71583cc904434989c8b4371d Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Tue, 19 Sep 2023 10:27:31 +0300 Subject: [PATCH 55/87] Search for project info file in root directory Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/index.js b/index.js index a21a8b2..0e21873 100644 --- a/index.js +++ b/index.js @@ -8,19 +8,16 @@ async function run() { try { console.log(`CWD: ${process.cwd()}`) - const label = core.getInput('label'); - const filePath = `${process.cwd()}/${core.getInput('filePath')}`; + const filePathInput = core.getInput('filePath'); + const labelInput = core.getInput('label'); + + const filePath = getProjectInfoFile(filePathInput); - console.log(`Label: ${label}`) + console.log(`Label: ${labelInput}`) console.log(`File path: ${filePath}`) - core.setOutput("label", label); - - // if (project == 'dotnet') - // filePath = `${filePath}/.csproj`; - // else if (project == 'nodejs') - // filePath = `${filePath}/package.json`; + core.setOutput("label", labelInput); const packageJson = require(filePath); const version = packageJson.version; @@ -29,23 +26,22 @@ async function run() { // the version is in semantic format, so we can split it by dot const versionParts = version.split('.'); // 1.2.3 => [1, 2, 3] - if (label === 'major') { + if (labelInput === 'major') { versionParts[0] = parseInt(versionParts[0]) + 1; versionParts[1] = 0; versionParts[2] = 0; } - else if (label == 'minor') { + else if (labelInput == 'minor') { versionParts[1] = parseInt(versionParts[1]) + 1; versionParts[2] = 0; } - else if (label == 'patch') + else if (labelInput == 'patch') + // increment the patch version versionParts[2] = parseInt(versionParts[2]) + 1; - console.log(versionParts) - // increment the patch version // join the parts back together const newVersion = versionParts.join('.'); @@ -129,7 +125,6 @@ async function commitChanges(filePath) { } ); - console.log('treeResponse success') const newTreeSha = treeResponse.data.sha; // Create a new commit @@ -148,7 +143,6 @@ async function commitChanges(filePath) { } ); - console.log('commitResponse success') const newCommitSha = commitResponse.data.sha; // Update the branch reference @@ -164,10 +158,20 @@ async function commitChanges(filePath) { }, } ); - - console.log('Changes committed successfully!'); } catch (error) { - console.error('Error committing changes:', error); + core.setFailed(error.message); + } } +function getProjectInfoFile(filePathInput) { + if (filePathInput == null || filePathInput == undefined || filePathInput == '') { + // List files inside the root directory of the repository + const files = fs.readdirSync(process.cwd()); + // Return the first file that matches .csproj or package.json + const projectInfoFile = files.find(file => file.match(/\.csproj|package\.json/)); + return `${process.cwd()}/${projectInfoFile}`; + } + else + return `${process.cwd()}/${filePathInput}`; +} From 633a83664c50eadb062cc7beaf2b15a774c5bed1 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Tue, 19 Sep 2023 10:28:03 +0300 Subject: [PATCH 56/87] Don't send `filePath` input to test out it's functionality Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- .github/workflows/main.yaml | 1 - action.yml | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 75e9686..4c340c2 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -27,7 +27,6 @@ jobs: id: hello with: label: minor - filePath: package.json githubToken: ${{ secrets.GITHUB_TOKEN }} # ${{ github.event.label.name }} diff --git a/action.yml b/action.yml index 2561992..1c0992f 100644 --- a/action.yml +++ b/action.yml @@ -6,7 +6,7 @@ inputs: required: false filePath: description: "File path of the project info (e.g: package.json) relative to the root directory of the repository." - required: true + required: false githubToken: description: GitHub repository token required: true From 1e31d49f272ce836a1b332bbeee49dd9118e9763 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Tue, 19 Sep 2023 10:29:14 +0300 Subject: [PATCH 57/87] Revert "Commit message here" This reverts commit ed64defb13d3de168db4a0491e02c00169a17948. --- package.json | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 40c602f..05f823b 100644 --- a/package.json +++ b/package.json @@ -1 +1,22 @@ -New content to be added \ No newline at end of file +{ + "name": "docker-container-action", + "version": "1.0.0", + "description": "This action prints \"Hello World\" or \"Hello\" + the name of a person to greet to the log.", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "@actions/core": "^1.10.0", + "@actions/github": "^5.1.1", + "@actions/io": "^1.1.3", + "axios": "^1.5.0", + "xml2js": "^0.6.2" + }, + "devDependencies": { + "@types/node": "^20.6.2" + } +} From 8d8142bf0e386b4849c5085c23d89841793a1c3e Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Tue, 19 Sep 2023 10:58:54 +0300 Subject: [PATCH 58/87] Organize the codebase Add support for dotnet projects Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/index.js b/index.js index 0e21873..86c6ebc 100644 --- a/index.js +++ b/index.js @@ -11,17 +11,15 @@ async function run() { const filePathInput = core.getInput('filePath'); const labelInput = core.getInput('label'); - const filePath = getProjectInfoFile(filePathInput); + const file = getProjectInfoFile(filePathInput); console.log(`Label: ${labelInput}`) - console.log(`File path: ${filePath}`) + console.log(`File path: ${file}`) core.setOutput("label", labelInput); - const packageJson = require(filePath); - const version = packageJson.version; - + const version = getProjectVersion(file); // the version is in semantic format, so we can split it by dot const versionParts = version.split('.'); @@ -45,14 +43,13 @@ async function run() { // join the parts back together const newVersion = versionParts.join('.'); + updateProjectVersion(file, newVersion); console.log(`Old version: ${version}. New version: ${newVersion}`) - packageJson.version = newVersion; + fs.writeFileSync(file, JSON.stringify(projectInfoFile, null, 2)); - fs.writeFileSync(filePath, JSON.stringify(packageJson, null, 2)); - - await commitChanges(core.getInput('filePath')); + await commitChanges(core.getInput('filePath'), file); const payload = JSON.stringify(github.context.payload, undefined, 2) @@ -64,9 +61,9 @@ async function run() { // Region functions -async function commitChanges(filePath) { +async function commitChanges(filePath, file) { const commitMessage = 'Commit message here'; - const newContent = 'New content to be added'; + const newContent = file; const githubToken = core.getInput('githubToken'); @@ -83,7 +80,6 @@ async function commitChanges(filePath) { `https://api.github.com/repos/${owner}/${repo}/branches/${branch}` ); - console.log('branchResponse: ' + branchResponse.data) const baseTreeSha = branchResponse.data.commit.sha; // Create a new blob with the updated content @@ -100,7 +96,6 @@ async function commitChanges(filePath) { }, } ); - console.log('blobResponse success') const newBlobSha = blobResponse.data.sha; // Create a new tree with the updated blob @@ -164,14 +159,32 @@ async function commitChanges(filePath) { } } -function getProjectInfoFile(filePathInput) { - if (filePathInput == null || filePathInput == undefined || filePathInput == '') { +function getProjectInfoFile(filePath) { + if (filePath == null || filePath == undefined || filePath == '') { // List files inside the root directory of the repository const files = fs.readdirSync(process.cwd()); // Return the first file that matches .csproj or package.json const projectInfoFile = files.find(file => file.match(/\.csproj|package\.json/)); - return `${process.cwd()}/${projectInfoFile}`; + return require(`${process.cwd()}/${projectInfoFile}`); } else - return `${process.cwd()}/${filePathInput}`; + return require(`${process.cwd()}/${filePath}`); +} + +function getProjectVersion(file) { + + // Update the version if the file is .csproj + if (file.match(/\.csproj/)) + return file.Project.PropertyGroup[0].Version; + else if (file.match(/package\.json/)) + return file.version; + +} +function updateProjectVersion(file, newVersion) { + + // Update the version if the file is .csproj + if (file.match(/\.csproj/)) + file.Project.PropertyGroup[0].Version = newVersion; + else if (file.match(/package\.json/)) + file.version = newVersion; } From 337fc055f9125b817401e6147274ca2db461a124 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Tue, 19 Sep 2023 11:04:40 +0300 Subject: [PATCH 59/87] Fix errors Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 86c6ebc..198aff2 100644 --- a/index.js +++ b/index.js @@ -171,20 +171,23 @@ function getProjectInfoFile(filePath) { return require(`${process.cwd()}/${filePath}`); } -function getProjectVersion(file) { +function getProjectVersion(filePath) { + const projectInfoFile = require(filePath); // Update the version if the file is .csproj - if (file.match(/\.csproj/)) - return file.Project.PropertyGroup[0].Version; - else if (file.match(/package\.json/)) - return file.version; + if (filePath.match(/\.csproj/)) + return projectInfoFile.Project.PropertyGroup[0].Version; + else if (filePath.match(/package\.json/)) + return projectInfoFile.version; } -function updateProjectVersion(file, newVersion) { +function updateProjectVersion(filePath, newVersion) { + + const projectInfoFile = require(filePath); // Update the version if the file is .csproj - if (file.match(/\.csproj/)) - file.Project.PropertyGroup[0].Version = newVersion; - else if (file.match(/package\.json/)) - file.version = newVersion; + if (filePath.match(/\.csproj/)) + projectInfoFile.Project.PropertyGroup[0].Version = newVersion; + else if (filePath.match(/package\.json/)) + projectInfoFile.version = newVersion; } From fd3c042b3e7c31397975aa12cd36e1da3a5ed094 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Tue, 19 Sep 2023 11:08:04 +0300 Subject: [PATCH 60/87] fix file path error Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 198aff2..06b8d0c 100644 --- a/index.js +++ b/index.js @@ -11,7 +11,8 @@ async function run() { const filePathInput = core.getInput('filePath'); const labelInput = core.getInput('label'); - const file = getProjectInfoFile(filePathInput); + const filePath = getProjectInfoFilePath(filePathInput); + const file = require(filePath); console.log(`Label: ${labelInput}`) @@ -19,7 +20,7 @@ async function run() { core.setOutput("label", labelInput); - const version = getProjectVersion(file); + const version = getProjectVersion(filePath); // the version is in semantic format, so we can split it by dot const versionParts = version.split('.'); @@ -43,7 +44,7 @@ async function run() { // join the parts back together const newVersion = versionParts.join('.'); - updateProjectVersion(file, newVersion); + updateProjectVersion(filePath, newVersion); console.log(`Old version: ${version}. New version: ${newVersion}`) @@ -159,18 +160,17 @@ async function commitChanges(filePath, file) { } } -function getProjectInfoFile(filePath) { +function getProjectInfoFilePath(filePath) { if (filePath == null || filePath == undefined || filePath == '') { // List files inside the root directory of the repository const files = fs.readdirSync(process.cwd()); // Return the first file that matches .csproj or package.json const projectInfoFile = files.find(file => file.match(/\.csproj|package\.json/)); - return require(`${process.cwd()}/${projectInfoFile}`); + return `${process.cwd()}/${projectInfoFile}`; } else - return require(`${process.cwd()}/${filePath}`); + return `${process.cwd()}/${filePath}`; } - function getProjectVersion(filePath) { const projectInfoFile = require(filePath); From 509255af643495f4979de1e33aff7f83032ec9f9 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Tue, 19 Sep 2023 11:09:54 +0300 Subject: [PATCH 61/87] Fix error: projectInfoFile is not defined Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 06b8d0c..0398e10 100644 --- a/index.js +++ b/index.js @@ -48,7 +48,7 @@ async function run() { console.log(`Old version: ${version}. New version: ${newVersion}`) - fs.writeFileSync(file, JSON.stringify(projectInfoFile, null, 2)); + fs.writeFileSync(file, JSON.stringify(file, null, 2)); await commitChanges(core.getInput('filePath'), file); From fdd674f533d247030d6d66003a7a2d5e76787dd8 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Tue, 19 Sep 2023 11:10:41 +0300 Subject: [PATCH 62/87] Fix error: The "path" argument must be of type string or an instance of Buffer or URL. Received an instance of Object Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 0398e10..4c95ee9 100644 --- a/index.js +++ b/index.js @@ -48,7 +48,7 @@ async function run() { console.log(`Old version: ${version}. New version: ${newVersion}`) - fs.writeFileSync(file, JSON.stringify(file, null, 2)); + fs.writeFileSync(file, JSON.stringify(filePath, null, 2)); await commitChanges(core.getInput('filePath'), file); From d56581ce1a5e6274a469ef9b7ddcb49424d19844 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Tue, 19 Sep 2023 11:13:05 +0300 Subject: [PATCH 63/87] Fix Error: The "path" argument must be of type string or an instance of Buffer or URL. Received an instance of Object Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 4c95ee9..f4fc096 100644 --- a/index.js +++ b/index.js @@ -48,9 +48,9 @@ async function run() { console.log(`Old version: ${version}. New version: ${newVersion}`) - fs.writeFileSync(file, JSON.stringify(filePath, null, 2)); + fs.writeFileSync(file, JSON.stringify(file, null, 2)); - await commitChanges(core.getInput('filePath'), file); + await commitChanges(core.getInput('filePath'), JSON.stringify(file, null, 2)); const payload = JSON.stringify(github.context.payload, undefined, 2) From e26c8c577686ebca2748637fe59df1dd3ff61519 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Tue, 19 Sep 2023 11:13:50 +0300 Subject: [PATCH 64/87] Comment out the fileWrite function Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index f4fc096..b8475b3 100644 --- a/index.js +++ b/index.js @@ -48,7 +48,7 @@ async function run() { console.log(`Old version: ${version}. New version: ${newVersion}`) - fs.writeFileSync(file, JSON.stringify(file, null, 2)); + // fs.writeFileSync(file, JSON.stringify(file, null, 2)); await commitChanges(core.getInput('filePath'), JSON.stringify(file, null, 2)); From 44b0f0aa90a3860293db29db84f97a3d09930cd1 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Tue, 19 Sep 2023 11:14:37 +0300 Subject: [PATCH 65/87] Test Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index b8475b3..7135a3d 100644 --- a/index.js +++ b/index.js @@ -50,7 +50,7 @@ async function run() { // fs.writeFileSync(file, JSON.stringify(file, null, 2)); - await commitChanges(core.getInput('filePath'), JSON.stringify(file, null, 2)); + await commitChanges(core.getInput('filePath'), file); const payload = JSON.stringify(github.context.payload, undefined, 2) From 2abe8e9c5fa71eaca2d587b0326be95cdb95fcf5 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Tue, 19 Sep 2023 11:15:40 +0300 Subject: [PATCH 66/87] Print error in detail Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 7135a3d..d8ef376 100644 --- a/index.js +++ b/index.js @@ -155,7 +155,7 @@ async function commitChanges(filePath, file) { } ); } catch (error) { - core.setFailed(error.message); + core.setFailed(error); } } From 37ae560d8cd5bdfebe488195307330b619c089f1 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Tue, 19 Sep 2023 11:16:53 +0300 Subject: [PATCH 67/87] stringify contnet Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index d8ef376..3e0c5cd 100644 --- a/index.js +++ b/index.js @@ -87,7 +87,7 @@ async function commitChanges(filePath, file) { const blobResponse = await axios.post( `https://api.github.com/repos/${owner}/${repo}/git/blobs`, { - content: newContent, + content: JSON.stringify(newContent), encoding: 'utf-8', }, { From ae2dbd7484a22cc830a1d218147f01386c4f7b9f Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Tue, 19 Sep 2023 11:17:36 +0300 Subject: [PATCH 68/87] Add logs Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 3e0c5cd..1cadeca 100644 --- a/index.js +++ b/index.js @@ -82,7 +82,7 @@ async function commitChanges(filePath, file) { ); const baseTreeSha = branchResponse.data.commit.sha; - + console.log(file) // Create a new blob with the updated content const blobResponse = await axios.post( `https://api.github.com/repos/${owner}/${repo}/git/blobs`, From 556815239c98da24cf2b1597c1f20cb8545bd3ec Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Tue, 19 Sep 2023 11:19:45 +0300 Subject: [PATCH 69/87] Add more logs Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 1cadeca..0a7e3de 100644 --- a/index.js +++ b/index.js @@ -82,7 +82,7 @@ async function commitChanges(filePath, file) { ); const baseTreeSha = branchResponse.data.commit.sha; - console.log(file) + console.log(typeof file, file) // Create a new blob with the updated content const blobResponse = await axios.post( `https://api.github.com/repos/${owner}/${repo}/git/blobs`, @@ -98,6 +98,7 @@ async function commitChanges(filePath, file) { } ); + console.log('Blob Created') const newBlobSha = blobResponse.data.sha; // Create a new tree with the updated blob const treeResponse = await axios.post( @@ -121,6 +122,7 @@ async function commitChanges(filePath, file) { } ); + console.log('Tree Created') const newTreeSha = treeResponse.data.sha; // Create a new commit @@ -139,6 +141,7 @@ async function commitChanges(filePath, file) { } ); + console.log('Commit Created') const newCommitSha = commitResponse.data.sha; // Update the branch reference @@ -154,6 +157,7 @@ async function commitChanges(filePath, file) { }, } ); + console.log('Branch Updated') } catch (error) { core.setFailed(error); From 495b12533831430a2a9a612fa8902c2f2bc6e77c Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Tue, 19 Sep 2023 11:26:38 +0300 Subject: [PATCH 70/87] Add logs Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index 0a7e3de..92f6533 100644 --- a/index.js +++ b/index.js @@ -99,6 +99,7 @@ async function commitChanges(filePath, file) { ); console.log('Blob Created') + console.log('File path: ', filePath) const newBlobSha = blobResponse.data.sha; // Create a new tree with the updated blob const treeResponse = await axios.post( From 2303020aadd63f642cd4af7dfba897d4a09f273d Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Tue, 19 Sep 2023 11:30:24 +0300 Subject: [PATCH 71/87] Update filePath functionality Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 92f6533..6c713ec 100644 --- a/index.js +++ b/index.js @@ -49,8 +49,8 @@ async function run() { console.log(`Old version: ${version}. New version: ${newVersion}`) // fs.writeFileSync(file, JSON.stringify(file, null, 2)); - - await commitChanges(core.getInput('filePath'), file); + const filePathRelatedToRoot = getProjectInfoFilePath(filePathInput, true); + await commitChanges(file, filePathRelatedToRoot); const payload = JSON.stringify(github.context.payload, undefined, 2) @@ -62,7 +62,7 @@ async function run() { // Region functions -async function commitChanges(filePath, file) { +async function commitChanges(file, filePath) { const commitMessage = 'Commit message here'; const newContent = file; const githubToken = core.getInput('githubToken'); @@ -165,16 +165,16 @@ async function commitChanges(filePath, file) { } } -function getProjectInfoFilePath(filePath) { +function getProjectInfoFilePath(filePath, relativeToRoot = false) { if (filePath == null || filePath == undefined || filePath == '') { // List files inside the root directory of the repository const files = fs.readdirSync(process.cwd()); // Return the first file that matches .csproj or package.json const projectInfoFile = files.find(file => file.match(/\.csproj|package\.json/)); - return `${process.cwd()}/${projectInfoFile}`; + return relativeToRoot ? projectInfoFile : `${process.cwd()}/${projectInfoFile}`; } else - return `${process.cwd()}/${filePath}`; + return relativeToRoot ? filePath : `${process.cwd()}/${filePath}`; } function getProjectVersion(filePath) { const projectInfoFile = require(filePath); From 450787df5a7729119ace8c7db86b548cb87a2cc6 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 19 Sep 2023 08:30:44 +0000 Subject: [PATCH 72/87] Commit message here --- package.json | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/package.json b/package.json index 05f823b..53539b5 100644 --- a/package.json +++ b/package.json @@ -1,22 +1 @@ -{ - "name": "docker-container-action", - "version": "1.0.0", - "description": "This action prints \"Hello World\" or \"Hello\" + the name of a person to greet to the log.", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "keywords": [], - "author": "", - "license": "ISC", - "dependencies": { - "@actions/core": "^1.10.0", - "@actions/github": "^5.1.1", - "@actions/io": "^1.1.3", - "axios": "^1.5.0", - "xml2js": "^0.6.2" - }, - "devDependencies": { - "@types/node": "^20.6.2" - } -} +{"name":"docker-container-action","version":"1.1.0","description":"This action prints \"Hello World\" or \"Hello\" + the name of a person to greet to the log.","main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"keywords":[],"author":"","license":"ISC","dependencies":{"@actions/core":"^1.10.0","@actions/github":"^5.1.1","@actions/io":"^1.1.3","axios":"^1.5.0","xml2js":"^0.6.2"},"devDependencies":{"@types/node":"^20.6.2"}} \ No newline at end of file From 5727bbc02c0875b7f67650e2e6c560e9890804e5 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Tue, 19 Sep 2023 11:31:45 +0300 Subject: [PATCH 73/87] Don't stringify contnet Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 6c713ec..001024c 100644 --- a/index.js +++ b/index.js @@ -87,7 +87,7 @@ async function commitChanges(file, filePath) { const blobResponse = await axios.post( `https://api.github.com/repos/${owner}/${repo}/git/blobs`, { - content: JSON.stringify(newContent), + content: newContent, encoding: 'utf-8', }, { From 44b17fe49def7a3f7a4f882d81a01993dbbf285f Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Tue, 19 Sep 2023 11:32:03 +0300 Subject: [PATCH 74/87] Revert "Commit message here" This reverts commit 450787df5a7729119ace8c7db86b548cb87a2cc6. --- package.json | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 53539b5..05f823b 100644 --- a/package.json +++ b/package.json @@ -1 +1,22 @@ -{"name":"docker-container-action","version":"1.1.0","description":"This action prints \"Hello World\" or \"Hello\" + the name of a person to greet to the log.","main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"keywords":[],"author":"","license":"ISC","dependencies":{"@actions/core":"^1.10.0","@actions/github":"^5.1.1","@actions/io":"^1.1.3","axios":"^1.5.0","xml2js":"^0.6.2"},"devDependencies":{"@types/node":"^20.6.2"}} \ No newline at end of file +{ + "name": "docker-container-action", + "version": "1.0.0", + "description": "This action prints \"Hello World\" or \"Hello\" + the name of a person to greet to the log.", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "@actions/core": "^1.10.0", + "@actions/github": "^5.1.1", + "@actions/io": "^1.1.3", + "axios": "^1.5.0", + "xml2js": "^0.6.2" + }, + "devDependencies": { + "@types/node": "^20.6.2" + } +} From b1a3b9a9fb8bb44167a8c327601ddf77a167d9e2 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Tue, 19 Sep 2023 11:34:13 +0300 Subject: [PATCH 75/87] Revert "Don't stringify contnet" This reverts commit 5727bbc02c0875b7f67650e2e6c560e9890804e5. --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 001024c..6c713ec 100644 --- a/index.js +++ b/index.js @@ -87,7 +87,7 @@ async function commitChanges(file, filePath) { const blobResponse = await axios.post( `https://api.github.com/repos/${owner}/${repo}/git/blobs`, { - content: newContent, + content: JSON.stringify(newContent), encoding: 'utf-8', }, { From fca117f7ea1ba3147021e47d200f1944740b5cc5 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Tue, 19 Sep 2023 11:34:51 +0300 Subject: [PATCH 76/87] Indet `newContent` Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 6c713ec..1a3e425 100644 --- a/index.js +++ b/index.js @@ -87,7 +87,7 @@ async function commitChanges(file, filePath) { const blobResponse = await axios.post( `https://api.github.com/repos/${owner}/${repo}/git/blobs`, { - content: JSON.stringify(newContent), + content: JSON.stringify(newContent, null, 2), encoding: 'utf-8', }, { From dda4f75bd7e2790c718354ca23fcd05520a50510 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 19 Sep 2023 08:35:16 +0000 Subject: [PATCH 77/87] Commit message here --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 05f823b..cfb716f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "docker-container-action", - "version": "1.0.0", + "version": "1.1.0", "description": "This action prints \"Hello World\" or \"Hello\" + the name of a person to greet to the log.", "main": "index.js", "scripts": { @@ -19,4 +19,4 @@ "devDependencies": { "@types/node": "^20.6.2" } -} +} \ No newline at end of file From 15ea112f839a6ae6a989bb449a1370bd272d2783 Mon Sep 17 00:00:00 2001 From: Shakar <5h4k4r.b4kr@gmail.com> Date: Tue, 19 Sep 2023 12:44:16 +0300 Subject: [PATCH 78/87] add new line at the end of the file Signed-off-by: Shakar <5h4k4r.b4kr@gmail.com> --- index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/index.js b/index.js index 1a3e425..f2195bc 100644 --- a/index.js +++ b/index.js @@ -48,11 +48,10 @@ async function run() { console.log(`Old version: ${version}. New version: ${newVersion}`) - // fs.writeFileSync(file, JSON.stringify(file, null, 2)); const filePathRelatedToRoot = getProjectInfoFilePath(filePathInput, true); await commitChanges(file, filePathRelatedToRoot); - const payload = JSON.stringify(github.context.payload, undefined, 2) + const payload = JSON.stringify(github.context.payload + '\n', undefined, 2) // console.log(`The event payload: ${payload}`); } catch (error) { From 90e6ae5406f89d9ac6129f79ca4523e88c2fe43a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 19 Sep 2023 09:44:41 +0000 Subject: [PATCH 79/87] Commit message here --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cfb716f..eb08b35 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "docker-container-action", - "version": "1.1.0", + "version": "1.2.0", "description": "This action prints \"Hello World\" or \"Hello\" + the name of a person to greet to the log.", "main": "index.js", "scripts": { From e4da18c1049bea3de527486c83fbcb56f260d266 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 19 Sep 2023 10:52:05 +0000 Subject: [PATCH 80/87] Commit message here --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index eb08b35..6eddd49 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "docker-container-action", - "version": "1.2.0", + "version": "1.3.0", "description": "This action prints \"Hello World\" or \"Hello\" + the name of a person to greet to the log.", "main": "index.js", "scripts": { From 2102f1bfa872e1a4bd7fd115f88fbe5417ab082b Mon Sep 17 00:00:00 2001 From: Shakar Bakr <5h4k4r.b4kr@gmail.com> Date: Tue, 19 Sep 2023 13:52:54 +0300 Subject: [PATCH 81/87] Code cleanpu Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com> --- index.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/index.js b/index.js index f2195bc..240d75e 100644 --- a/index.js +++ b/index.js @@ -51,8 +51,6 @@ async function run() { const filePathRelatedToRoot = getProjectInfoFilePath(filePathInput, true); await commitChanges(file, filePathRelatedToRoot); - const payload = JSON.stringify(github.context.payload + '\n', undefined, 2) - // console.log(`The event payload: ${payload}`); } catch (error) { core.setFailed(error.message); From 3829330c4e567c230893b687a1361fa5010b421e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 19 Sep 2023 10:53:17 +0000 Subject: [PATCH 82/87] Commit message here --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6eddd49..3755c25 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "docker-container-action", - "version": "1.3.0", + "version": "1.4.0", "description": "This action prints \"Hello World\" or \"Hello\" + the name of a person to greet to the log.", "main": "index.js", "scripts": { From 0b2fb2a01e33ddc098e8e21e5314d00c11ad3486 Mon Sep 17 00:00:00 2001 From: Shakar Bakr <5h4k4r.b4kr@gmail.com> Date: Tue, 19 Sep 2023 13:56:59 +0300 Subject: [PATCH 83/87] Append newline to the end of the file Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com> --- index.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 240d75e..a6b62cb 100644 --- a/index.js +++ b/index.js @@ -61,9 +61,12 @@ async function run() { // Region functions async function commitChanges(file, filePath) { const commitMessage = 'Commit message here'; - const newContent = file; - const githubToken = core.getInput('githubToken'); + let newContent = JSON.stringify(newContent, null, 2); + // Append a newline character to the end of the new content + newContent += '\n'; + + const githubToken = core.getInput('githubToken'); // Get the repository owner and name const repoFullName = process.env.GITHUB_REPOSITORY; @@ -84,7 +87,7 @@ async function commitChanges(file, filePath) { const blobResponse = await axios.post( `https://api.github.com/repos/${owner}/${repo}/git/blobs`, { - content: JSON.stringify(newContent, null, 2), + content: newContent, encoding: 'utf-8', }, { From 6759debe95070bc4ff6bffadc931253384013472 Mon Sep 17 00:00:00 2001 From: Shakar Bakr <5h4k4r.b4kr@gmail.com> Date: Tue, 19 Sep 2023 13:57:41 +0300 Subject: [PATCH 84/87] Fix error Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com> --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index a6b62cb..61cbbbd 100644 --- a/index.js +++ b/index.js @@ -62,7 +62,7 @@ async function run() { async function commitChanges(file, filePath) { const commitMessage = 'Commit message here'; - let newContent = JSON.stringify(newContent, null, 2); + let newContent = JSON.stringify(file, null, 2); // Append a newline character to the end of the new content newContent += '\n'; From e2d2c7209599a72b16ad775ded58b5db2b3a9091 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 19 Sep 2023 10:58:13 +0000 Subject: [PATCH 85/87] Commit message here --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 3755c25..abe91ee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "docker-container-action", - "version": "1.4.0", + "version": "1.5.0", "description": "This action prints \"Hello World\" or \"Hello\" + the name of a person to greet to the log.", "main": "index.js", "scripts": { @@ -19,4 +19,4 @@ "devDependencies": { "@types/node": "^20.6.2" } -} \ No newline at end of file +} From f6001456e8f8b18bc021e29119cc595fa8d9a7af Mon Sep 17 00:00:00 2001 From: Shakar Bakr <5h4k4r.b4kr@gmail.com> Date: Tue, 19 Sep 2023 13:59:05 +0300 Subject: [PATCH 86/87] Code format Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com> --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 61cbbbd..637155f 100644 --- a/index.js +++ b/index.js @@ -26,18 +26,18 @@ async function run() { const versionParts = version.split('.'); // 1.2.3 => [1, 2, 3] if (labelInput === 'major') { + versionParts[0] = parseInt(versionParts[0]) + 1; versionParts[1] = 0; versionParts[2] = 0; - } - else if (labelInput == 'minor') { + } else if (labelInput == 'minor') { + versionParts[1] = parseInt(versionParts[1]) + 1; versionParts[2] = 0; } else if (labelInput == 'patch') - // increment the patch version versionParts[2] = parseInt(versionParts[2]) + 1; From 46340bef18f2009859775bef73b4ebd310967d31 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 19 Sep 2023 13:37:33 +0000 Subject: [PATCH 87/87] Commit message here --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index abe91ee..e12b423 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "docker-container-action", - "version": "1.5.0", + "version": "1.6.0", "description": "This action prints \"Hello World\" or \"Hello\" + the name of a person to greet to the log.", "main": "index.js", "scripts": {