Skip to content

Commit

Permalink
reduce matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
hugcabbage committed Sep 16, 2024
1 parent ad449bf commit f895259
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 68 deletions.
42 changes: 20 additions & 22 deletions .github/workflows/renew-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,54 +11,52 @@ jobs:
renew:
runs-on: ubuntu-latest
env:
DEPLOY_DIR: ${{ matrix.deploydir }}
DOT_CONFIG: ${{ matrix.dotconfig }}
EXTRA_STR: _some
strategy:
fail-fast: false
fail-fast: true
matrix:
deploydir:
- preset-lede
- preset-openwrt
- preset-immortalwrt
- preset-lienol-openwrt
- preset-x-wrt
dotconfig:
- 1.config
- 2.config
include:
- deploydir: preset-openwrt
dotconfig: multi-common.config
- deploydir: preset-openwrt
dotconfig: multi-mini.config
steps:

- uses: actions/checkout@v4
with:
path: ${{ env.EXTRA_STR }}

- name: Carry out
env:
RENEW_PY: extra-files/renew.py
RENEW_PY: ${{ env.EXTRA_STR }}/extra-files/renew.py
DEPLOY_DIR: ${{ env.EXTRA_STR }}/${{ matrix.deploydir }}
run: |
chmod +x $RENEW_PY
$RENEW_PY
dot_config_array=(1.config 2.config)
if [ "$DEPLOY_DIR" = "$EXTRA_STR/preset-openwrt" ]; then
dot_config_array+=(multi-common.config multi-mini.config)
fi
for dc in "${dot_config_array[@]}"; do
export DOT_CONFIG=$dc
chmod +x $RENEW_PY
$RENEW_PY
done
- uses: actions/upload-artifact@v4
with:
name: ${{ env.DEPLOY_DIR }}
path: ${{ env.DEPLOY_DIR }}
name: ${{ matrix.deploydir }}
path: ${{ env.EXTRA_STR }}/${{ matrix.deploydir }}

commit:
if: always()
needs: renew
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v4

- uses: actions/download-artifact@v3

- uses: actions/download-artifact@v3

- uses: geekyeggo/delete-artifact@v2
- uses: actions/download-artifact@v4

- uses: geekyeggo/delete-artifact@v5
with:
name: '*'

Expand Down
64 changes: 21 additions & 43 deletions .github/workflows/renew.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,60 +19,38 @@ permissions:

jobs:

set-matrix:
runs-on: ubuntu-latest
outputs:
dotconfig: ${{ steps.set-matrix.outputs.dotconfig }}
deploydir: ${{ steps.set-matrix.outputs.deploydir }}
steps:

- uses: actions/checkout@v4

- id: set-matrix
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
let dotconfig = [];
let cLs = "${{ inputs.dotconfig }}".replaceAll(' ', '').split(',');
let deploydir = "${{ inputs.deploydir }}".trim();
if (deploydir.endsWith('/')) deploydir = deploydir.slice(0, -1);
for (i=0; i<cLs.length; i++) {
try {
fs.accessSync(deploydir + '/' + cLs[i]);
dotconfig.push(cLs[i]);
}
catch (err) {
console.log(cLs[i] + ' does not exist!');
}
}
core.setOutput("dotconfig", JSON.stringify(dotconfig));
core.setOutput("deploydir", deploydir);
renew:
needs: set-matrix
runs-on: ubuntu-latest
env:
DEPLOY_DIR: ${{ needs.set-matrix.outputs.deploydir }}
DOT_CONFIG: ${{ matrix.dotconfig }}
strategy:
matrix:
dotconfig: ${{ fromJSON(needs.set-matrix.outputs.dotconfig) }}
EXTRA_STR: _some
steps:

- uses: actions/checkout@v4
with:
path: ${{ env.EXTRA_STR }}

- name: Carry out
env:
RENEW_PY: extra-files/renew.py
RENEW_PY: ${{ env.EXTRA_STR }}/extra-files/renew.py
DEPLOY_DIR: ${{ env.EXTRA_STR }}/${{ inputs.deploydir }}
DOT_CONFIG_IN: ${{ inputs.dotconfig }}
run: |
chmod +x $RENEW_PY
$RENEW_PY
if [ ! -d "$DEPLOY_DIR" ]; then
echo "Directory $DEPLOY_DIR does not exist!"
exit 1
fi
dot_config_array=($(echo $DOT_CONFIG_IN | tr -d ' ' | tr ',' '\n'))
for dc in "${dot_config_array[@]}"; do
export DOT_CONFIG=$dc
chmod +x $RENEW_PY
$RENEW_PY
done

- uses: actions/upload-artifact@v4
with:
name: ${{ env.DEPLOY_DIR }}
path: ${{ env.DEPLOY_DIR }}
name: ${{ inputs.deploydir }}
path: ${{ env.EXTRA_STR }}/${{ inputs.deploydir }}

commit:
needs: renew
Expand All @@ -81,9 +59,9 @@ jobs:

- uses: actions/checkout@v4

- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4

- uses: geekyeggo/delete-artifact@v2
- uses: geekyeggo/delete-artifact@v5
with:
name: '*'

Expand Down
6 changes: 3 additions & 3 deletions extra-files/renew.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ def main():
shutil.move(f'{fcg}.fullbak', f'{bas}/{fconfig}.fullbak')

# Only .config and .config.fullbak of this renew are kept
for item in glob.glob(f'{destdir}/**', recursive=True):
if not os.path.isdir(item) and fconfig not in item:
os.remove(item)
#for item in glob.glob(f'{destdir}/**', recursive=True):
# if not os.path.isdir(item) and fconfig not in item:
# os.remove(item)


if __name__ == '__main__':
Expand Down
3 changes: 3 additions & 0 deletions extra-files/tools/routine_cmd.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import subprocess


Expand All @@ -12,5 +13,7 @@ def gen_dot_config(clone: str, config: str):
f'mv -f {config} .config && make defconfig',
f'cp -f .config {config}'
]
if os.path.isdir('feeds'):
commands[:] = commands[2:]
for cmd in commands:
subprocess.run(cmd, shell=True)

0 comments on commit f895259

Please sign in to comment.