From b88ab2a928dc1c9bfa795f687fd9a2df9834cd5f Mon Sep 17 00:00:00 2001 From: Matthew Sevey Date: Wed, 17 Jan 2024 10:31:25 -0500 Subject: [PATCH] ci: fix bugs in docker workflow (#90) --- .../workflows/dockerfile_workflow_test.yaml | 8 ++ .../reusable_dockerfile_pipeline.yml | 85 ++++++++++--------- .../workflows/reusable_testground_test.yaml | 4 +- 3 files changed, 56 insertions(+), 41 deletions(-) diff --git a/.github/workflows/dockerfile_workflow_test.yaml b/.github/workflows/dockerfile_workflow_test.yaml index a9ffcf6..e8173a2 100644 --- a/.github/workflows/dockerfile_workflow_test.yaml +++ b/.github/workflows/dockerfile_workflow_test.yaml @@ -10,3 +10,11 @@ jobs: dockerfile: docker-action-test/Dockerfile packageName: docker-test secrets: inherit + reusable-build-defaults: + permissions: + contents: write + packages: write + uses: celestiaorg/.github/.github/workflows/reusable_dockerfile_pipeline.yml@develop + with: + dockerfile: docker-action-test/Dockerfile + secrets: inherit diff --git a/.github/workflows/reusable_dockerfile_pipeline.yml b/.github/workflows/reusable_dockerfile_pipeline.yml index 7e49fdb..5b5ef61 100644 --- a/.github/workflows/reusable_dockerfile_pipeline.yml +++ b/.github/workflows/reusable_dockerfile_pipeline.yml @@ -12,7 +12,6 @@ on: required: false type: string description: "You can specify a different package name." - default: "${{ github.repository }}" env: GITHUB_REG: ghcr.io @@ -39,52 +38,60 @@ 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" + # Check repo name for .github use to test this workflow + if [[ $REPO_NAME == ".github" ]]; then + # Remove the leading . to avoid failing the character check + REPO_NAME="github" + fi - echo "REPO_OWNER=$REPO_OWNER" >> $GITHUB_ENV - echo "repo_owner=$REPO_OWNER" >> "$GITHUB_OUTPUT" + # Log variables for debugging + echo "Repository Owner: $REPO_OWNER" + echo "Repository Name: $REPO_NAME" + echo "INPUT PACKAGE NAME: ${{ inputs.packageName }}" - 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 "${{ inputs.packageName }}" + # 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" - 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! => [ $PACKAGE_NAME} ]" - 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 - # If there is a user submitted package name, use it - if [[ -n "${{ inputs.packageName }}" ]]; then - PACKAGE_NAME=$(echo "${{ inputs.packageName }}" | tr '[:upper:]' '[:lower:]') - else - # Set the default package name to the repository name - PACKAGE_NAME=$REPO_NAME - fi + # Set the default package name to the repository name + PACKAGE_NAME=$REPO_NAME - # 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 + # If there is a user submitted package name, use it + if [[ -n "${{ inputs.packageName }}" ]]; then + PACKAGE_NAME=$(echo "${{ inputs.packageName }}" | tr '[:upper:]' '[:lower:]') + fi - echo "IMAGE_NAME=$PACKAGE_NAME" >> $GITHUB_ENV - echo "image_name=$PACKAGE_NAME" >> "$GITHUB_OUTPUT" + # 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 - # yamllint enable + # Log the package name for debugging + echo "PACKAGE_NAME: $PACKAGE_NAME" + + # 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. diff --git a/.github/workflows/reusable_testground_test.yaml b/.github/workflows/reusable_testground_test.yaml index 0ee352a..b25f4a3 100644 --- a/.github/workflows/reusable_testground_test.yaml +++ b/.github/workflows/reusable_testground_test.yaml @@ -7,7 +7,7 @@ on: description: "Path to Tests" required: true type: string - default: "compositions/cluster-k8s/sanity/002-da-sync-8.toml" + # default: "compositions/cluster-k8s/sanity/002-da-sync-8.toml" testground_url: required: true type: string @@ -16,7 +16,7 @@ on: required: true type: string description: "TestGround Cluster Region" - default: "eu-west-1" + # default: "eu-west-1" celestia_node_commit_sha: required: false type: string