-
Notifications
You must be signed in to change notification settings - Fork 289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set stable tag workflow #3079
Set stable tag workflow #3079
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# | ||
# This workflow scans a dedicated list of adapters (hardcode at setStableTag.js) and ensures that the release number listed | ||
# at sources-dist-stable.json and the release tagged as 'stable' at npm are identical. If a difference is detected, the dist-tag | ||
# at npmjs is changed to meet the contents of sources-dist-stable.json. | ||
# | ||
# This workflow is triggered by any push and additionally runs once a day | ||
# | ||
|
||
name: Set stable tag | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
push: | ||
branches: [ "master" ] | ||
|
||
schedule: | ||
# * is a special character in YAML, so you have to quote this string | ||
# every day at 1:00:00 | ||
- cron: '0 1 * * *' | ||
|
||
jobs: | ||
set-stable-tag: | ||
name: set stable tag | ||
if: | | ||
github.repository == 'ioBroker/ioBroker.repositories' | ||
|
||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 18 | ||
- run: npm i | ||
- run: npm run setStableTag | ||
env: | ||
OWN_GITHUB_TOKEN: ${{ secrets.OWN_GITHUB_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
'use strict'; | ||
//const fs = require('fs'); | ||
const execSync = require('child_process').execSync; | ||
|
||
const { | ||
// addComment, | ||
// addLabel, | ||
// getGithub, | ||
getUrl, | ||
// getAllComments, | ||
// deleteComment | ||
} = require('./common'); | ||
|
||
const STABLE_JSON = 'sources-dist-stable.json'; | ||
const ADAPTER_LIST = [ | ||
'admin', | ||
'discovery', | ||
'js-controller', | ||
'backitup' | ||
]; | ||
|
||
async function getStableRepo() { | ||
return await getUrl('http://repo.iobroker.live/sources-dist.json'); | ||
} | ||
|
||
async function getNpmMeta( pAdapter ) { | ||
return await getUrl(`https://registry.npmjs.org/iobroker.${pAdapter}`); | ||
}; | ||
|
||
async function getNpmDisttags(pAdapter) { | ||
const npmMeta = await getNpmMeta( pAdapter ); | ||
return npmMeta['dist-tags']; | ||
}; | ||
|
||
function getPullRequestNumber() { | ||
if (process.env.GITHUB_REF && process.env.GITHUB_REF.match(/refs\/pull\/\d+\/merge/)) { | ||
const result = /refs\/pull\/(\d+)\/merge/g.exec(process.env.GITHUB_REF); | ||
if (!result) { | ||
console.log ('GITHUB_REF not found or not parseable.'); | ||
return null; | ||
} | ||
return result[1]; | ||
} else if (process.env.GITHUB_EVENT_PATH) { | ||
const event = JSON.parse(fs.readFileSync(process.env.GITHUB_EVENT_PATH, 'utf8')); | ||
return event.pull_request ? event.pull_request.number : (event.issue ? event.issue.number : ''); | ||
} else { | ||
console.log ('GITHUB_REF and process.env.GITHUB_EVENT_PATH are not set!'); | ||
return null; | ||
} | ||
} | ||
|
||
async function doIt() { | ||
|
||
const prID = getPullRequestNumber(); | ||
console.log(`Process PR ${prID}`); | ||
|
||
if (prID) { | ||
const files = await getGithub(`https://api.github.com/repos/ioBroker/ioBroker.repositories/pulls/${prID}/files`); | ||
console.log('Files changed:'); | ||
files.forEach( f=>{console.log(` ${f}`)}); | ||
const isStable = files.includes(`${STABLE_JSON}`) | ||
if (!isStable) | ||
{ | ||
return 'No changes to stable repository detected'; | ||
} | ||
} else { | ||
console.log(`scanning ${STABLE_JSON} ...`); | ||
} | ||
|
||
const stable=await getStableRepo(); | ||
for (const adapter in stable) { | ||
if (ADAPTER_LIST.includes( adapter )) { | ||
console.log (`\nchecking ${adapter} ...`); | ||
|
||
const npmTags=await getNpmDisttags(adapter); | ||
const repoRelease = stable[adapter].version; | ||
const npmRelease = npmTags.stable; | ||
//console.log( `repo: ${repoRelease} - npm: ${npmRelease}`); | ||
if (repoRelease === npmRelease) { | ||
console.log (`${adapter} ${repoRelease} correctly tagged as stable`) | ||
Check notice Code scanning / CodeQL Semicolon insertion Note
Avoid automated semicolon insertion (91% of all statements in
the enclosing function Error loading related location Loading |
||
} else { | ||
console.log (`${adapter} ${repoRelease} need to be tagged as stable`); | ||
console.log( `executing npm --//registry.npmjs.org/:_authToken=*** dist-tag add iobroker.${adapter}@${repoRelease} stable`); | ||
const cmd = `npm --//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN} dist-tag add iobroker.${adapter}@${repoRelease} stable`; | ||
try { | ||
const result=execSync( cmd, { encoding: 'utf-8' }); | ||
Check failure Code scanning / CodeQL Uncontrolled command line Critical
This command line depends on a
user-provided value Error loading related location Loading Check warning Code scanning / CodeQL Indirect uncontrolled command line Medium
This command depends on an unsanitized
environment variable Error loading related location Loading |
||
console.log(result); | ||
} catch (_e) { | ||
// console.log (JSON.stringify(e)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
return 'done'; | ||
} | ||
|
||
// activate for debugging purposes | ||
//process.env.GITHUB_REF = 'refs/pull/2298/merge'; | ||
//process.env.OWN_GITHUB_TOKEN = 'add-token-here'; | ||
//process.env.GITHUB_EVENT_PATH = __dirname + '/../event.json'; | ||
|
||
console.log(`process.env.GITHUB_REF = ${process.env.GITHUB_REF}`); | ||
console.log(`process.env.GITHUB_EVENT_PATH = ${process.env.GITHUB_EVENT_PATH}`); | ||
console.log(`process.env.OWN_GITHUB_TOKEN = ${(process.env.OWN_GITHUB_TOKEN || '').length}`); | ||
console.log(`process.env.NPM_TOKEN = ${(process.env.NPM_TOKEN || '').length}`); | ||
|
||
doIt() | ||
.then(result => console.log(result)) | ||
.catch(e => console.error(e)); |
Check notice
Code scanning / CodeQL
Semicolon insertion Note