Skip to content

Commit bad9577

Browse files
committed
[feature] add readme and update workflows
1 parent 256f6f8 commit bad9577

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed

.github/workflows/cron.update.yml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: cron-update
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: "0 5 * * *"
7+
8+
jobs:
9+
cron-update:
10+
runs-on: ubuntu-latest
11+
12+
permissions:
13+
actions: read
14+
contents: write
15+
16+
steps:
17+
- name: init / checkout
18+
uses: actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2
19+
with:
20+
ref: 'master'
21+
22+
- name: cron-update / get latest version
23+
run: |
24+
echo "LATEST_VERSION=$(curl -s https://api.github.com/repos/AdguardTeam/AdGuardHome/releases/latest | jq -r '.tag_name' | sed 's/v//')" >> "${GITHUB_ENV}"
25+
26+
- name: cron-update / compare latest with current version
27+
uses: actions/github-script@62c3794a3eb6788d9a2a72b219504732c0c9a298
28+
with:
29+
script: |
30+
const { existsSync, readFileSync, writeFileSync } = require('node:fs');
31+
const { resolve } = require('node:path');
32+
const { inspect } = require('node:util');
33+
const latest = "${{ env.LATEST_VERSION }}";
34+
const repository = {dot:{}};
35+
36+
try{
37+
const path = resolve('.json');
38+
if(existsSync(path)){
39+
try{
40+
repository.dot = JSON.parse(readFileSync(path).toString());
41+
}catch(e){
42+
throw new Error('could not parse .json');
43+
}
44+
}else{
45+
throw new Error('.json does not exist');
46+
}
47+
}catch(e){
48+
core.setFailed(e);
49+
}
50+
51+
const current = repository.dot.semver.version;
52+
53+
if(latest.match(/\d+\.\d+\.\d+/i) && latest !== `${repository.dot.semver.version}`){
54+
core.info(`found newer version ${latest}`);
55+
repository.dot.semver.version = latest.split('.').slice(0,3).join('.');
56+
if(repository.dot.semver?.latest){
57+
repository.dot.semver.latest = repository.dot.semver.version;
58+
}
59+
if(repository.dot?.readme?.comparison?.image){
60+
repository.dot.readme.comparison.image = repository.dot.readme.comparison.image.replace(current , repository.dot.semver.version);
61+
}
62+
try{
63+
writeFileSync(resolve('.json'), JSON.stringify(repository.dot, null, 2));
64+
core.exportVariable('WORKFLOW_AUTO_UPDATE', true);
65+
}catch(e){
66+
core.setFailed(e);
67+
}
68+
}else{
69+
core.info(`latest version ${latest} is equal to current version ${repository.dot.semver.version}, no update needed!`);
70+
}
71+
72+
core.info(inspect(repository.dot, {showHidden:false, depth:null, colors:true}));
73+
74+
- name: cron-update / checkout
75+
id: checkout
76+
if: env.WORKFLOW_AUTO_UPDATE == 'true'
77+
run: |
78+
git config user.name "github-actions[bot]"
79+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
80+
git add .json
81+
git commit -m "[upgrade] ${{ env.LATEST_VERSION }}"
82+
git push origin HEAD:master
83+
84+
- name: cron-update / build docker image
85+
if: env.WORKFLOW_AUTO_UPDATE == 'true' && steps.checkout.outcome == 'success'
86+
uses: the-actions-org/workflow-dispatch@3133c5d135c7dbe4be4f9793872b6ef331b53bc7
87+
with:
88+
workflow: docker.yml
89+
wait-for-completion: false
90+
token: "${{ secrets.REPOSITORY_TOKEN }}"
91+
inputs: '{ "release":"false", "readme":"true" }'

.github/workflows/readme.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: readme
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
readme:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: update README.md
11+
uses: the-actions-org/workflow-dispatch@3133c5d135c7dbe4be4f9793872b6ef331b53bc7
12+
with:
13+
wait-for-completion: false
14+
workflow: docker.yml
15+
token: "${{ secrets.REPOSITORY_TOKEN }}"
16+
inputs: '{ "build":"false", "release":"false", "readme":"true" }'

0 commit comments

Comments
 (0)