From d50932520b7f47b12ff6742bcc89bc071e0a70d3 Mon Sep 17 00:00:00 2001 From: Clobee Date: Mon, 28 Apr 2025 13:14:22 +0100 Subject: [PATCH 1/2] Adds a workflow job to automatically update the version in the code --- .github/workflows/version_updater.yml | 75 +++++++++++++++++++++++++++ cfo-info.php | 2 +- composer.json | 2 +- global-cfo.php | 2 +- 4 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/version_updater.yml diff --git a/.github/workflows/version_updater.yml b/.github/workflows/version_updater.yml new file mode 100644 index 0000000..0f8e3e5 --- /dev/null +++ b/.github/workflows/version_updater.yml @@ -0,0 +1,75 @@ +name: "Update version 🚀" + +description: Search the code for __GCFO_UNDEFINED_VERSION__ and replaces it with the last release version. + +on: + push: + branches: [ main, master ] + +env: + DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION: true + FORCE_COLOR: true + TERM: xterm-256color + +jobs: + build: + name: Update version + runs-on: ubuntu-latest + + steps: + + - id: KeyDB + uses: pozetroninc/github-action-get-latest-release@master + with: + repository: ${{ github.repository }} + owner: JohnSully + repo: KeyDB + excludes: draft + + - name: Setup the environment + run: | + LAST_VERSION="`echo ${{ steps.keydb.outputs.release }}`" + echo "LAST_VERSION=${LAST_VERSION}" + echo "LAST_VERSION=${LAST_VERSION}" >> $GITHUB_ENV + + # Please use __GCFO_UNDEFINED_VERSION__ in your code + TMP_UNDEFINED_VERSION="__GCFO_UNDEFINED_VERSION__" + echo "UNDEFINED_VERSION=${TMP_UNDEFINED_VERSION}" + echo "UNDEFINED_VERSION=${TMP_UNDEFINED_VERSION}" >> $GITHUB_ENV + + - name: CheckOut Source Code + uses: actions/checkout@v4 + continue-on-error: true + with: + ref: main + fetch-depth: 0 + persist-credentials: true + set-safe-directory: true + clean: true + + - name: 🔍 Listing the files to be modified + id: search_code + run: | + SEARCH_CMD="`grep -rni --exclude-dir={.git,vendor,.github} \"${{ env.UNDEFINED_VERSION }}\" .`" + + # Continue only if we have something to modify + if [[ -z "$SEARCH_CMD" ]]; then + echo "No files containing ${{ env.UNDEFINED_VERSION }}" + else + echo "$SEARCH_CMD" + echo "modify_source=true" >> $GITHUB_OUTPUT + fi + + - name: ✨ Running the modification + if: ${{ steps.search_code.outputs.modify_source == 'true' }} + run: | + for file in `grep -rl --exclude-dir={.git,vendor,.github} "${{ env.UNDEFINED_VERSION }}" .`; do + sed -i "s/${{ env.UNDEFINED_VERSION }}/${{ env.LAST_VERSION }}/g" $file + done + + - name: Commit and push changes + if: ${{ steps.search_code.outputs.modify_source == 'true' }} + uses: devops-infra/action-commit-push@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + commit_message: "(pipeline) Update version:${{ env.LAST_VERSION }}" diff --git a/cfo-info.php b/cfo-info.php index fac91e9..0393573 100644 --- a/cfo-info.php +++ b/cfo-info.php @@ -1,5 +1,5 @@ Date: Thu, 15 May 2025 12:31:18 +0100 Subject: [PATCH 2/2] Adds workflow to search/replace __GCFO_UNDEFINED_VERSION__ with the last release tag --- .github/workflows/auto_tag_code.yml | 118 ++++++++++++++++++++++++++ .github/workflows/version_updater.yml | 75 ---------------- README.md | 2 + 3 files changed, 120 insertions(+), 75 deletions(-) create mode 100644 .github/workflows/auto_tag_code.yml delete mode 100644 .github/workflows/version_updater.yml diff --git a/.github/workflows/auto_tag_code.yml b/.github/workflows/auto_tag_code.yml new file mode 100644 index 0000000..4b2e44e --- /dev/null +++ b/.github/workflows/auto_tag_code.yml @@ -0,0 +1,118 @@ +name: Auto update the tags 🛠 + +# Search the code for __GCFO_UNDEFINED_VERSION__ and replaces it with the last release version. +# +# Automatically craft a new tag (according to the commits). +# Each merge is a minor version. +# For intentional version from the commit messages use: #major, #minor, #patch, #none +# +# The code search/replace will only works against __GCFO_UNDEFINED_VERSION__ . +# +# Search the code for __GCFO_UNDEFINED_VERSION__ and replaces it with the last tag. +# The changed files are being saved in the main branch "main". +# We recommend dev to use a "develop" branch as a trunk/working branch. +# +# When devs are ready to publish then they can craft a release using the latest tag(s). + +on: + pull_request: + types: [ "closed" ] + branches: [ "master", "main" ] + +env: + DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION: true + FORCE_COLOR: true + TERM: xterm-256color + +concurrency: production + +jobs: + build: + + name: Update tags + runs-on: ubuntu-latest + + steps: + + - name: Setup the environment + run: | + + # Please use __GCFO_UNDEFINED_VERSION__ in your code + TMP_UNDEFINED_VERSION="__GCFO_UNDEFINED_VERSION__" + echo "UNDEFINED_VERSION=${TMP_UNDEFINED_VERSION}" + echo "UNDEFINED_VERSION=${TMP_UNDEFINED_VERSION}" >> $GITHUB_ENV + + - name: CheckOut Source Code + uses: actions/checkout@v4 + # continue-on-error: true + with: + # ref: main + fetch-depth: '0' + # persist-credentials: true + # set-safe-directory: true + clean: true + + - name: Minor version for each merge + id: taggerDryRun + uses: anothrNick/github-tag-action@1.73.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + TAG_PREFIX: '' + DRY_RUN: true + # PRERELEASE: true + # DEFAULT_BRANCH: main + + - name: Display new tag + run: | + echo "The next tag version will be: ${{ steps.taggerDryRun.outputs.new_tag }}" + + - name: Display current tag + run: | + echo "The current tag is: ${{ steps.taggerDryRun.outputs.tag }}" + + - name: Display part + run: | + echo "The version increment was: ${{ steps.taggerDryRun.outputs.part }}" + + # DO MY BUILD HERE + # IN CASE OF FAILURE, THE STEP BELOW WILL NOT RUN. + + - name: 🔍 Listing the files to be modified + id: search_code + run: | + SEARCH_CMD=$(grep -rl --exclude-dir={.git,vendor,.github} "${{ env.UNDEFINED_VERSION }}" . || true) + COUNT_LINES=$(grep -rl --exclude-dir={.git,vendor,.github} "${{ env.UNDEFINED_VERSION }}" . | wc -l | awk '{print ($0+0)}') + + # Continue only if we have something to modify + if [ "$COUNT_LINES" -gt 0 ]; then + echo "Found ${COUNT_LINES} file(s) to modify" + echo "$SEARCH_CMD" + echo "modify_source=true" >> $GITHUB_OUTPUT + else + echo "No files containing ${{ env.UNDEFINED_VERSION }}" + fi + + - name: ✨ Running the modification + if: ${{ steps.search_code.outputs.modify_source == 'true' }} + run: | + for file in `grep -rl --exclude-dir={.git,vendor,.github} "${{ env.UNDEFINED_VERSION }}" .`; do + sed -i "s/${{ env.UNDEFINED_VERSION }}/${{ steps.taggerDryRun.outputs.new_tag }}/g" $file + done + + - name: Commit and push changes + if: ${{ steps.search_code.outputs.modify_source == 'true' }} + uses: devops-infra/action-commit-push@master + with: + force: true + github_token: ${{ secrets.GITHUB_TOKEN }} + commit_message: "(pipeline) Version update: ${{ steps.taggerDryRun.outputs.tag }} => ${{ steps.taggerDryRun.outputs.new_tag }} (${{ steps.taggerDryRun.outputs.part }})" + # target_branch: main + + - name: Minor version for each merge + uses: anothrNick/github-tag-action@1.73.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + TAG_PREFIX: '' + # DRY_RUN: true + PRERELEASE: true + # DEFAULT_BRANCH: main diff --git a/.github/workflows/version_updater.yml b/.github/workflows/version_updater.yml deleted file mode 100644 index 0f8e3e5..0000000 --- a/.github/workflows/version_updater.yml +++ /dev/null @@ -1,75 +0,0 @@ -name: "Update version 🚀" - -description: Search the code for __GCFO_UNDEFINED_VERSION__ and replaces it with the last release version. - -on: - push: - branches: [ main, master ] - -env: - DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION: true - FORCE_COLOR: true - TERM: xterm-256color - -jobs: - build: - name: Update version - runs-on: ubuntu-latest - - steps: - - - id: KeyDB - uses: pozetroninc/github-action-get-latest-release@master - with: - repository: ${{ github.repository }} - owner: JohnSully - repo: KeyDB - excludes: draft - - - name: Setup the environment - run: | - LAST_VERSION="`echo ${{ steps.keydb.outputs.release }}`" - echo "LAST_VERSION=${LAST_VERSION}" - echo "LAST_VERSION=${LAST_VERSION}" >> $GITHUB_ENV - - # Please use __GCFO_UNDEFINED_VERSION__ in your code - TMP_UNDEFINED_VERSION="__GCFO_UNDEFINED_VERSION__" - echo "UNDEFINED_VERSION=${TMP_UNDEFINED_VERSION}" - echo "UNDEFINED_VERSION=${TMP_UNDEFINED_VERSION}" >> $GITHUB_ENV - - - name: CheckOut Source Code - uses: actions/checkout@v4 - continue-on-error: true - with: - ref: main - fetch-depth: 0 - persist-credentials: true - set-safe-directory: true - clean: true - - - name: 🔍 Listing the files to be modified - id: search_code - run: | - SEARCH_CMD="`grep -rni --exclude-dir={.git,vendor,.github} \"${{ env.UNDEFINED_VERSION }}\" .`" - - # Continue only if we have something to modify - if [[ -z "$SEARCH_CMD" ]]; then - echo "No files containing ${{ env.UNDEFINED_VERSION }}" - else - echo "$SEARCH_CMD" - echo "modify_source=true" >> $GITHUB_OUTPUT - fi - - - name: ✨ Running the modification - if: ${{ steps.search_code.outputs.modify_source == 'true' }} - run: | - for file in `grep -rl --exclude-dir={.git,vendor,.github} "${{ env.UNDEFINED_VERSION }}" .`; do - sed -i "s/${{ env.UNDEFINED_VERSION }}/${{ env.LAST_VERSION }}/g" $file - done - - - name: Commit and push changes - if: ${{ steps.search_code.outputs.modify_source == 'true' }} - uses: devops-infra/action-commit-push@master - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - commit_message: "(pipeline) Update version:${{ env.LAST_VERSION }}" diff --git a/README.md b/README.md index 03837d6..c47853a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +> __LATEST TAG:__ __GCFO_UNDEFINED_VERSION__ + # What is it? An blank boilerplate plugin, structured a bit more like a big-boy project; namespaces, autoloader, a (basic) renderer, Exceptions.