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)