diff --git a/.github/workflows/generate.yml b/.github/workflows/generate.yml new file mode 100644 index 0000000..0fca38b --- /dev/null +++ b/.github/workflows/generate.yml @@ -0,0 +1,93 @@ +name: "Step 2, Generate the project from Base builder" +on: + schedule: + - cron: '10 1 * * *' + workflow_dispatch: + push: + branches: + - 'main' + paths: + - 'conf/*' + - '.github/data/*' + - '.github/workflows/generate.yml' + + +jobs: + generate: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + token: ${{ secrets.VM_TOKEN }} + fetch-depth: '2' + - name: Get latest release + id: get-latest-release + uses: InsonusK/get-latest-release@v1.0.1 + with: + myToken: ${{ github.token }} + view_top: 1 + + - name: Preparing env variables + run: | + git switch main || (git fetch --all && git checkout -b main origin/main) + . conf/all.release.conf + echo "ALL_RELEASES=$ALL_RELEASES" >> $GITHUB_ENV + oldHash="$(cat .github/workflows/build.yml | grep -i "uses: ${{ github.repository }}" | head -1 | cut -d @ -f 2)" + echo "OLD_HASH=${oldHash}" >> $GITHUB_ENV + git clone https://github.com/vmactions/base-builder.git + mkdir -p .github/tpl + cat base-builder/.github/tpl/README.tpl.md >.github/tpl/README.tpl.md + + - name: Generate files + uses: vmactions/render@v0.0.1 + with: + datafile: .github/data/datafile.ini + files: | + base-builder/.github/tpl/build.tpl.yml : .github/workflows/build.yml + base-builder/.github/tpl/manual.tpl.yml : .github/workflows/manual.yml + base-builder/.github/FUNDING.yml : .github/FUNDING.yml + base-builder/.github/workflows/readme.yml : .github/workflows/readme.yml + base-builder/build.sh : build.sh + + - name: Check modifications + run: | + #if only hash id in build.yml changes, skip + currentHash="$(cat .github/workflows/build.yml | grep -i "uses: ${{ github.repository }}" | head -1 | cut -d @ -f 2)" + echo "Current hash: $currentHash" + lastHash="$(git rev-parse 'HEAD~1')" + echo "Last hash: $lastHash" + oldHash="$lastHash" + echo "OLD_HASH: $OLD_HASH" + echo "Old hash using last hash: $oldHash" + git diff + cp .github/workflows/build.yml build.yml.back + sed -i "s/$currentHash/$oldHash/g" .github/workflows/build.yml + if git diff --quiet; then + echo "no changes" + else + #has changes: + rm -f build.yml.back + rm -rf base-builder + #commit all changes and get new hash + git config user.email "ghactions@vmactions.org" + git config user.name "Generate.yml" + git add . + git commit -m "Generated from base-builder" + newHash="$(git rev-parse main)" + echo "New hash: $newHash" + #modify build.yml + sed -i "s/$oldHash/$newHash/g" .github/workflows/build.yml + fi + - uses: EndBug/add-and-commit@v9 + with: + message: "Update from base vm" + pull: '--rebase --autostash ' + add: | + .github/workflows/readme.yml + .github/workflows/manual.yml + .github/workflows/build.yml + .github/tpl/README.tpl.md + .github/FUNDING.yml + build.sh + +