Skip to content

Upstream js

Upstream js #786

Workflow file for this run

name: Upstream js
on:
schedule:
- cron: '0 */3 * * *' # “At minute 0 past every 3rd hour.”
workflow_dispatch:
inputs:
tag_version:
description: image tag
type: choice
required: true
options:
- alpha
- latest
default: alpha
jobs:
upstream:
runs-on: ubuntu-latest
outputs:
hasAtLeastOneNewVersion: ${{ steps.fetchLatestPkg.outputs.hasAtLeastOneNewVersion }}
hasNewVersionAvailableJS: ${{ steps.fetchLatestPkg.outputs.hasVersionNewJS }}
latestVersionAvailableJS: ${{ steps.fetchLatestPkg.outputs.latestVersionJS }}
hasAtLeastOneNewVersionWithoutPR: ${{ steps.checkPrAlreadyExist.outputs.hasAtLeastOneNewVersionWithoutPR }}
steps:
- id: checkoutRepo
name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 1
- id: fetchLatestPkg
name: Fetch the latest package version
uses: actions/github-script@v6
env:
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});
console.log('hasVersionNewJS', hasVersionNewJS)
console.log('latestVersionJS', latestVersionJS)
if (hasVersionNewJS === 'true' ) {
core.setOutput('hasAtLeastOneNewVersion', 'true');
core.setOutput('hasVersionNewJS', 'true');
core.setOutput('latestVersionJS', latestVersionJS);
} else {
core.setOutput('hasAtLeastOneNewVersion', 'false');
console.log('No new version available, skipping upstream!')
}
- name: Check value after
run: |
echo "The value hasAtLeastOneNewVersion is: ${{ steps.fetchLatestPkg.outputs.hasAtLeastOneNewVersion }}"
echo "The value hasVersionNewJS is: ${{ steps.fetchLatestPkg.outputs.hasVersionNewJS }}"
echo "The value latestVersionJS is: ${{ steps.fetchLatestPkg.outputs.latestVersionJS }}"
- id: checkPrAlreadyExist
name: Check PR with latest already exist
if: ${{ steps.fetchLatestPkg.outputs.hasAtLeastOneNewVersion == 'true' }}
uses: actions/github-script@v6
env:
HAS_NEW_JS_VERSION: ${{ steps.fetchLatestPkg.outputs.hasVersionNewJS }}
LATEST_JS_VERSION: ${{ steps.fetchLatestPkg.outputs.latestVersionJS }}
with:
github-token: ${{ secrets.BOT_GITHUB_TOKEN }}
script: |
const hasVersionNewJS = process.env.HAS_NEW_JS_VERSION;
const latestVersionJS = process.env.LATEST_JS_VERSION;
const checkPRAlreadyExist = require('./scripts/github/update/check-pr-already-exist.js');
let isPRWithLatestJSAlreadyAvailable = false;
if (hasVersionNewJS === 'true') {
isPRWithLatestJSAlreadyAvailable = await checkPRAlreadyExist({github, context, version: latestVersionJS});
console.log('isPRWithLatestJSAlreadyAvailable', isPRWithLatestJSAlreadyAvailable);
}
if (isPRWithLatestJSAlreadyAvailable) {
console.log('Warning: Upstream PR already exist, stop the migration execution!');
core.setOutput('hasAtLeastOneNewVersionWithoutPR', 'false');
} else {
core.setOutput('hasAtLeastOneNewVersionWithoutPR', 'true');
}
migrate:
if: ${{ needs.upstream.outputs.hasAtLeastOneNewVersionWithoutPR == 'true' }}
runs-on: ubuntu-latest
needs: upstream
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
token: ${{ secrets.BOT_GITHUB_TOKEN }}
fetch-depth: 1
- name: setup NPM
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache-dependency-path: package-lock.json
- name: "General :: dbpci-install"
run: |
npm ci --ignore-scripts
- name: Migration
shell: bash
env:
IS_JS_AFFECTED: ${{ needs.upstream.outputs.hasNewVersionAvailableJS }}
PACKAGE_VERSION_JS: ${{ needs.upstream.outputs.latestVersionAvailableJS }}
BRANCH_TO_CREATE: "upstream-dependencies"
run: |
migrateDependenciesJS() {
echo "Update JS dependencies to: ${PACKAGE_VERSION_JS}"
echo "Calling migration JS"
npx nx migrate @alfresco/js-api@${PACKAGE_VERSION_JS}
echo "Migration JS done"
}
migrateLibDependenciesJS() {
eval projects=( "cli"
"core"
"content-services"
"process-services"
"process-services-cloud"
"insights"
"testing"
"extensions" )
projectslength=${#projects[@]}
for (( i=0; i<${projectslength}; i++ ));
do
echo "Update JS dependencies in adf-${projects[$i]} to: ${PACKAGE_VERSION_JS}"
DESTDIR="lib/${projects[$i]}"
sed -i "${sedi[@]}" "s/\"@alfresco\/js-api\": \".*\"/\"@alfresco\/js-api\": \">=${PACKAGE_VERSION_JS}\"/g" ${DESTDIR}/package.json
done
}
regeneratePackageLock() {
echo "Regenerate lock"
npm i --package-lock-only
echo "Package-lock done."
}
if git checkout ${BRANCH_TO_CREATE} 2>/dev/null ; then
git reset --hard origin/develop
echo "Reset branch"
fi
if [[ "$IS_JS_AFFECTED" == "true" ]]; then
migrateDependenciesJS
migrateLibDependenciesJS
fi
regeneratePackageLock
- name: Commit Code
if: ${{ needs.upstream.outputs.hasAtLeastOneNewVersion == 'true' }}
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "[ci:force][auto-commit] Update dependencies JS:${{ needs.upstream.outputs.latestVersionAvailableJS }}"
branch: upstream-dependencies
push_options: '--force'
create_branch: true
- name: Create a Pull request
uses: actions/github-script@v6
env:
PACKAGE_VERSION_JS: ${{ needs.upstream.outputs.latestVersionAvailableJS }}
with:
github-token: ${{ secrets.BOT_GITHUB_TOKEN }}
script: |
const { PACKAGE_VERSION_JS } = process.env
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 < 1) {
const payloadPullRequest = {
owner: context.repo.owner,
repo: context.repo.repo,
title: `GH Auto: Upstream dependencies JS-API:${PACKAGE_VERSION_JS}`,
head: `${context.repo.owner}:${BRANCH_TO_CREATE}`,
base: 'develop',
body: `Automatic PR`
};
console.log('Payload: ',payloadPullRequest);
const { data: pr } = await github.rest.pulls.create(payloadPullRequest);
return pr.number;
} else {
const upstreamPrOpen = prs[0];
// override the title to contains the latest js dep number
const payloadUpdatePullRequest = {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: upstreamPrOpen.number,
title: `GH Auto: Upstream dependencies JS-API:${PACKAGE_VERSION_JS}`,
};
await github.rest.pulls.update(payloadUpdatePullRequest);
return upstreamPrOpen.number;
}
console.log(`Trigger a dispatch event for the monorepo`);