mirror of
https://github.com/11notes/docker-bind.git
synced 2025-11-05 06:13:15 +00:00
[feature] new automated update
This commit is contained in:
109
.github/workflows/cron.update.yml
vendored
Normal file
109
.github/workflows/cron.update.yml
vendored
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
name: cron-update
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
schedule:
|
||||||
|
- cron: "0 5 * * *"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
cron-update:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: cron-update / get latest version
|
||||||
|
uses: actions/github-script@62c3794a3eb6788d9a2a72b219504732c0c9a298
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
(async()=>{
|
||||||
|
let found = false;
|
||||||
|
const res = await fetch('https://www.isc.org/download/');
|
||||||
|
if(res && res.status === 200){
|
||||||
|
const html = await res.text();
|
||||||
|
const trs = [...html.replace(/[\r\n]*/ig, '').matchAll(/<tr>(.*?)<\/tr>/ig)];
|
||||||
|
for(const tr of trs){
|
||||||
|
const tds = [...tr[0].matchAll(/<td[^>]*>(.*?)<\/td>/ig)];
|
||||||
|
if(Array.isArray(tds)){
|
||||||
|
for(const td of tds){
|
||||||
|
if(/This software is recommended for production use/i.test(td.input) && /Current Stable, ESV/i.test(td.input)){
|
||||||
|
core.exportVariable('LATEST_VERSION', td[1]);
|
||||||
|
core.info(`found bind version ${td[1]}`);
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!found){
|
||||||
|
core.setFailed('no version for Unifi could be found!');
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
- name: cron-update / compare latest with current version
|
||||||
|
uses: actions/github-script@62c3794a3eb6788d9a2a72b219504732c0c9a298
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
const { existsSync, readFileSync, writeFileSync } = require('node:fs');
|
||||||
|
const { resolve } = require('node:path');
|
||||||
|
const { inspect } = require('node:util');
|
||||||
|
const latest = "${{ env.LATEST_VERSION }}";
|
||||||
|
const repository = {dot:{}};
|
||||||
|
|
||||||
|
try{
|
||||||
|
const path = resolve('.json');
|
||||||
|
if(existsSync(path)){
|
||||||
|
try{
|
||||||
|
repository.dot = JSON.parse(readFileSync(path).toString());
|
||||||
|
}catch(e){
|
||||||
|
throw new Error('could not parse .json');
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
throw new Error('.json does not exist');
|
||||||
|
}
|
||||||
|
}catch(e){
|
||||||
|
core.setFailed(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
const current = repository.dot.semver.version;
|
||||||
|
|
||||||
|
if(latest.match(/\d+\.\d+\.\d+/i) && latest !== repository.dot.semver.version){
|
||||||
|
core.info(`found newer version ${latest}`);
|
||||||
|
repository.dot.semver.version = latest.split('.').slice(0,3).join('.');
|
||||||
|
if(repository.dot.semver?.latest){
|
||||||
|
repository.dot.semver.latest = repository.dot.semver.version;
|
||||||
|
}
|
||||||
|
if(repository.dot.semver?.stable){
|
||||||
|
repository.dot.semver.stable = repository.dot.semver.version;
|
||||||
|
}
|
||||||
|
if(repository.dot?.readme?.comparison?.image){
|
||||||
|
repository.dot.readme.comparison.image = repository.dot.readme.comparison.image.replace(/\d+\.\d+/i , latest.split('.').slice(0,2).join('.'));
|
||||||
|
}
|
||||||
|
try{
|
||||||
|
writeFileSync(resolve('.json'), JSON.stringify(repository.dot, null, 2));
|
||||||
|
core.exportVariable('WORKFLOW_AUTO_UPDATE', true);
|
||||||
|
}catch(e){
|
||||||
|
core.setFailed(e);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
core.info(`latest version ${latest} is equal to current version ${repository.dot.semver.version}, no update needed!`);
|
||||||
|
}
|
||||||
|
|
||||||
|
core.info(inspect(repository.dot, {showHidden:false, depth:null, colors:true}));
|
||||||
|
|
||||||
|
- name: cron-update / checkout
|
||||||
|
id: checkout
|
||||||
|
if: env.WORKFLOW_AUTO_UPDATE == 'true'
|
||||||
|
run: |
|
||||||
|
git config user.name "github-actions[bot]"
|
||||||
|
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
||||||
|
git add .json
|
||||||
|
git commit -m "[upgrade] ${{ env.LATEST_VERSION }}"
|
||||||
|
git push origin HEAD:master
|
||||||
|
|
||||||
|
- name: cron-update / build docker image
|
||||||
|
if: env.WORKFLOW_AUTO_UPDATE == 'true' && steps.checkout.outcome == 'success'
|
||||||
|
uses: the-actions-org/workflow-dispatch@3133c5d135c7dbe4be4f9793872b6ef331b53bc7
|
||||||
|
with:
|
||||||
|
wait-for-completion: false
|
||||||
|
workflow: docker.yml
|
||||||
|
token: "${{ secrets.REPOSITORY_TOKEN }}"
|
||||||
|
inputs: '{ "release":"false", "readme":"true" }'
|
||||||
Reference in New Issue
Block a user