Step 2, Generate the project from BaseVM #1189
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: "Step 2, Generate the project from BaseVM" | |
| 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@v6 | |
| with: | |
| token: ${{ secrets.VM_TOKEN }} | |
| fetch-depth: '2' | |
| - name: Preparing env variables | |
| run: | | |
| git switch main || (git fetch --all && git checkout -b main origin/main) | |
| . conf/default.release.conf | |
| echo "DEFAULT_RELEASE=$DEFAULT_RELEASE" >> $GITHUB_ENV | |
| echo "ALL_RELEASES=\"$(ls conf/ | grep -v default | sed 's/.conf//g' | tr '\n' ',' | sed "s/,\$//" | sed 's/,/", "/g')\"" >> $GITHUB_ENV | |
| LATEST_TAG="$(git tag --sort=-v:refname | head -n 1)" | |
| echo "LATEST_TAG=${LATEST_TAG}" >> $GITHUB_ENV | |
| echo "LATEST_VERSION_NUMBER=${LATEST_TAG:1}" >> $GITHUB_ENV | |
| oldHash="$(cat .github/workflows/test.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-vm.git | |
| mkdir -p .github/tpl | |
| cat base-vm/.github/tpl/README.tpl.md >.github/tpl/README.tpl.md | |
| - name: Generate files | |
| uses: anyvm-org/template-render@v0.0.4 | |
| with: | |
| datafile: .github/data/datafile.ini | |
| files: | | |
| base-vm/.github/tpl/test.tpl.yml : .github/workflows/test.yml | |
| base-vm/.github/tpl/manual.tpl.yml : .github/workflows/manual.yml | |
| base-vm/.github/FUNDING.yml : .github/FUNDING.yml | |
| base-vm/.github/workflows/readme.yml : .github/workflows/readme.yml | |
| base-vm/.github/workflows/major.yml : .github/workflows/major.yml | |
| base-vm/package.json : package.json | |
| base-vm/index.js : index.js | |
| base-vm/action.yml : action.yml | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: '24' | |
| - name: Update node_modules | |
| run: | | |
| node -v | |
| [ -e "node_modules" ] && git rm -r node_modules | |
| npm install --save | |
| git add node_modules | |
| - name: Check modifications | |
| run: | | |
| #if only hash id in test.yml changes, skip | |
| currentHash="$(cat .github/workflows/test.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/test.yml test.yml.back | |
| sed -i "s/$currentHash/$oldHash/g" .github/workflows/test.yml | |
| if git diff --quiet; then | |
| echo "no changes" | |
| else | |
| #has changes: | |
| rm -f test.yml.back | |
| rm -rf base-vm | |
| #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-vm" | |
| newHash="$(git rev-parse main)" | |
| echo "New hash: $newHash" | |
| #modify test.yml | |
| sed -i "s/$oldHash/$newHash/g" .github/workflows/test.yml | |
| fi | |
| - name: Commit and push changes | |
| run: | | |
| git config user.email "ghactions@vmactions.org" | |
| git config user.name "Generate.yml" | |
| git add \ | |
| .github/workflows/readme.yml \ | |
| .github/workflows/major.yml \ | |
| .github/workflows/manual.yml \ | |
| .github/workflows/test.yml \ | |
| .github/tpl/README.tpl.md \ | |
| .github/FUNDING.yml \ | |
| package.json \ | |
| package-lock.json \ | |
| index.js \ | |
| action.yml \ | |
| node_modules | |
| if git diff --cached --quiet; then | |
| echo "Nothing to commit, skipping push" | |
| else | |
| git commit -m "Update ${{ github.repository }} from base vm" | |
| git pull --rebase --autostash | |
| git push | |
| fi | |