Skip to content

Commit 5479252

Browse files
committed
chore: upgrade to latest workflows
1 parent 309bc96 commit 5479252

File tree

4 files changed

+177
-23
lines changed

4 files changed

+177
-23
lines changed

.github/workflows/org.readme.yml

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

.github/workflows/org.update.yml

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
name: org.update
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
etc:
7+
description: 'base64 encoded json string'
8+
required: true
9+
10+
jobs:
11+
update:
12+
runs-on: ubuntu-latest
13+
14+
permissions:
15+
actions: read
16+
contents: write
17+
18+
steps:
19+
- name: init / checkout
20+
uses: actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2
21+
with:
22+
ref: 'master'
23+
fetch-depth: 0
24+
25+
- name: update / setup node
26+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
27+
with:
28+
node-version: '20'
29+
- run: npm i semver
30+
31+
- name: update / compare latest with current version
32+
uses: actions/github-script@62c3794a3eb6788d9a2a72b219504732c0c9a298
33+
with:
34+
script: |
35+
(async()=>{
36+
const { Buffer } = require('node:buffer');
37+
const { inspect } = require('node:util');
38+
const { existsSync, readFileSync, writeFileSync } = require('node:fs');
39+
const { resolve } = require('node:path');
40+
const semver = require('semver')
41+
42+
// defaults
43+
const json = `${{ toJSON(github.event.inputs) }}`;
44+
const job = {inputs:{}, json:{}};
45+
46+
// check if inputs is valid base64 encoded json
47+
try{
48+
if(json.length > 0){
49+
const n = JSON.parse(json);
50+
if(n?.etc){
51+
try{
52+
job.inputs = JSON.parse(Buffer.from(n.etc, 'base64').toString('ascii'));
53+
if(!job.inputs?.version){
54+
core.setFailed(`input does not contain valid semver version: ${inspect(job.inputs, {showHidden:false, depth:null, colors:true})}`);
55+
}else if(!job.inputs?.tag){
56+
core.setFailed(`input does not contain valid git tag: ${inspect(job.inputs, {showHidden:false, depth:null, colors:true})}`);
57+
}
58+
}catch(e){
59+
core.setFailed(`could not parse github.event.inputs.etc: ${n.etc} (${Buffer.from(n.etc, 'base64').toString('ascii')})`);
60+
}
61+
}
62+
}
63+
}catch(e){
64+
core.setFailed(`could not parse github.event.inputs: ${json}`);
65+
}
66+
67+
// check if .json exists
68+
try{
69+
const path = resolve('.json');
70+
if(existsSync(path)){
71+
try{
72+
job.json = JSON.parse(readFileSync(path).toString());
73+
}catch(e){
74+
throw new Error('could not parse .json');
75+
}
76+
}else{
77+
throw new Error('.json does not exist!');
78+
}
79+
}catch(e){
80+
core.setFailed(e);
81+
}
82+
83+
// semver
84+
const latest = semver.valid(semver.coerce(job.inputs.version));
85+
const current = semver.valid(semver.coerce(job.json.semver.version));
86+
const tag = semver.valid(semver.coerce(job.inputs.tag));
87+
const checks = {latestTagExists:true};
88+
89+
try{
90+
const tag = await fetch(`https://hub.docker.com/v2/repositories/${job.json.image}/tags/${latest}`);
91+
if(tag.status === 404){
92+
checks.latestTagExists = false;
93+
}
94+
}catch(e){
95+
core.warning(e);
96+
}
97+
98+
// compare
99+
if((latest && latest !== current) || !checks.latestTagExists){
100+
core.info(`new ${semver.diff(current, latest)} release found (${latest}), updating ...`)
101+
job.json.semver.version = latest;
102+
103+
// update .json
104+
try{
105+
writeFileSync(resolve('.json'), JSON.stringify(job.json, null, 2));
106+
107+
// export variables
108+
core.exportVariable('WORKFLOW_UPDATE', true);
109+
core.exportVariable('LATEST_TAG', semver.inc(tag, semver.diff(current, latest)));
110+
core.exportVariable('LATEST_VERSION', latest);
111+
}catch(e){
112+
core.setFailed(e);
113+
}
114+
}else{
115+
core.info('no update required')
116+
}
117+
118+
core.info(inspect(job, {showHidden:false, depth:null, colors:true}));
119+
})();
120+
121+
122+
123+
- name: update / checkout
124+
id: checkout
125+
if: env.WORKFLOW_UPDATE == 'true'
126+
run: |
127+
git config user.name "github-actions[bot]"
128+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
129+
git add .json
130+
git commit -m "chore: auto upgrade to v${{ env.LATEST_VERSION }}"
131+
git push origin HEAD:master
132+
133+
- name: update / tag
134+
if: env.WORKFLOW_UPDATE == 'true' && steps.checkout.outcome == 'success'
135+
run: |
136+
SHA256=$(git rev-list --branches --max-count=1)
137+
git tag -a v${{ env.LATEST_TAG }} -m "v${{ env.LATEST_TAG }}" ${SHA256}
138+
git push --follow-tags
139+
140+
- name: update / build container image
141+
if: env.WORKFLOW_UPDATE == 'true' && steps.checkout.outcome == 'success'
142+
uses: the-actions-org/workflow-dispatch@3133c5d135c7dbe4be4f9793872b6ef331b53bc7
143+
with:
144+
workflow: docker.yml
145+
wait-for-completion: false
146+
token: "${{ secrets.REPOSITORY_TOKEN }}"
147+
inputs: '{ "release":"true", "readme":"true" }'
148+
ref: "v${{ env.LATEST_TAG }}"

.github/workflows/version.yml renamed to .github/workflows/org.version.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
1-
name: version
1+
name: org.version
2+
run-name: org.version ${{ inputs.version }}
3+
24
on:
35
workflow_dispatch:
46
inputs:
57
version:
68
description: 'set version for build'
79
type: string
810
required: true
11+
912
jobs:
13+
# ╔═════════════════════════════════════════════════════╗
14+
# ║ BUILD VERSION {N} IMAGE ║
15+
# ╚═════════════════════════════════════════════════════╝
1016
version:
1117
runs-on: ubuntu-latest
1218
steps:
13-
# ╔═════════════════════════════════════════════════════╗
14-
# ║ BUILD VERSION {N} IMAGE ║
15-
# ╚═════════════════════════════════════════════════════╝
16-
- name: version / setup config
19+
- name: setup config
1720
uses: actions/github-script@62c3794a3eb6788d9a2a72b219504732c0c9a298
1821
with:
1922
script: |
2023
const { Buffer } = require('node:buffer');
2124
const etc = {
2225
version:"${{ github.event.inputs.version }}",
23-
semver:{disable:{rolling: true}}
26+
semver:{disable:{rolling:true}}
2427
};
2528
core.exportVariable('WORKFLOW_BASE64JSON', Buffer.from(JSON.stringify(etc)).toString('base64'));
2629
27-
- name: version / build container image
30+
- name: build container image
2831
uses: the-actions-org/workflow-dispatch@3133c5d135c7dbe4be4f9793872b6ef331b53bc7
2932
with:
3033
wait-for-completion: false

.github/workflows/readme.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)