diff --git a/.github/workflows/gt-update.yml b/.github/workflows/gt-update.yml index 15a082f0..af8fb6b3 100644 --- a/.github/workflows/gt-update.yml +++ b/.github/workflows/gt-update.yml @@ -5,7 +5,7 @@ # \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under European Union Public License v. 1.2 # /___/ Please report bugs and contribute back your improvements # -# Version: v2.3.0 +# Version: v3.0.2 ################################### name: "gt update" @@ -119,12 +119,7 @@ jobs: - name: reset gpg keys run: gt reset --gpg-only true -r "${{ matrix.remote }}" - name: gt update - id: gt_update - run: | - set -euo pipefail - gt update -r "${{ matrix.remote }}" - gt update -r "${{ matrix.remote }}" - echo "remote_version=$(git --git-dir='.gt/remotes/${{ matrix.remote}}/repo/.git' tag | sort --version-sort | tail -n 1)" >> $GITHUB_OUTPUT + run: gt update -r "${{ matrix.remote }}" - id: has_changes name: git status run: | @@ -132,19 +127,84 @@ jobs: git status gitStatus=$(git status --porcelain) (if [[ $gitStatus != "" ]]; then echo "has_changes=1"; else echo "has_changes=0"; fi) >> $GITHUB_OUTPUT + - id: determine_versions + if: ${{ steps.has_changes.outputs.has_changes == 1 }} + run: | + set -euo pipefail + + pulledTsv=".gt/remotes/${{ matrix.remote }}/pulled.tsv" + allowedVersionRegex='^[a-zA-Z0-9._-]+$' + isMigration=false + + # pulled.tsv has two header lines (version pragma + column names), data starts at line 3 + dataStartLine=3 + + # tag + file of every entry as "tagfile", so we also notice a file which moved to another tag + oldEntries=$(git show "HEAD:$pulledTsv" | tail -n +"$dataStartLine" | cut -f1,2 | sort --version-sort) + newEntries=$(tail -n +"$dataStartLine" "$pulledTsv" | cut -f1,2 | sort --version-sort) + + changedFiles=$(git diff --name-only) + + # find out if we really have updates or if gt was updated and we merely migrated the pulled.tsv to a new version + if [[ "$changedFiles" == "$pulledTsv" ]]; then + oldPragma=$(git show "HEAD:$pulledTsv" | sed -n '1p') + newPragma=$(head -n 1 "$pulledTsv") + + if [[ $oldPragma != "$newPragma" ]]; then + # If some tag/file combination changed, then we consider it an update, even if no file content changed. + # Might be the files we fetched did not change in this release but we still update to a new version ... + if [[ "$oldEntries" == "$newEntries" ]]; then + # ... however, if tag and file are the same then it is solely a migration + isMigration=true + migrationVersion="${newPragma#"#@ Version: "}" + [[ $migrationVersion =~ $allowedVersionRegex ]] || { + echo >&2 "ERROR: migration version '$migrationVersion' does not match $allowedVersionRegex => something is odd, aborting." + exit 1 + } + echo "commit_message=migrate pulled.tsv of remote ${{ matrix.remote }} to version $migrationVersion" >>"$GITHUB_OUTPUT" + fi + fi + fi + + if [[ "$isMigration" == false ]]; then + # entries present now but not in HEAD, reduced to their tag (grep exits 1 on no match, hence || true) + mapfile -t newTags < <( + { grep -vxFf <(printf '%s\n' "$oldEntries") <<<"$newEntries" || true; } | + cut -f1 | + sort -u --version-sort + ) + + if ((${#newTags[@]} == 0)); then + echo >&2 "ERROR: could not find any new tags in $pulledTsv => something is odd (did you remove entries in a pull-hook?), aborting." + exit 1 + fi + + for t in "${newTags[@]}"; do + [[ "$t" =~ $allowedVersionRegex ]] || { + echo >&2 "ERROR: tag '$t' does not match $allowedVersionRegex => something is odd, aborting." + exit 1 + } + done + + newVersionsStr=$(IFS=, printf '%s' "${newTags[*]}") + + echo "commit_message=update files of remote ${{ matrix.remote }} to version(s) $newVersionsStr via gt" >>"$GITHUB_OUTPUT" + fi + - name: git commit if: ${{ steps.has_changes.outputs.has_changes == 1 }} + id: git_commit run: | set -euo pipefail git config --local user.name 'tegonal-bot' git config --local user.email 'tegonal-bot@users.noreply.github.com' - git commit -am 'update files of remote ${{ matrix.remote }} to version ${{steps.gt_update.outputs.remote_version}} via gt' || true + git commit -am '${{ steps.determine_versions.outputs.commit_message }}' || true - name: cleanup-on-push-to-main if: ${{ steps.has_changes.outputs.has_changes == 1 && hashFiles('./scripts/cleanup-on-push-to-main.sh') != '' }} run: | ( ./scripts/cleanup-on-push-to-main.sh || (printf '\033[0;31mERROR\033[0m: during cleanup, see error above\n' && false) && - (git commit -am 'cleanup after gt pull for remote ${{ matrix.remote }} and version ${{steps.gt_update.outputs.remote_version}}' || (printf '\033[0;31mERROR\033[0m: during commit, maybe no changes due to cleanup (which would be fine)?, see above\n'; false )) + (git commit -am 'cleanup after gt update for remote ${{ matrix.remote }}' || (printf '\033[0;31mERROR\033[0m: during commit, maybe no changes due to cleanup (which would be fine)?, see above\n'; false )) ) || (printf '\033[0;34mINFO\033[0m: going to reset changes back to the status after `gt update` and continue without cleanup\n' && git reset --hard) - name: Create pull request if necessary if: ${{ steps.has_changes.outputs.has_changes == 1 }} @@ -153,8 +213,8 @@ jobs: #gt-placeholder-gh-action-create-pr-end with: branch: 'gt/update/${{ matrix.remote }}' - title: 'update files of remote ${{ matrix.remote }} to version ${{steps.gt_update.outputs.remote_version}} via gt' - commit-message: 'update files of remote ${{ matrix.remote }} to version ${{steps.gt_update.outputs.remote_version}} via gt' + title: '${{ steps.determine_versions.outputs.commit_message }}' + commit-message: '${{ steps.determine_versions.outputs.commit_message }}' body: "following the changes after running `gt update -r \"${{ matrix.remote }}\"` and reset gpg keys" delete-branch: true token: ${{ secrets.AUTO_PR_TOKEN }} @@ -164,6 +224,7 @@ jobs: name: "Check signing-key" runs-on: ubuntu-latest steps: + #gt-placeholder-gh-action-checkout-3-start - uses: actions/checkout@v7 #gt-placeholder-gh-action-checkout-3-end diff --git a/.gt/remotes/gt/pulled.tsv b/.gt/remotes/gt/pulled.tsv index 61fddb91..b9b5e895 100644 --- a/.gt/remotes/gt/pulled.tsv +++ b/.gt/remotes/gt/pulled.tsv @@ -1,3 +1,3 @@ -#@ Version: 1.3.0 -tag file relativeTarget tagFilter hasPlaceholder sha512 -v2.3.0 .github/workflows/gt-update.yml ../.github/workflows/gt-update.yml .* true 679341556e5a6800456cb7ecc38fb7aa2932dcb68cb1f3b120c454470aea53b18a681f88b8ed0ac2399e4ace2ae52a0ec06c584cf15da6e590f7a1fe5f850320 +#@ Version: 1.4.0 +tag file relativeTarget tagFilter hasPlaceholder excludeFilesMatching sha512 +v3.0.2 .github/workflows/gt-update.yml ../.github/workflows/gt-update.yml .* true ^$ 176b38fa9497545726605b928b885957eb7490b5fd2f4a1348479c95151cb3b11784ddfd1f80131aa53b6443adc21e92a7769924a1ca950d2ec65a705a422711