Skip to content

Commit

Permalink
PR
Browse files Browse the repository at this point in the history
  • Loading branch information
willdavsmith committed Oct 16, 2023
1 parent 95c5517 commit 4cfa8f8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 30 deletions.
14 changes: 5 additions & 9 deletions .github/scripts/delete-recipes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,36 @@ set -e

# Get command line arguments
GHCR_ORG=$1
GHCR_PATH=$2
RECIPE_VERSION=$2

# Print usage information
function print_usage() {
echo "Usage: $0 <GHCR_ORG> <RECIPE_VERSION>"
echo " Deletes all recipes in the repository from the GitHub Container Registry. Requires you to be logged into GitHub."
echo " GHCR_ORG: Organization name of the GitHub Container Registry. For example, radius-project"
echo " GHCR_PATH: Path name for Recipe storage. For example, recipes"
echo " RECIPE_VERSION: Version of the recipe to publish. For example, 1.0"
}

# Verify that the required arguments are present
if [ -z "$GHCR_ORG" ] || [ -z "$RECIPE_VERSION" ]; then
if [ -z "$GHCR_ORG" ] || [ -z "$GHCR_PATH" ] || [ -z "$RECIPE_VERSION" ]; then
echo "Missing required arguments"
print_usage
exit 1
fi

# We create output that's intended to be consumed by the GitHub Action summary. If we're
# not running in a GitHub Action, we'll just silence the output.
if [[ -z "$GITHUB_STEP_SUMMARY" ]]; then
GITHUB_STEP_SUMMARY=/dev/null
fi

for RECIPE in $(find . -type f -name "*.bicep")
do
# Get the recipe name and directory name
# ./azure/redis-azure.bicep -> redis-azure and azure, respectively
export FILE_NAME=$(basename $RECIPE | cut -d. -f1)
export DIR_NAME=$(dirname $RECIPE | cut -d/ -f2)

echo "Deleting ghcr.io/$GHCR_ORG/recipes/$DIR_NAME/$FILE_NAME:$RECIPE_VERSION"
echo "Deleting ghcr.io/$GHCR_ORG/$GHCR_PATH/$DIR_NAME/$FILE_NAME:$RECIPE_VERSION"
gh api \
--method DELETE \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/orgs/$GHCR_ORG/packages/container/recipes/$DIR_NAME/$FILE_NAME:$RECIPE_VERSION
/orgs/$GHCR_ORG/packages/container/$GHCR_PATH/$DIR_NAME/$FILE_NAME:$RECIPE_VERSION
done
14 changes: 8 additions & 6 deletions .github/scripts/publish-recipes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ set -e

# Get command line arguments
GHCR_ORG=$1
RECIPE_VERSION=$2
GHCR_PATH=$2
RECIPE_VERSION=$3

# Print usage information
function print_usage() {
echo "Usage: $0 <GHCR_ORG> <RECIPE_VERSION>"
echo " Publishes all recipes in the repository to the GitHub Container Registry. Requires you to be logged into GitHub"
echo " GHCR_ORG: Organization name of the GitHub Container Registry. For example, radius-project"
echo " GHCR_PATH: Path name for Recipe storage. For example, recipes"
echo " RECIPE_VERSION: Version of the recipe to publish. For example, 1.0"
}

# Verify that the required arguments are present
if [ -z "$GHCR_ORG" ] || [ -z "$RECIPE_VERSION" ]; then
if [ -z "$GHCR_ORG" ] || [ -z "$GHCR_PATH" ] || [ -z "$RECIPE_VERSION" ]; then
echo "Missing required arguments"
print_usage
exit 1
Expand All @@ -28,14 +30,14 @@ if [[ -z "$GITHUB_STEP_SUMMARY" ]]; then
GITHUB_STEP_SUMMARY=/dev/null
fi

echo "## Recipes published to ghcr.io/$GHCR_ORG" >> $GITHUB_STEP_SUMMARY
echo "## Recipes published to ghcr.io/$GHCR_ORG/$GHCR_PATH" >> $GITHUB_STEP_SUMMARY
for RECIPE in $(find . -type f -name "*.bicep")
do
# Get the platform (file) name and resource (directory) name
export FILE_NAME=$(basename $RECIPE | cut -d. -f1) # rediscaches
export DIR_NAME=$(dirname $RECIPE | cut -d/ -f2) # dev

