Skip to content

Commit 9b8e735

Browse files
committed
Add update-registry-metadata workflow
1 parent 94c7a35 commit 9b8e735

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Update Registry Metadata
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
env:
9+
GITHUB_ROLE_ARN: arn:aws:iam::461800378586:role/GitHubECRPublic
10+
11+
permissions:
12+
id-token: write # Required for OIDC
13+
contents: read # This is required for actions/checkout
14+
15+
jobs:
16+
update_ecr_about_text:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v5
21+
22+
- name: Get repo name
23+
id: image_name
24+
run: |
25+
sed -E -e 's/docker-//' -e 's/^/image_name=/' <<<"${{ github.repository }}" >> "$GITHUB_OUTPUT"
26+
27+
- name: Get repo description
28+
id: repo_description
29+
run: |
30+
description=$(gh repo view ${{ github.repository }} --json description -q .description)
31+
echo "description=$description" >> "$GITHUB_OUTPUT"
32+
env:
33+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
35+
# There are numerous issues with extracting a Usage section
36+
# * Varying levels of header ie "# Usage" or "## Usage"
37+
# * The match should continue until the next header of the same level or a higher level
38+
# * The next header could be indented in a quote or alert/note eg "> # Next Section"
39+
# * The section name could differ, Usage | usage | Install | Example etc
40+
# Note: if we put this back in it needs to be added to the Update Catalog Data step
41+
# - name: Extract Usage from README
42+
# id: usage
43+
# run: |
44+
# if awk '/^#+ *Install \/ Usage/{flag=1; next} /^#+/{flag=0} flag' README.md | grep -q .; then
45+
# usage=$(awk '/^#+ *Install \/ Usage/{flag=1; next} /^#+/{flag=0} flag' README.md)
46+
# echo "usage<<EOF" >> "$GITHUB_OUTPUT"
47+
# echo "$usage" >> "$GITHUB_OUTPUT"
48+
# echo "EOF" >> "$GITHUB_OUTPUT"
49+
# fi
50+
51+
- name: Configure AWS Credentials
52+
uses: aws-actions/configure-aws-credentials@v4
53+
with:
54+
role-to-assume: ${{ env.GITHUB_ROLE_ARN }}
55+
aws-region: us-east-1 # ECR Public is in us-east-1
56+
57+
- name: Update ECR Repository Catalog Data
58+
run: |
59+
set -x
60+
aws ecr-public get-repository-catalog-data --repository-name ${{ steps.image_name.outputs.image_name }} > catalog-data.json
61+
if [[ -n "${{ steps.repo_description.outputs.description }}" ]]; then
62+
jq --arg description "${{ steps.repo_description.outputs.description }}" '.catalogData.description = $description' catalog-data.json > catalog-data.json.tmp && mv catalog-data.json.tmp catalog-data.json
63+
fi
64+
jq --arg about "$(cat README.md)" --arg repo "${{ steps.image_name.outputs.image_name }}" '.catalogData.aboutText = $about | .repositoryName = $repo' catalog-data.json > catalog-data.json.tmp && mv catalog-data.json.tmp catalog-data.json
65+
aws ecr-public put-repository-catalog-data --repository-name ${{ steps.image_name.outputs.image_name }} --cli-input-json file://catalog-data.json

0 commit comments

Comments
 (0)