import re

with open('.gitea/workflows/qa.yml', 'r') as f:
    content = f.read()

bad_auth = """      - name: 🔐 Registry Auth
        run: |
          echo "@mintel:registry=https://${{ vars.REGISTRY_HOST || 'npm.infra.mintel.me' }}" > .npmrc
          echo "//${{ vars.REGISTRY_HOST || 'npm.infra.mintel.me' }}/:_authToken=${{ secrets.REGISTRY_PASS }}" >> .npmrc"""

good_auth = """      - name: 🔐 Registry Auth
        run: |
          REGISTRY="${{ vars.REGISTRY_HOST || 'npm.infra.mintel.me' }}"
          echo "@mintel:registry=https://$REGISTRY" > .npmrc
          echo "//$REGISTRY/:_authToken=${{ secrets.NPM_TOKEN || secrets.GITEA_PAT || secrets.MINTEL_PRIVATE_TOKEN }}" >> .npmrc"""

content = content.replace(bad_auth, good_auth)

with open('.gitea/workflows/qa.yml', 'w') as f:
    f.write(content)
