From bf47e3641194c36e9b3cb1b14a9ede33d49ffe56 Mon Sep 17 00:00:00 2001 From: Matthew Sevey Date: Wed, 10 Jan 2024 09:15:31 -0500 Subject: [PATCH] ci: fix indenting, add comments, and enable yamllint --- .../reusable_dockerfile_pipeline.yml | 79 ++++++++++--------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/.github/workflows/reusable_dockerfile_pipeline.yml b/.github/workflows/reusable_dockerfile_pipeline.yml index e9840af..7c9f92d 100644 --- a/.github/workflows/reusable_dockerfile_pipeline.yml +++ b/.github/workflows/reusable_dockerfile_pipeline.yml @@ -38,54 +38,55 @@ jobs: # Extract both the repository owner and repository name # According to docs, github.repository is in the format of owner/repo, not just repo # https://docs.github.com/en/actions/learn-github-actions/contexts#github-context - REPO_OWNER=$(echo "${{ github.repository }}" | awk -F'/' '{print $1}' | tr '[:upper:]' '[:lower:]') - REPO_NAME=$(echo "${{ github.repository }}" | awk -F'/' '{print $2}' | tr '[:upper:]' '[:lower:]') + REPO_OWNER=$(echo "${{ github.repository }}" | awk -F'/' '{print $1}' | tr '[:upper:]' '[:lower:]') + REPO_NAME=$(echo "${{ github.repository }}" | awk -F'/' '{print $2}' | tr '[:upper:]' '[:lower:]') - echo "Repository Owner: $REPO_OWNER" - echo "Repository Name: $REPO_NAME" + # Log variables for debugging + echo "Repository Owner: $REPO_OWNER" + echo "Repository Name: $REPO_NAME" + echo "INPUT PACKAGE NAME: ${{ inputs.packageName }}" - echo "REPO_OWNER=$REPO_OWNER" >> $GITHUB_ENV - echo "repo_owner=$REPO_OWNER" >> "$GITHUB_OUTPUT" + # Set environment variables and outputs + echo "REPO_OWNER=$REPO_OWNER" >> $GITHUB_ENV + echo "repo_owner=$REPO_OWNER" >> "$GITHUB_OUTPUT" + echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV + echo "short_sha=`echo ${GITHUB_SHA} | cut -c1-8`" >> "$GITHUB_OUTPUT" - echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV - echo "short_sha=`echo ${GITHUB_SHA} | cut -c1-8`" >> "$GITHUB_OUTPUT" - # yamllint disable - echo "INPUT PACKAGE NAME: ${{ inputs.packageName }}" - if [[ "${{ inputs.packageName }}" == "${{ github.repository }}" ]]; then - # If a user submitted package name that has the naming containing - # both the repository owner and repository name, we fail - # e.g: inputs.packageName = "celestiaorg/celestiaorg" is not allowed - echo "------------------------------------------------------------" - echo "ERROR: Package name not valid! => [ ${{ inputs.packageName }} ]" - echo "Don't use the repository owner and repository name in the package name." - echo "------------------------------------------------------------" - exit 1 - fi + if [[ "${{ inputs.packageName }}" == "${{ github.repository }}" ]]; then + # If a user submitted package name that has the naming containing + # both the repository owner and repository name, we fail + # e.g: inputs.packageName = "celestiaorg/celestiaorg" is not allowed + echo "------------------------------------------------------------" + echo "ERROR: Package name not valid! => [ ${{ inputs.packageName }} ]" + echo "Don't use the repository owner and repository name in the package name." + echo "------------------------------------------------------------" + exit 1 + fi - # Set the default package name to the repository name - PACKAGE_NAME=$REPO_NAME + # Set the default package name to the repository name + PACKAGE_NAME=$REPO_NAME - # If there is a user submitted package name, use it - if [[ -n "${{ inputs.packageName }}" ]]; then - PACKAGE_NAME=$(echo "${{ inputs.packageName }}" | tr '[:upper:]' '[:lower:]') - fi + # If there is a user submitted package name, use it + if [[ -n "${{ inputs.packageName }}" ]]; then + PACKAGE_NAME=$(echo "${{ inputs.packageName }}" | tr '[:upper:]' '[:lower:]') + fi - # validate the package name characters - if [[ ! $PACKAGE_NAME =~ ^[A-Za-z0-9\-]+$ ]]; then - echo "------------------------------------------------------------" - echo "ERROR: Package name not valid! => [ $PACKAGE_NAME ]" - echo "ONLY can use: A-Za-z0-9\-" - echo "------------------------------------------------------------" - exit 1 - fi + # validate the package name characters + if [[ ! $PACKAGE_NAME =~ ^[A-Za-z0-9\-]+$ ]]; then + echo "------------------------------------------------------------" + echo "ERROR: Package name not valid! => [ $PACKAGE_NAME ]" + echo "ONLY can use: A-Za-z0-9\-" + echo "------------------------------------------------------------" + exit 1 + fi - echo "PACKAGE_NAME: $PACKAGE_NAME" + # Log the package name for debugging + echo "PACKAGE_NAME: $PACKAGE_NAME" - echo "IMAGE_NAME=$PACKAGE_NAME" >> $GITHUB_ENV - echo "image_name=$PACKAGE_NAME" >> "$GITHUB_OUTPUT" - - # yamllint enable + # Set environment variables and outputs + echo "IMAGE_NAME=$PACKAGE_NAME" >> $GITHUB_ENV + echo "image_name=$PACKAGE_NAME" >> "$GITHUB_OUTPUT" # The key logic that we want to determine is whether or not we are working # on a fork and if this is a pull request or merge to main.