echo "Publishing $DIR_NAME/$FILE_NAME to ghcr.io/$GHCR_ORG from $RECIPE"
echo "- ghcr.io/$GHCR_ORG/recipes/$DIR_NAME/$FILE_NAME:$RECIPE_VERSION" >> $GITHUB_STEP_SUMMARY
rad bicep publish --file $RECIPE --target "br:ghcr.io/$GHCR_ORG/recipes/$DIR_NAME/$FILE_NAME:$RECIPE_VERSION"
echo "Publishing $DIR_NAME/$FILE_NAME to ghcr.io/$GHCR_ORG/$GHCR_PATH from $RECIPE"
echo "- ghcr.io/$GHCR_ORG/$GHCR_PATH/$DIR_NAME/$FILE_NAME:$RECIPE_VERSION" >> $GITHUB_STEP_SUMMARY
rad bicep publish --file $RECIPE --target "br:ghcr.io/$GHCR_ORG/$GHCR_PATH/$DIR_NAME/$FILE_NAME:$RECIPE_VERSION"
done
35 changes: 20 additions & 15 deletions .github/workflows/publish-recipes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ env:

jobs:
publish-dev:
name: Publish Recipes to Dev GHCR
name: Publish Recipes to GHCR - Dev
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' && github.event.action != 'closed'
steps:
Expand All @@ -55,12 +55,12 @@ jobs:
registry: ghcr.io
username: ${{ env.GHCR_ACTOR }}
password: ${{ secrets.GH_RAD_CI_BOT_PAT }}
- name: Publish Recipes to Dev GHCR
- name: Publish Recipes to GHCR
# Uses REL_VERSION as the recipe version so PR builds result in a `pr-<pr number>` tag
run: ./.github/scripts/publish-recipes.sh radius-project ${{ env.REL_VERSION }}
run: ./.github/scripts/publish-recipes.sh radius-project dev/recipes ${{ env.REL_VERSION }}

delete-dev:
name: Delete Dev GHCR Images
name: Delete GHCR recipes - Dev
runs-on: ubuntu-latest
needs: publish-dev
if: github.event_name == 'pull_request' && github.event.action == 'closed'
Expand All @@ -69,33 +69,38 @@ jobs:
uses: actions/checkout@v3
- name: Parse release version and set environment variables
run: python ./.github/scripts/get_release_version.py
- name: Delete Dev GHCR Images
- name: Delete Recipes from GHCR
# Uses REL_VERSION as the recipe version so PR builds result in a `pr-<pr number>` tag
run: ./.github/scripts/delete-recipes.sh radius-project ${{ env.REL_VERSION }}
run: ./.github/scripts/delete-recipes.sh radius-project dev/recipes ${{ env.REL_VERSION }}

# This is where we can add integration tests in the future

publish-public:
name: Publish Recipes to Public ACR
name: Publish Recipes to GHCR - Public
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
environment:
name: Public
env:
ACR_HOST: radius.azurecr.io
steps:
- name: Check out repo
uses: actions/checkout@v3
- name: Parse release version and set environment variables
run: python ./.github/scripts/get_release_version.py
- name: Download rad-bicep
- name: Download rad CLI
run: |
./.github/scripts/curl-with-retries.sh https://get.radapp.dev/tools/bicep-extensibility/edge/linux-x64/rad-bicep --output rad-bicep
echo "Downloading edge rad CLI"
wget -q "${{ env.RAD_CLI_URL }}" -O - | /bin/bash -s edge
chmod +x rad-bicep
./rad-bicep --version
- name: Publish Recipes to Prod ACR
run: |
./.github/scripts/publish-recipes.sh . radius.azurecr.io ${{ env.REL_CHANNEL }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ env.GHCR_ACTOR }}
password: ${{ secrets.GH_RAD_CI_BOT_PAT }}
- name: Publish Recipes to GHCR
run: |
./.github/scripts/publish-recipes.sh radius-project recipes ${{ env.REL_CHANNEL }}
if [ "${{ env.REL_TAG }}" != "${{ env.REL_CHANNEL }}" ]; then
./.github/scripts/publish-recipes.sh . radius.azurecr.io ${{ env.REL_TAG }}
./.github/scripts/publish-recipes.sh radius-project recipes ${{ env.REL_TAG }}
fi

0 comments on commit 4cfa8f8

Please sign in to comment.