From db91e8f041171a7364b55c66a1eae7f3840a23ab Mon Sep 17 00:00:00 2001 From: jfldde <168934971+jfldde@users.noreply.github.com> Date: Fri, 25 Oct 2024 13:28:21 +0100 Subject: [PATCH] Shared validate-bitcoin-da between workflows (#1378) --- .../actions/validate-bitcoin-da/action.yml | 106 ++++++++++++++++ .github/workflows/checks.yml | 97 ++------------ .github/workflows/release.yml | 120 +++--------------- 3 files changed, 131 insertions(+), 192 deletions(-) create mode 100644 .github/actions/validate-bitcoin-da/action.yml diff --git a/.github/actions/validate-bitcoin-da/action.yml b/.github/actions/validate-bitcoin-da/action.yml new file mode 100644 index 000000000..4cfc2f59e --- /dev/null +++ b/.github/actions/validate-bitcoin-da/action.yml @@ -0,0 +1,106 @@ +name: 'Bitcoin DA ID Validation' +description: 'Validates Bitcoin DA ID format and checks binaries' + +inputs: + expected_da_id: + description: 'Expected Bitcoin DA ID value' + required: true + action: + description: 'Which action to run (validate_format or check_binary)' + required: true + +runs: + using: "composite" + steps: + - name: Validate Format + if: inputs.action == 'validate_format' + shell: bash + run: | + echo "Raw EXPECTED_BITCOIN_DA_ID value:" + echo "${{ inputs.expected_da_id }}" + + echo "Length of EXPECTED_BITCOIN_DA_ID: ${#EXPECTED_BITCOIN_DA_ID}" + + if [ -z "${EXPECTED_BITCOIN_DA_ID// }" ]; then + echo "Error: EXPECTED_BITCOIN_DA_ID is not set, empty, or contains only spaces" + exit 1 + fi + + # Remove any trailing newline or carriage return + EXPECTED_BITCOIN_DA_ID=$(echo "${{ inputs.expected_da_id }}" | tr -d '\n\r') + + # Count commas and spaces + comma_count=$(echo "$EXPECTED_BITCOIN_DA_ID" | tr -cd ',' | wc -c) + space_count=$(echo "$EXPECTED_BITCOIN_DA_ID" | tr -cd ' ' | wc -c) + + echo "Number of commas: $comma_count" + echo "Number of spaces: $space_count" + + # Split the string into an array and trim each element + IFS=', ' read -ra raw_numbers <<< "$EXPECTED_BITCOIN_DA_ID" + numbers=() + for num in "${raw_numbers[@]}"; do + trimmed_num=$(echo "$num" | tr -d '[:space:]') # Remove all whitespace + numbers+=("$trimmed_num") + done + + echo "Number of elements after splitting and trimming: ${#numbers[@]}" + + # Check if there are exactly 8 numbers + if [ ${#numbers[@]} -ne 8 ]; then + echo "Error: EXPECTED_BITCOIN_DA_ID should contain exactly 8 numbers" + echo "Actual number of elements: ${#numbers[@]}" + exit 1 + fi + + # Check if all numbers are valid u32 + for i in "${!numbers[@]}"; do + num=${numbers[$i]} + echo "Checking number $((i+1)): '$num'" + echo "Hex representation: $(echo -n "$num" | xxd -p)" + if ! [[ $num =~ ^[0-9]+$ ]]; then + echo "Error: '$num' is not composed of digits only" + exit 1 + fi + if [ $num -gt 4294967295 ]; then + echo "Error: '$num' is greater than 4294967295" + exit 1 + fi + done + + # Reconstruct the trimmed DA_ID + trimmed_da_id=$(IFS=', '; echo "${numbers[*]}") + + # Final check + if [ $comma_count -eq 7 ] && [ $space_count -eq 7 ] && [ ${#numbers[@]} -eq 8 ]; then + echo "EXPECTED_BITCOIN_DA_ID is valid:" + echo "- Contains 7 commas" + echo "- Contains 7 spaces" + echo "- Contains 8 valid u32 numbers" + echo "Original value: $EXPECTED_BITCOIN_DA_ID" + echo "Trimmed value: $trimmed_da_id" + else + echo "Error: EXPECTED_BITCOIN_DA_ID format is incorrect" + echo "- Comma count: $comma_count (should be 7)" + echo "- Space count: $space_count (should be 7)" + echo "- Number count: ${#numbers[@]} (should be 8)" + exit 1 + fi + + - name: Check Binary + if: inputs.action == 'check_binary' + shell: bash + run: | + RESULT=$(grep -R "BATCH_PROVER_BITCOIN_ID" target/ || echo "Grep failed") + EXPECTED_BITCOIN_DA_ID=$(echo "${{ env.EXPECTED_BITCOIN_DA_ID }}" | tr -d '\n\r') + if echo "$RESULT" | grep -q "$EXPECTED_BITCOIN_DA_ID"; then + echo "Check passed successfully." + echo "Expected: BATCH_PROVER_BITCOIN_ID ${{ env.EXPECTED_BITCOIN_DA_ID }} " + echo "Actual: $RESULT" + + else + echo "Check failed. Expected: BATCH_PROVER_BITCOIN_ID ${{ env.EXPECTED_BITCOIN_DA_ID }} " + echo "Actual: $RESULT" + exit 1 + fi + diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index f972dd3da..41a4ce9ad 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -458,82 +458,14 @@ jobs: validate_and_check_DA_ID: runs-on: ubicloud-standard-2 needs: build - env: - EXPECTED_BITCOIN_DA_ID: ${{ vars.EXPECTED_BITCOIN_DA_ID }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - - name: Validate EXPECTED_BITCOIN_DA_ID format - run: | - echo "Raw EXPECTED_BITCOIN_DA_ID value:" - echo "$EXPECTED_BITCOIN_DA_ID" - - echo "Length of EXPECTED_BITCOIN_DA_ID: ${#EXPECTED_BITCOIN_DA_ID}" - - if [ -z "${EXPECTED_BITCOIN_DA_ID// }" ]; then - echo "Error: EXPECTED_BITCOIN_DA_ID is not set, empty, or contains only spaces" - exit 1 - fi - - # Remove any trailing newline or carriage return - EXPECTED_BITCOIN_DA_ID=$(echo "$EXPECTED_BITCOIN_DA_ID" | tr -d '\n\r') - - # Count commas and spaces - comma_count=$(echo "$EXPECTED_BITCOIN_DA_ID" | tr -cd ',' | wc -c) - space_count=$(echo "$EXPECTED_BITCOIN_DA_ID" | tr -cd ' ' | wc -c) - - echo "Number of commas: $comma_count" - echo "Number of spaces: $space_count" - - # Split the string into an array and trim each element - IFS=', ' read -ra raw_numbers <<< "$EXPECTED_BITCOIN_DA_ID" - numbers=() - for num in "${raw_numbers[@]}"; do - trimmed_num=$(echo "$num" | tr -d '[:space:]') # Remove all whitespace - numbers+=("$trimmed_num") - done - - echo "Number of elements after splitting and trimming: ${#numbers[@]}" - - # Check if there are exactly 8 numbers - if [ ${#numbers[@]} -ne 8 ]; then - echo "Error: EXPECTED_BITCOIN_DA_ID should contain exactly 8 numbers" - echo "Actual number of elements: ${#numbers[@]}" - exit 1 - fi - - # Check if all numbers are valid u32 - for i in "${!numbers[@]}"; do - num=${numbers[$i]} - echo "Checking number $((i+1)): '$num'" - echo "Hex representation: $(echo -n "$num" | xxd -p)" - if ! [[ $num =~ ^[0-9]+$ ]]; then - echo "Error: '$num' is not composed of digits only" - exit 1 - fi - if [ $num -gt 4294967295 ]; then - echo "Error: '$num' is greater than 4294967295" - exit 1 - fi - done - - # Reconstruct the trimmed DA_ID - trimmed_da_id=$(IFS=', '; echo "${numbers[*]}") + - uses: actions/checkout@v4 - # Final check - if [ $comma_count -eq 7 ] && [ $space_count -eq 7 ] && [ ${#numbers[@]} -eq 8 ]; then - echo "EXPECTED_BITCOIN_DA_ID is valid:" - echo "- Contains 7 commas" - echo "- Contains 7 spaces" - echo "- Contains 8 valid u32 numbers" - echo "Original value: $EXPECTED_BITCOIN_DA_ID" - echo "Trimmed value: $trimmed_da_id" - else - echo "Error: EXPECTED_BITCOIN_DA_ID format is incorrect" - echo "- Comma count: $comma_count (should be 7)" - echo "- Space count: $space_count (should be 7)" - echo "- Number count: ${#numbers[@]} (should be 8)" - exit 1 - fi + - name: Validate EXPECTED_BITCOIN_DA_ID format + uses: ./.github/actions/validate-bitcoin-da + with: + expected_da_id: ${{ vars.EXPECTED_BITCOIN_DA_ID }} + action: validate_format - name: Download artifact uses: actions/download-artifact@v3 @@ -543,16 +475,7 @@ jobs: - name: Check BATCH_PROVER_BITCOIN_ID id: check-id - run: | - RESULT=$(grep -R "BATCH_PROVER_BITCOIN_ID" target/ || echo "Grep failed") - EXPECTED_BITCOIN_DA_ID=$(echo "${{ env.EXPECTED_BITCOIN_DA_ID }}" | tr -d '\n\r') - if echo "$RESULT" | grep -q "$EXPECTED_BITCOIN_DA_ID"; then - echo "Check passed successfully." - echo "Expected: BATCH_PROVER_BITCOIN_ID ${{ env.EXPECTED_BITCOIN_DA_ID }} " - echo "Actual: $RESULT" - - else - echo "Check failed. Expected: BATCH_PROVER_BITCOIN_ID ${{ env.EXPECTED_BITCOIN_DA_ID }} " - echo "Actual: $RESULT" - exit 1 - fi + uses: ./.github/actions/validate-bitcoin-da + with: + expected_da_id: ${{ vars.EXPECTED_BITCOIN_DA_ID }} + action: check_binary diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6df398014..d939191a0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,87 +5,15 @@ on: tags: - "v*.*.*" -env: - EXPECTED_BITCOIN_DA_ID: ${{ vars.EXPECTED_BITCOIN_DA_ID }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - jobs: - validate_DA_ID_format: runs-on: ubuntu-latest steps: - - name: Validate EXPECTED_BITCOIN_DA_ID format - run: | - echo "Raw EXPECTED_BITCOIN_DA_ID value:" - echo "$EXPECTED_BITCOIN_DA_ID" - - echo "Length of EXPECTED_BITCOIN_DA_ID: ${#EXPECTED_BITCOIN_DA_ID}" - - if [ -z "${EXPECTED_BITCOIN_DA_ID// }" ]; then - echo "Error: EXPECTED_BITCOIN_DA_ID is not set, empty, or contains only spaces" - exit 1 - fi - - # Remove any trailing newline or carriage return - EXPECTED_BITCOIN_DA_ID=$(echo "$EXPECTED_BITCOIN_DA_ID" | tr -d '\n\r') - - # Count commas and spaces - comma_count=$(echo "$EXPECTED_BITCOIN_DA_ID" | tr -cd ',' | wc -c) - space_count=$(echo "$EXPECTED_BITCOIN_DA_ID" | tr -cd ' ' | wc -c) - - echo "Number of commas: $comma_count" - echo "Number of spaces: $space_count" - - # Split the string into an array and trim each element - IFS=', ' read -ra raw_numbers <<< "$EXPECTED_BITCOIN_DA_ID" - numbers=() - for num in "${raw_numbers[@]}"; do - trimmed_num=$(echo "$num" | tr -d '[:space:]') # Remove all whitespace - numbers+=("$trimmed_num") - done - - echo "Number of elements after splitting and trimming: ${#numbers[@]}" - - # Check if there are exactly 8 numbers - if [ ${#numbers[@]} -ne 8 ]; then - echo "Error: EXPECTED_BITCOIN_DA_ID should contain exactly 8 numbers" - echo "Actual number of elements: ${#numbers[@]}" - exit 1 - fi - - # Check if all numbers are valid u32 - for i in "${!numbers[@]}"; do - num=${numbers[$i]} - echo "Checking number $((i+1)): '$num'" - echo "Hex representation: $(echo -n "$num" | xxd -p)" - if ! [[ $num =~ ^[0-9]+$ ]]; then - echo "Error: '$num' is not composed of digits only" - exit 1 - fi - if [ $num -gt 4294967295 ]; then - echo "Error: '$num' is greater than 4294967295" - exit 1 - fi - done - - # Reconstruct the trimmed DA_ID - trimmed_da_id=$(IFS=', '; echo "${numbers[*]}") - - # Final check - if [ $comma_count -eq 7 ] && [ $space_count -eq 7 ] && [ ${#numbers[@]} -eq 8 ]; then - echo "EXPECTED_BITCOIN_DA_ID is valid:" - echo "- Contains 7 commas" - echo "- Contains 7 spaces" - echo "- Contains 8 valid u32 numbers" - echo "Original value: $EXPECTED_BITCOIN_DA_ID" - echo "Trimmed value: $trimmed_da_id" - else - echo "Error: EXPECTED_BITCOIN_DA_ID format is incorrect" - echo "- Comma count: $comma_count (should be 7)" - echo "- Space count: $space_count (should be 7)" - echo "- Number count: ${#numbers[@]} (should be 8)" - exit 1 - fi + - uses: actions/checkout@v4 + - uses: ./.github/actions/validate-bitcoin-da + with: + expected_da_id: ${{ vars.EXPECTED_BITCOIN_DA_ID }} + action: validate_format linux_amd64_binary_extraction: needs: validate_DA_ID_format @@ -127,19 +55,10 @@ jobs: - name: Check BATCH_PROVER_BITCOIN_ID id: check-id - run: | - RESULT=$(grep -R "BATCH_PROVER_BITCOIN_ID" target/ || echo "Grep failed") - EXPECTED_BITCOIN_DA_ID=$(echo "${{ env.EXPECTED_BITCOIN_DA_ID }}" | tr -d '\n\r') - if echo "$RESULT" | grep -q "$EXPECTED_BITCOIN_DA_ID"; then - echo "Check passed successfully." - echo "Expected: BATCH_PROVER_BITCOIN_ID ${{ env.EXPECTED_BITCOIN_DA_ID }} " - echo "Actual: $RESULT" - - else - echo "Check failed. Expected: BATCH_PROVER_BITCOIN_ID ${{ env.EXPECTED_BITCOIN_DA_ID }} " - echo "Actual: $RESULT" - exit 1 - fi + uses: ./.github/actions/validate-bitcoin-da + with: + expected_da_id: ${{ vars.EXPECTED_BITCOIN_DA_ID }} + action: check_binary - name: Upload linux-amd64 Binary uses: actions/upload-artifact@v4 @@ -180,19 +99,10 @@ jobs: - name: Check BATCH_PROVER_BITCOIN_ID id: check-id - run: | - RESULT=$(grep -R "BATCH_PROVER_BITCOIN_ID" target/ || echo "Grep failed") - EXPECTED_BITCOIN_DA_ID=$(echo "${{ env.EXPECTED_BITCOIN_DA_ID }}" | tr -d '\n\r') - if echo "$RESULT" | grep -q "$EXPECTED_BITCOIN_DA_ID"; then - echo "Check passed successfully." - echo "Expected: BATCH_PROVER_BITCOIN_ID ${{ env.EXPECTED_BITCOIN_DA_ID }} " - echo "Actual: $RESULT" - - else - echo "Check failed. Expected: BATCH_PROVER_BITCOIN_ID ${{ env.EXPECTED_BITCOIN_DA_ID }} " - echo "Actual: $RESULT" - exit 1 - fi + uses: ./.github/actions/validate-bitcoin-da + with: + expected_da_id: ${{ vars.EXPECTED_BITCOIN_DA_ID }} + action: check_binary - name: Upload osx-arm64 Binary uses: actions/upload-artifact@v4 @@ -233,7 +143,7 @@ jobs: name: Release ${{ github.ref_name }} body: | This is the release for version ${{ github.ref_name }}. - + It includes: - citrea-${{ github.ref_name }}-linux-amd64 - - citrea-${{ github.ref_name }}-osx-arm64 \ No newline at end of file + - citrea-${{ github.ref_name }}-osx-arm64