Skip to content

Commit c095115

Browse files
authored
Add codex/update-link-index action (#4)
* Use temporary folder for downloading the zip and use GITHUB_PATH * Add integration test * Add triggers * Fix name * Add codex/update-link-index action
1 parent a303033 commit c095115

3 files changed

Lines changed: 101 additions & 1 deletion

File tree

codex/update-link-index/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!-- Generated by https://github.com/reakaleek/gh-action-readme -->
2+
# <!--name-->codex/update-link-index<!--/name-->
3+
<!--description-->
4+
This action updates the link index for the given repository.
5+
<!--/description-->
6+
7+
## Inputs
8+
<!--inputs-->
9+
| Name | Description | Required | Default |
10+
|---------------|----------------------------------------------|----------|---------|
11+
| `environment` | The environment to update the link index for | `false` | `dev` |
12+
<!--/inputs-->
13+
14+
## Outputs
15+
<!--outputs-->
16+
| Name | Description |
17+
|------|-------------|
18+
<!--/outputs-->
19+
20+
## Usage
21+
<!--usage action="your/action" version="v1"-->
22+
```yaml
23+
steps:
24+
- uses: elastic/docs-actions/codex/update-link-index@main
25+
```
26+
<!--/usage-->

codex/update-link-index/action.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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

docs-builder/setup/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Set up elastic/docs-builder CLI for use in actions
99
| Name | Description | Required | Default |
1010
|----------------|---------------------|----------|-----------------------|
1111
| `version` | docs-builer version | `false` | `latest` |
12-
| `github-token` | GitHub token | `true` | `${{ github.token }}` |
12+
| `github-token` | GitHub token | `false` | `${{ github.token }}` |
1313
<!--/inputs-->
1414

1515
## Outputs

0 commit comments

Comments
 (0)