|
| 1 | +name: codex/update-link-index |
| 2 | +description: This action updates the link index for the given repository. |
| 3 | + |
| 4 | +inputs: |
| 5 | + environment: |
| 6 | + description: The environment to update the link index for |
| 7 | + required: false |
| 8 | + default: "dev" |
| 9 | + |
| 10 | +runs: |
| 11 | + using: composite |
| 12 | + steps: |
| 13 | + - name: Generate vault role |
| 14 | + id: generate-vault-role |
| 15 | + shell: bash |
| 16 | + run: | |
| 17 | + workflow_ref="${{ github.repository }}/.github/workflows/codex-build.yml" |
| 18 | + echo "${workflow_ref}" |
| 19 | + hash=$(echo -n "${workflow_ref}" | sha256sum | awk '{print substr($1, 1, 12)}') |
| 20 | + echo "result=token-policy-${hash}" >> "${GITHUB_OUTPUT}" |
| 21 | + - name: Fetch ephemeral GitHub token |
| 22 | + id: fetch-ephemeral-token |
| 23 | + uses: elastic/ci-gh-actions/fetch-github-token@v1.0.0 |
| 24 | + with: |
| 25 | + vault-instance: "ci-prod" |
| 26 | + vault-role: "${{ steps.generate-vault-role.outputs.result }}" |
| 27 | + - name: Clone codex-link-index |
| 28 | + uses: actions/checkout@v6 |
| 29 | + with: |
| 30 | + repository: elastic/codex-link-index |
| 31 | + token: ${{ steps.fetch-ephemeral-token.outputs.token }} |
| 32 | + - name: Download artifact |
| 33 | + uses: actions/download-artifact@v6 |
| 34 | + with: |
| 35 | + name: links |
| 36 | + path: ${{ inputs.environment }}/${{ github.repository }} |
| 37 | + - name: Commit and push |
| 38 | + shell: bash |
| 39 | + run: | |
| 40 | + echo "::group::Configure git" |
| 41 | + git config user.name "GitHub Actions" |
| 42 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 43 | + echo "::endgroup::" |
| 44 | +
|
| 45 | + echo "::group::Stage changes" |
| 46 | + git add . |
| 47 | + if git diff --staged --quiet; then |
| 48 | + echo "No changes to commit" |
| 49 | + echo "::endgroup::" |
| 50 | + exit 0 |
| 51 | + fi |
| 52 | + git diff --staged --stat |
| 53 | + echo "::endgroup::" |
| 54 | +
|
| 55 | + echo "::group::Commit" |
| 56 | + git commit -m "Update link index for ${{ github.repository }}@${{ github.sha }} |
| 57 | +
|
| 58 | + Workflow run URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" |
| 59 | + echo "::endgroup::" |
| 60 | + |
| 61 | + echo "::group::Push" |
| 62 | + for i in {1..5}; do |
| 63 | + if git push; then |
| 64 | + echo "Push succeeded" |
| 65 | + echo "::endgroup::" |
| 66 | + exit 0 |
| 67 | + fi |
| 68 | + echo "::warning::Push failed, attempt $i/5. Rebasing and retrying..." |
| 69 | + git pull --rebase |
| 70 | + done |
| 71 | +
|
| 72 | + echo "::error::Failed to push after 5 attempts" |
| 73 | + echo "::endgroup::" |
| 74 | + exit 1 |
0 commit comments