diff --git a/.github/actions/update-app-version/action.yaml b/.github/actions/sync-app-version/action.yaml similarity index 64% rename from .github/actions/update-app-version/action.yaml rename to .github/actions/sync-app-version/action.yaml index 5060b3c..b676714 100644 --- a/.github/actions/update-app-version/action.yaml +++ b/.github/actions/sync-app-version/action.yaml @@ -1,4 +1,4 @@ -name: Update appVersion +name: Sync appVersion description: |- This action update appVersion in all charts. It gets the appVersion from the input and sets it in each Chart.yaml and changes the version of Chart.yaml itself. Charts @@ -6,15 +6,11 @@ description: |- inputs: app_version: - description: The new appVersion value + description: appVersion value + required: true + upstream: + description: Upsteam ID required: true - -outputs: - app_version: - description: The update appVersion value - - chart_version: - description: The updated Chart.yaml version value runs: using: node16 diff --git a/.github/actions/update-app-version/index.dist.js b/.github/actions/sync-app-version/index.dist.js similarity index 99% rename from .github/actions/update-app-version/index.dist.js rename to .github/actions/sync-app-version/index.dist.js index 162c253..4b46f73 100644 --- a/.github/actions/update-app-version/index.dist.js +++ b/.github/actions/sync-app-version/index.dist.js @@ -10232,6 +10232,8 @@ const fs = __nccwpck_require__(7147); const path = __nccwpck_require__(1017); const chartsDir = path.join(process.env.GITHUB_WORKSPACE, 'charts'); +const appVersion = core.getInput('app_version', { required: true }); +const upstream = core.getInput('upstream', { required: true }); function getCharts() { const files = fs.readdirSync(chartsDir); @@ -10243,21 +10245,35 @@ function getCharts() { return directories; } +function update_charts() { + const charts = getCharts() + core.info(`The appVersion ${appVersion}`); + charts.forEach(function (chart) { + chartPath = path.join(chartsDir, chart, "Chart.yaml") + const chartData = yaml.load(fs.readFileSync(chartPath, 'utf8')) + + chartData.appVersion = appVersion; + chartData.version = semver.inc(chartData.version, 'patch'); + const updatedYaml = yaml.dump(chartData); + fs.writeFileSync(chartPath, updatedYaml, 'utf8'); + core.info(`The new version of ${chart} is ${chartData.version}`); + }); + +} +async function push_changes() { + await exec.exec('git config user.name "github-actions[bot]"'); + await exec.exec('git config user.email "github-actions[bot]@users.noreply.github.com"'); + await exec.exec(`git checkout -b ${process.env.PR_BRANCH}`); + await exec.exec('git add charts'); + await exec.exec(`git commit -m "Sync appVersion: ${appVersion}. Triggered by ${upstream}"`); + await exec.exec(`git push origin ${process.env.PR_BRANCH} --force`); +} + async function run() { try { - const charts = getCharts() - const appVersion = core.getInput('app_version', { required: true }); - core.info(`The appVersion ${appVersion}`); - charts.forEach(function (chart) { - chartPath = path.join(chartsDir, chart, "Chart.yaml") - const chartData = yaml.load(fs.readFileSync(chartPath, 'utf8')) - - chartData.appVersion = appVersion; - chartData.version = semver.inc(chartData.version, 'patch'); - const updatedYaml = yaml.dump(chartData); - fs.writeFileSync(chartPath, updatedYaml, 'utf8'); - core.info(`The new version of ${chart} is ${chartData.version}`); - }); + update_charts() + push_changes() + // draft_pr() } catch (err) { return core.setFailed(`Error: ${err}`) } diff --git a/.github/actions/sync-app-version/index.js b/.github/actions/sync-app-version/index.js new file mode 100644 index 0000000..c9fa43f --- /dev/null +++ b/.github/actions/sync-app-version/index.js @@ -0,0 +1,56 @@ +const yaml = require('js-yaml'); +const core = require('@actions/core'); +const semver = require('semver'); +const fs = require('fs'); +const path = require('path'); + +const chartsDir = path.join(process.env.GITHUB_WORKSPACE, 'charts'); +const appVersion = core.getInput('app_version', { required: true }); +const upstream = core.getInput('upstream', { required: true }); + +function getCharts() { + const files = fs.readdirSync(chartsDir); + const directories = files.filter((file) => { + const filePath = path.join(chartsDir, file); + return fs.statSync(filePath).isDirectory(); + }); + core.debug(`Charts: ${directories}`); + return directories; +} + +function update_charts() { + const charts = getCharts() + core.info(`The appVersion ${appVersion}`); + charts.forEach(function (chart) { + chartPath = path.join(chartsDir, chart, "Chart.yaml") + const chartData = yaml.load(fs.readFileSync(chartPath, 'utf8')) + + chartData.appVersion = appVersion; + chartData.version = semver.inc(chartData.version, 'patch'); + const updatedYaml = yaml.dump(chartData); + fs.writeFileSync(chartPath, updatedYaml, 'utf8'); + core.info(`The new version of ${chart} is ${chartData.version}`); + }); + +} +async function push_changes() { + await exec.exec('git config user.name "github-actions[bot]"'); + await exec.exec('git config user.email "github-actions[bot]@users.noreply.github.com"'); + await exec.exec(`git checkout -b ${process.env.PR_BRANCH}`); + await exec.exec('git add charts'); + await exec.exec(`git commit -m "Sync appVersion: ${appVersion}. Triggered by ${upstream}"`); + await exec.exec(`git push origin ${process.env.PR_BRANCH} --force`); +} + +async function run() { + try { + update_charts() + push_changes() + // draft_pr() + } catch (err) { + return core.setFailed(`Error: ${err}`) + } + +} + +run(); diff --git a/.github/actions/update-app-version/package-lock.json b/.github/actions/sync-app-version/package-lock.json similarity index 100% rename from .github/actions/update-app-version/package-lock.json rename to .github/actions/sync-app-version/package-lock.json diff --git a/.github/actions/update-app-version/package.json b/.github/actions/sync-app-version/package.json similarity index 83% rename from .github/actions/update-app-version/package.json rename to .github/actions/sync-app-version/package.json index 40752a8..d533daa 100644 --- a/.github/actions/update-app-version/package.json +++ b/.github/actions/sync-app-version/package.json @@ -1,7 +1,7 @@ { - "name": "update-app-version-action", + "name": "sync-app-version-action", "version": "1.0.0", - "description": "Update appVersion and version in Chart.yaml", + "description": "Main action fro sync-app-version.yaml workflow", "main": "index.js", "scripts": { "lint": "eslint .", diff --git a/.github/actions/update-app-version/index.js b/.github/actions/update-app-version/index.js deleted file mode 100644 index 3f60d34..0000000 --- a/.github/actions/update-app-version/index.js +++ /dev/null @@ -1,40 +0,0 @@ -const yaml = require('js-yaml'); -const core = require('@actions/core'); -const semver = require('semver'); -const fs = require('fs'); -const path = require('path'); - -const chartsDir = path.join(process.env.GITHUB_WORKSPACE, 'charts'); - -function getCharts() { - const files = fs.readdirSync(chartsDir); - const directories = files.filter((file) => { - const filePath = path.join(chartsDir, file); - return fs.statSync(filePath).isDirectory(); - }); - core.debug(`Charts: ${directories}`); - return directories; -} - -async function run() { - try { - const charts = getCharts() - const appVersion = core.getInput('app_version', { required: true }); - core.info(`The appVersion ${appVersion}`); - charts.forEach(function (chart) { - chartPath = path.join(chartsDir, chart, "Chart.yaml") - const chartData = yaml.load(fs.readFileSync(chartPath, 'utf8')) - - chartData.appVersion = appVersion; - chartData.version = semver.inc(chartData.version, 'patch'); - const updatedYaml = yaml.dump(chartData); - fs.writeFileSync(chartPath, updatedYaml, 'utf8'); - core.info(`The new version of ${chart} is ${chartData.version}`); - }); - } catch (err) { - return core.setFailed(`Error: ${err}`) - } - -} - -run(); diff --git a/.github/workflows/sync-app-version.yaml b/.github/workflows/sync-app-version.yaml index d43bdc0..eae78d0 100644 --- a/.github/workflows/sync-app-version.yaml +++ b/.github/workflows/sync-app-version.yaml @@ -1,12 +1,23 @@ name: Sync appVersion +# TODO: add description of this action on: + push: + branches: + - SCALRCORE-27249 workflow_dispatch: inputs: app_version: description: Scalr Agent version in format x.y.z (without `agent/` prefix). required: true type: string + upstream: + description: | + This input is used to link the dispatch with the upstream. It will be + as prefix in PR name. + required: true + type: string + env: PR_BRANCH: 'actions/sync-app-version-${{ inputs.app_version }}' @@ -18,71 +29,73 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Update appVersion - id: update - uses: ./.github/actions/update-app-version - with: - # app_version: ${{inputs.app_version}} - app_version: "0.42.0" - - - name: Commit Changes + - name: printenv shell: bash - run: |- - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" + run: printenv + + - name: Main + uses: ./.github/actions/sync-app-version + with: + app_version: ${{inputs.app_version}} + upstream: ${{inputs.upstream}} - git checkout -b $PR_BRANCH + # - name: Commit Changes + # shell: bash + # run: |- + # git config user.name "github-actions[bot]" + # git config user.email "github-actions[bot]@users.noreply.github.com" - git status - git add . - git commit -m "Release: ${{steps.update.outputs.version}}" - git push origin $PR_BRANCH --force + # git checkout -b $PR_BRANCH + # git status + # git add . + # git commit -m "Release: ${{steps.update.outputs.version}}" + # git push origin $PR_BRANCH --force - - name: 'Create Pull Request' - uses: 'actions/github-script@v6' - with: - script: |- - const tag = "v" + process.env.NEW_VERSION; + # - name: 'Create Pull Request' + # uses: 'actions/github-script@v6' + # with: + # script: |- + # const tag = "v" + process.env.NEW_VERSION; - try { - const listResponse = await github.rest.pulls.list({ - owner: context.repo.owner, - repo: context.repo.repo, - state: "open", - head: context.repo.owner + ":" + process.env.PR_BRANCH, - base: process.env.GITHUB_REF_NAME, - }); + # try { + # const listResponse = await github.rest.pulls.list({ + # owner: context.repo.owner, + # repo: context.repo.repo, + # state: "open", + # head: context.repo.owner + ":" + process.env.PR_BRANCH, + # base: process.env.GITHUB_REF_NAME, + # }); - core.isDebug() && console.log(listResponse); + # core.isDebug() && console.log(listResponse); - if (!listResponse.data.length) { - const createResponse = await github.rest.pulls.create({ - owner: context.repo.owner, - repo: context.repo.repo, - title: "Release: " + tag, - body: process.env.RELEASE_NOTES, - head: process.env.PR_BRANCH, - base: process.env.GITHUB_REF_NAME, - }); + # if (!listResponse.data.length) { + # const createResponse = await github.rest.pulls.create({ + # owner: context.repo.owner, + # repo: context.repo.repo, + # title: "Release: " + tag, + # body: process.env.RELEASE_NOTES, + # head: process.env.PR_BRANCH, + # base: process.env.GITHUB_REF_NAME, + # }); - core.info( - `Created PR #${createResponse.data.number} at ${createResponse.data.html_url}` - ); - } else { - const updateResponse = await github.rest.pulls.update({ - owner: context.repo.owner, - repo: context.repo.repo, - pull_number: listResponse.data[0].number, - title: "Release: " + tag, - body: process.env.RELEASE_NOTES, - }); + # core.info( + # `Created PR #${createResponse.data.number} at ${createResponse.data.html_url}` + # ); + # } else { + # const updateResponse = await github.rest.pulls.update({ + # owner: context.repo.owner, + # repo: context.repo.repo, + # pull_number: listResponse.data[0].number, + # title: "Release: " + tag, + # body: process.env.RELEASE_NOTES, + # }); - core.info( - `Updated PR #${updateResponse.data.number} at ${updateResponse.data.html_url}` - ); - } - } catch (err) { - console.error(err); - core.setFailed(`Failed to create pull request: ${err}`); - } \ No newline at end of file + # core.info( + # `Updated PR #${updateResponse.data.number} at ${updateResponse.data.html_url}` + # ); + # } + # } catch (err) { + # console.error(err); + # core.setFailed(`Failed to create pull request: ${err}`); + # } \ No newline at end of file