|
| 1 | +# Source: https://github.com/panubo/reference-github-actions/blob/main/docker-images/update-registry-metadata.yml |
| 2 | + |
| 3 | +name: Update Registry Metadata |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + |
| 10 | +env: |
| 11 | + GITHUB_ROLE_ARN: arn:aws:iam::461800378586:role/GitHubECRPublic |
| 12 | + |
| 13 | +permissions: |
| 14 | + id-token: write # Required for OIDC |
| 15 | + contents: read # This is required for actions/checkout |
| 16 | + |
| 17 | +jobs: |
| 18 | + update_repo_metadata: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - name: Checkout |
| 22 | + uses: actions/checkout@v5 |
| 23 | + |
| 24 | + - name: Get repo name |
| 25 | + id: image_name |
| 26 | + run: | |
| 27 | + sed -E -e 's/docker-//' -e 's/^/image_name=/' <<<"${{ github.repository }}" >> "$GITHUB_OUTPUT" |
| 28 | +
|
| 29 | + - name: Get repo description |
| 30 | + id: repo_description |
| 31 | + run: | |
| 32 | + description=$(gh repo view ${{ github.repository }} --json description -q .description) |
| 33 | + echo "description=$description" >> "$GITHUB_OUTPUT" |
| 34 | + env: |
| 35 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 36 | + |
| 37 | + # There are numerous issues with extracting a Usage section |
| 38 | + # * Varying levels of header ie "# Usage" or "## Usage" |
| 39 | + # * The match should continue until the next header of the same level or a higher level |
| 40 | + # * The next header could be indented in a quote or alert/note eg "> # Next Section" |
| 41 | + # * The section name could differ, Usage | usage | Install | Example etc |
| 42 | + # Note: if we put this back in it needs to be added to the Update Catalog Data step |
| 43 | + # - name: Extract Usage from README |
| 44 | + # id: usage |
| 45 | + # run: | |
| 46 | + # if awk '/^#+ *Install \/ Usage/{flag=1; next} /^#+/{flag=0} flag' README.md | grep -q .; then |
| 47 | + # usage=$(awk '/^#+ *Install \/ Usage/{flag=1; next} /^#+/{flag=0} flag' README.md) |
| 48 | + # echo "usage<<EOF" >> "$GITHUB_OUTPUT" |
| 49 | + # echo "$usage" >> "$GITHUB_OUTPUT" |
| 50 | + # echo "EOF" >> "$GITHUB_OUTPUT" |
| 51 | + # fi |
| 52 | + |
| 53 | + - name: Configure AWS Credentials |
| 54 | + uses: aws-actions/configure-aws-credentials@v4 |
| 55 | + with: |
| 56 | + role-to-assume: ${{ env.GITHUB_ROLE_ARN }} |
| 57 | + aws-region: us-east-1 # ECR Public is in us-east-1 |
| 58 | + |
| 59 | + - name: Update ECR Repository Catalog Data |
| 60 | + env: |
| 61 | + # ECR only wants the image_name not owner/image_name so we add image_name as an env then strip the owner with bash variable manipulation |
| 62 | + IMAGE_NAME: ${{ steps.image_name.outputs.image_name }} |
| 63 | + run: | |
| 64 | + set -x |
| 65 | + aws ecr-public get-repository-catalog-data --repository-name ${IMAGE_NAME#*/} > catalog-data.json |
| 66 | + if [[ -n "${{ steps.repo_description.outputs.description }}" ]]; then |
| 67 | + 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 |
| 68 | + fi |
| 69 | + jq --arg about "$(cat README.md)" --arg repo "${IMAGE_NAME#*/}" '.catalogData.aboutText = $about | .repositoryName = $repo | del(.catalogData.logoUrl)' catalog-data.json > catalog-data.json.tmp && mv catalog-data.json.tmp catalog-data.json |
| 70 | + aws ecr-public put-repository-catalog-data --repository-name ${IMAGE_NAME#*/} --cli-input-json file://catalog-data.json |
| 71 | +
|
| 72 | + - name: Update Quay.io Repository Description |
| 73 | + run: | |
| 74 | + JSON_DESCRIPTION="$(jq -n --arg desc "$(<README.md)" '{description: $desc}')" |
| 75 | + curl -sSf -X PUT \ |
| 76 | + -H "Authorization: Bearer ${{ secrets.PANUBUILD_QUAYIO_API_TOKEN }}" \ |
| 77 | + -H "Content-Type: application/json" \ |
| 78 | + -d "${JSON_DESCRIPTION}" \ |
| 79 | + 'https://quay.io/api/v1/repository/${{ steps.image_name.outputs.image_name }}' |
0 commit comments