Skip to content

Commit

Permalink
Add update-link-index action (#207)
Browse files Browse the repository at this point in the history
## Changes

Add a new custom action named `update-link-index`.

## Related issues:

- depends on #164
- closes #163

---------

Co-authored-by: Martijn Laarman <[email protected]>
  • Loading branch information
reakaleek and Mpdreamz authored Jan 15, 2025
1 parent 418958f commit 8c46022
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 0 deletions.
63 changes: 63 additions & 0 deletions actions/update-link-index/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<!--
this documentation was generated by https://github.com/reakaleek/gh-action-readme
with the command `VERSION=main gh action-readme update`
-->

# <!--name-->Update Link Index<!--/name-->

<!--description-->
This action updates the link index for the given link reference file.
<!--/description-->

## Inputs

<!--inputs-->
| Name | Description | Required | Default |
|-----------------------|----------------------------------------------------------------|----------|-----------------------------------|
| `link_reference_file` | The path to the link reference file | `false` | `.artifacts/docs/html/links.json` |
| `aws_account_id` | The AWS account ID to generate the role ARN for | `false` | `197730964718` |
| `aws_region` | The AWS region to use | `false` | `us-east-1` |
| `aws_s3_bucket_name` | The name of the S3 bucket to upload the link reference file to | `false` | `elastic-docs-link-index` |
<!--/inputs-->

## Outputs
<!--outputs-->
| Name | Description |
|------|-------------|
<!--/outputs-->

## Usage

<!--usage action="elastic/docs-builder/actions/update-link-index" version="env:VERSION"-->
```yaml
name: CI

on:
push:
branches:
- main
tags:
- "*.*.*"

permissions:
contents: read
packages: write

jobs:
deploy:
runs-on: ubuntu-latest
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{steps.deployment.outputs.page_url}}
steps:
- name: Publish Github
uses: elastic/docs-builder/actions/publish@main
id: deployment

- name: Update Link Index
uses: elastic/docs-builder/actions/update-link-index@main
```
<!--/usage-->
56 changes: 56 additions & 0 deletions actions/update-link-index/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Update Link Index

description: |
This action updates the link index for the given link reference file.
inputs:
link_reference_file:
description: 'The path to the link reference file'
required: false
default: '.artifacts/docs/html/links.json'
aws_account_id:
description: 'The AWS account ID to generate the role ARN for'
required: false
default: '197730964718' # elastic-web
aws_region:
description: 'The AWS region to use'
required: false
default: 'us-east-1'
aws_s3_bucket_name:
description: 'The name of the S3 bucket to upload the link reference file to'
required: false
default: 'elastic-docs-link-index'

runs:
using: composite
steps:
- name: Update Link Index
run: |
echo "Updating link index"
- name: Generate AWS Role ARN
id: role_arn
shell: python
env:
AWS_ACCOUNT_ID: ${{ inputs.aws_account_id }}
run: |
import hashlib
import os
prefix = "elastic-docs-link-index-uploader-"
aws_account_id = os.environ["AWS_ACCOUNT_ID"]
m = hashlib.sha256()
m.update(os.environ["GITHUB_REPOSITORY"].encode('utf-8'))
hash = m.hexdigest()[:64-len(prefix)]
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
f.write(f"result=arn:aws:iam::{aws_account_id}:role/{prefix}{hash}")
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
with:
role-to-assume: ${{ steps.role_arn.outputs.result }}
aws-region: us-east-1
- name: Upload Link Reference File to S3
bash: shell
run: |
repository_name=$(basename "${GITHUB_REPOSITORY}")
aws s3 cp ${{ inputs.link_reference_file }} "s3://${{ inputs.aws_s3_bucket_name }}/${repository_name}.json"

0 comments on commit 8c46022

Please sign in to comment.