From 0489992921a08b210d002a0f53e2727f94cabe2e Mon Sep 17 00:00:00 2001 From: Maurizio Vitale Date: Mon, 17 Apr 2023 16:22:41 +0100 Subject: [PATCH] [AAE-13775] Upstream js - fix issue (#8484) * fix issue * fix issue * put back \' * fix reg for release * add missing script * remove logs --- .github/workflows/upstream-js.yml | 5 +++-- .../github/update/check-pr-already-exist.js | 21 +++++++++++++++++++ scripts/github/update/latest-version-of.js | 11 +++++----- 3 files changed, 30 insertions(+), 7 deletions(-) create mode 100755 scripts/github/update/check-pr-already-exist.js diff --git a/.github/workflows/upstream-js.yml b/.github/workflows/upstream-js.yml index 343d4b1ae4..82ec7a1737 100644 --- a/.github/workflows/upstream-js.yml +++ b/.github/workflows/upstream-js.yml @@ -31,11 +31,12 @@ jobs: name: Fetch the latest package version uses: actions/github-script@v6 env: - TAG_VERSION: ${{ inputs.repo_to_update }} + TAG_VERSION: ${{ inputs.tag_version }} with: github-token: ${{ secrets.PAT_WRITE_PKG }} script: | const tagVersion = process.env.TAG_VERSION; + console.log('tagVersion:',tagVersion); const getLatestVersionOf = require('./scripts/github/update/latest-version-of.js'); const { hasVersionNew: hasVersionNewJS, latestVersion: latestVersionJS } = await getLatestVersionOf({github, context, dependencyName: 'js-api', tagVersion}); @@ -70,7 +71,7 @@ jobs: const hasVersionNewJS = process.env.HAS_NEW_JS_VERSION; const latestVersionJS = process.env.LATEST_JS_VERSION; - const checkPRAlreadyExist = require('./scripts/ci/jobs/check-pr-already-exist.js'); + const checkPRAlreadyExist = require('./scripts/github/update/check-pr-already-exist.js'); let isPRWithLatestJSAlreadyAvailable = false; if (hasVersionNewJS === 'true') { diff --git a/scripts/github/update/check-pr-already-exist.js b/scripts/github/update/check-pr-already-exist.js new file mode 100755 index 0000000000..771fac1bde --- /dev/null +++ b/scripts/github/update/check-pr-already-exist.js @@ -0,0 +1,21 @@ +module.exports = async ({github, context, version}) => { + + const BRANCH_TO_CREATE = 'upstream-dependencies'; + + const { data: prs } = await github.rest.pulls.list({ + owner: context.repo.owner, + repo: context.repo.repo, + state: 'open', + head: `${context.repo.owner}:${BRANCH_TO_CREATE}`, + base: 'develop' + }); + + if (prs?.length > 0) { + const title = prs[0].title; + const result = title.match(version); + return result?.length > 0 ? true : false; + } + return false; + +} + \ No newline at end of file diff --git a/scripts/github/update/latest-version-of.js b/scripts/github/update/latest-version-of.js index a839fa9755..76181a5963 100755 --- a/scripts/github/update/latest-version-of.js +++ b/scripts/github/update/latest-version-of.js @@ -16,18 +16,19 @@ module.exports = async ({github, context, dependencyName, tagVersion = 'alpha' } org: organization }); - let latestPkgToUpdate = null; - if (tagVersion === 'alpha') { + let latestPkgToUpdate = undefined; + if (tagVersion !== 'release') { console.log('alpha: taking most recent') - const filteredAlphaPkgs = availablePakages.filter( (item) => item.name.match('^[0-9]*.[0-9]*.[0-9]*.A.[0-9].[0-9]*$') ) + + const filteredAlphaPkgs = availablePakages.filter( (item) => item.name.match('^[0-9]*.[0-9]*.[0-9]*.-[0-9]*$')); latestPkgToUpdate = filteredAlphaPkgs[0]; } else { console.log('release: taking most recent') - const filteredReleasePkgs = availablePakages.filter( (item) => item.name.match('^[0-9]*.[0-9]*.[0-9]*.A.[0-9]*$') || item.name.match('^[0-9]*.[0-9]*.[0-9]*$') ) + const filteredReleasePkgs = availablePakages.filter( (item) => item.name.match('^[0-9]*.[0-9]*.[0-9]*$')); latestPkgToUpdate = filteredReleasePkgs[0]; } - if (latestPkgToUpdate === null) { + if (latestPkgToUpdate === undefined) { console.log(`Something went wrong. Not able to find any version.`); return { hasVersionNew: 'false' }; } else {