Skip to content

Commit 8c46022

Browse files
reakaleekMpdreamz
andauthored
Add update-link-index action (#207)
## Changes Add a new custom action named `update-link-index`. ## Related issues: - depends on #164 - closes #163 --------- Co-authored-by: Martijn Laarman <[email protected]>
1 parent 418958f commit 8c46022

File tree

2 files changed

+119
-0
lines changed

2 files changed

+119
-0
lines changed

actions/update-link-index/README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<!--
2+
this documentation was generated by https://github.com/reakaleek/gh-action-readme
3+
with the command `VERSION=main gh action-readme update`
4+
-->
5+
6+
# <!--name-->Update Link Index<!--/name-->
7+
8+
<!--description-->
9+
This action updates the link index for the given link reference file.
10+
<!--/description-->
11+
12+
## Inputs
13+
14+
<!--inputs-->
15+
| Name | Description | Required | Default |
16+
|-----------------------|----------------------------------------------------------------|----------|-----------------------------------|
17+
| `link_reference_file` | The path to the link reference file | `false` | `.artifacts/docs/html/links.json` |
18+
| `aws_account_id` | The AWS account ID to generate the role ARN for | `false` | `197730964718` |
19+
| `aws_region` | The AWS region to use | `false` | `us-east-1` |
20+
| `aws_s3_bucket_name` | The name of the S3 bucket to upload the link reference file to | `false` | `elastic-docs-link-index` |
21+
<!--/inputs-->
22+
23+
## Outputs
24+
<!--outputs-->
25+
| Name | Description |
26+
|------|-------------|
27+
<!--/outputs-->
28+
29+
## Usage
30+
31+
<!--usage action="elastic/docs-builder/actions/update-link-index" version="env:VERSION"-->
32+
```yaml
33+
name: CI
34+
35+
on:
36+
push:
37+
branches:
38+
- main
39+
tags:
40+
- "*.*.*"
41+
42+
permissions:
43+
contents: read
44+
packages: write
45+
46+
jobs:
47+
deploy:
48+
runs-on: ubuntu-latest
49+
permissions:
50+
pages: write
51+
id-token: write
52+
environment:
53+
name: github-pages
54+
url: ${{steps.deployment.outputs.page_url}}
55+
steps:
56+
- name: Publish Github
57+
uses: elastic/docs-builder/actions/publish@main
58+
id: deployment
59+
60+
- name: Update Link Index
61+
uses: elastic/docs-builder/actions/update-link-index@main
62+
```
63+
<!--/usage-->

actions/update-link-index/action.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Update Link Index
2+
3+
description: |
4+
This action updates the link index for the given link reference file.
5+
6+
inputs:
7+
link_reference_file:
8+
description: 'The path to the link reference file'
9+
required: false
10+
default: '.artifacts/docs/html/links.json'
11+
aws_account_id:
12+
description: 'The AWS account ID to generate the role ARN for'
13+
required: false
14+
default: '197730964718' # elastic-web
15+
aws_region:
16+
description: 'The AWS region to use'
17+
required: false
18+
default: 'us-east-1'
19+
aws_s3_bucket_name:
20+
description: 'The name of the S3 bucket to upload the link reference file to'
21+
required: false
22+
default: 'elastic-docs-link-index'
23+
24+
runs:
25+
using: composite
26+
steps:
27+
- name: Update Link Index
28+
run: |
29+
echo "Updating link index"
30+
- name: Generate AWS Role ARN
31+
id: role_arn
32+
shell: python
33+
env:
34+
AWS_ACCOUNT_ID: ${{ inputs.aws_account_id }}
35+
run: |
36+
import hashlib
37+
import os
38+
39+
prefix = "elastic-docs-link-index-uploader-"
40+
aws_account_id = os.environ["AWS_ACCOUNT_ID"]
41+
42+
m = hashlib.sha256()
43+
m.update(os.environ["GITHUB_REPOSITORY"].encode('utf-8'))
44+
hash = m.hexdigest()[:64-len(prefix)]
45+
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
46+
f.write(f"result=arn:aws:iam::{aws_account_id}:role/{prefix}{hash}")
47+
- name: Configure AWS Credentials
48+
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
49+
with:
50+
role-to-assume: ${{ steps.role_arn.outputs.result }}
51+
aws-region: us-east-1
52+
- name: Upload Link Reference File to S3
53+
bash: shell
54+
run: |
55+
repository_name=$(basename "${GITHUB_REPOSITORY}")
56+
aws s3 cp ${{ inputs.link_reference_file }} "s3://${{ inputs.aws_s3_bucket_name }}/${repository_name}.json"

0 commit comments

Comments
 (0)