<commit_before>name: publish-dist
on:
  workflow_run:
    workflows: build-dist
    types: [completed]

jobs:
  run:
    if: github.event.workflow_run.conclusion == 'success'
    runs-on: ubuntu-latest
    steps:
      - name: Download build-dist artifacts
        uses: dawidd6/action-download-artifact@v2
        with:
          workflow: build-dist
          run_id: ${{ github.event.workflow_run.id }}

      - name: Set up configuration and secrets
        run: |
          printf '[user]\n\tname = Cockpit Project\n\temail=<EMAIL>\n' > ~/.gitconfig
          echo '${{ secrets.COCKPITUOUS_TOKEN }}' > ~/.config/github-token
          # we push to -dist repo via https://github.com, that needs our cockpituous token
          git config --global credential.helper store
          echo 'https://token:${{ secrets.COCKPITUOUS_TOKEN }}@github.com' >> ~/.git-credentials

      - name: Commit dist tarball dist repo
        run: |
          set -ex

          # we need a fully predictable name/URL, and git introduces these
          # additional numbers into the version; so wrap it in a predictable named tar
          sha=$(ls -d dist-* | sed 's/dist-//')

          # multiple parallel workflows race against each other, so the final
          # `git push` may fail
          rc=1
          for retry in $(seq 5); do
              git clone https://github.com/${{ github.repository }}-dist.git dist-repo
              tar -cvf "dist-repo/${sha}.tar" -C "dist-$sha" .

              # freshly created empty repo?
              cd dist-repo
              git rev-parse HEAD >/dev/null 2>&1 || git init
              git add "${sha}.tar"
              git commit -m "Build for $sha"

              # remove tarballs older than a week
              now=$(date +%s)
              for f in *.tar; do
                  fmtime=$(git log --pretty=%at -n1 -- $f)
                  [ $(($now - $fmtime)) -lt 604800 ] || git rm $f
              done
              [ -z "$(git status --short)" ] || git commit -m 'Drop old builds'

              if git push; then<commit_msg>workflows: Reduce published dist tarball retention to 3 days<commit_after>name: publish-dist
on:
  workflow_run:
    workflows: build-dist
    types: [completed]

jobs:
  run:
    if: github.event.workflow_run.conclusion == 'success'
    runs-on: ubuntu-latest
    steps:
      - name: Download build-dist artifacts
        uses: dawidd6/action-download-artifact@v2
        with:
          workflow: build-dist
          run_id: ${{ github.event.workflow_run.id }}

      - name: Set up configuration and secrets
        run: |
          printf '[user]\n\tname = Cockpit Project\n\temail=<EMAIL>\n' > ~/.gitconfig
          echo '${{ secrets.COCKPITUOUS_TOKEN }}' > ~/.config/github-token
          # we push to -dist repo via https://github.com, that needs our cockpituous token
          git config --global credential.helper store
          echo 'https://token:${{ secrets.COCKPITUOUS_TOKEN }}@github.com' >> ~/.git-credentials

      - name: Commit dist tarball dist repo
        run: |
          set -ex

          # we need a fully predictable name/URL, and git introduces these
          # additional numbers into the version; so wrap it in a predictable named tar
          sha=$(ls -d dist-* | sed 's/dist-//')

          # multiple parallel workflows race against each other, so the final
          # `git push` may fail
          rc=1
          for retry in $(seq 5); do
              git clone https://github.com/${{ github.repository }}-dist.git dist-repo
              tar -cvf "dist-repo/${sha}.tar" -C "dist-$sha" .

              # freshly created empty repo?
              cd dist-repo
              git rev-parse HEAD >/dev/null 2>&1 || git init
              git add "${sha}.tar"
              git commit -m "Build for $sha"

              # remove tarballs older than 3 days
              now=$(date +%s)
              for f in *.tar; do
                  fmtime=$(git log --pretty=%at -n1 -- $f)
                  [ $(($now - $fmtime)) -lt 259200 ] || git rm $f
              done
              [ -z "$(git status --short)" ] || git commit -m 'Drop old builds'

              if git push; then
{'fraction_non_alphanumeric': 0.11833612240019126, 'fraction_numerical': 0.006693760459000717, 'mean_word_length': 1.7328543435662966, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5916985', 'n_tokens_mistral': 1267, 'n_tokens_neox': 1181, 'n_words': 397}