Step 2, Generate the project from BaseVM #707
This file contains 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@v4 | |
with: | |
token: ${{ secrets.VM_TOKEN }} | |
fetch-depth: '2' | |
- name: Get latest release | |
id: get-latest-release | |
uses: InsonusK/[email protected] | |
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/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="${{ steps.get-latest-release.outputs.tag_name }}" | |
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: vmactions/[email protected] | |
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 | |
base-vm/run.sh : run.sh | |
- name: Update node_modules | |
run: | | |
[ -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 "[email protected]" | |
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 | |
- uses: EndBug/add-and-commit@v9 | |
with: | |
message: "Update from base vm" | |
pull: '--rebase --autostash ' | |
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 | |
run.sh | |
node_modules | |