diff --git a/actions/update-link-index/README.md b/actions/update-link-index/README.md new file mode 100644 index 000000000..1d3bbdbfe --- /dev/null +++ b/actions/update-link-index/README.md @@ -0,0 +1,63 @@ + + +# Update Link Index + + +This action updates the link index for the given link reference file. + + +## 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` | + + +## Outputs + +| Name | Description | +|------|-------------| + + +## Usage + + +```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 +``` + diff --git a/actions/update-link-index/action.yml b/actions/update-link-index/action.yml new file mode 100644 index 000000000..7c0eed867 --- /dev/null +++ b/actions/update-link-index/action.yml @@ -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"