Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update actions #28

Merged
merged 1 commit into from
Jul 29, 2024
Merged

Update actions #28

merged 1 commit into from
Jul 29, 2024

Conversation

allthings-bot
Copy link
Member

@allthings-bot allthings-bot commented Jul 29, 2024

Update actions from workflow

Summary by CodeRabbit

  • New Features
    • Introduced a Docker build workflow to simplify the building and pushing of Docker images with customizable inputs.
    • Added a log printing workflow that enhances log visibility during CI/CD processes by structuring output for easier review.
    • Implemented a retry mechanism for script execution, improving reliability by allowing scripts to be retried in case of transient failures.
    • Launched an artifact upload action for seamless file uploads to Amazon S3 with generated access links.

Copy link

coderabbitai bot commented Jul 29, 2024

Walkthrough

This update introduces several new GitHub Actions workflows, enhancing CI/CD capabilities. The new actions include docker-build for building and pushing Docker images, print-logs for displaying log files, retry-script for executing scripts with retries upon failure, and upload-artifacts for uploading files to Amazon S3. Each action is designed to improve automation, reliability, and visibility within the development process.

Changes

File Path Change Summary
.github/actions/docker-build/action.yml Added a new GitHub Action for building and pushing Docker images, with customizable inputs for context, multiarch support, image name, and tag.
.github/actions/print-logs/action.yml Introduced a new action for printing log files from a specified directory, enhancing log visibility during CI/CD processes.
.github/actions/retry-script/action.yml Created an action to retry executing a specified script multiple times until success or maximum attempts are reached, improving workflow reliability.
.github/actions/upload-artifacts/action.yml Developed an action to upload files to an S3 bucket, allowing dynamic path construction and providing access links for uploaded files.

Sequence Diagram(s)

sequenceDiagram
    participant CI as CI/CD Pipeline
    participant DB as Docker Build Action
    participant PL as Print Logs Action
    participant RS as Retry Script Action
    participant UA as Upload Artifacts Action

    CI->>DB: Trigger Docker build
    DB->>DB: Build and push Docker image
    CI->>PL: Trigger log printing
    PL->>PL: Print logs from specified path
    CI->>RS: Trigger script execution
    RS->>RS: Execute script with retries
    CI->>UA: Trigger file upload
    UA->>UA: Upload files to S3 and print URLs
Loading

Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ffbf083 and f257964.

Files selected for processing (4)
  • .github/actions/docker-build/action.yml (1 hunks)
  • .github/actions/print-logs/action.yml (1 hunks)
  • .github/actions/retry-script/action.yml (1 hunks)
  • .github/actions/upload-artifacts/action.yml (1 hunks)
Additional comments not posted (14)
.github/actions/print-logs/action.yml (3)

1-2: LGTM!

The name and description fields are correctly defined.


3-6: LGTM!

The inputs section is correctly defined with a required input path.


8-19: LGTM!

The steps to set the PATH are correctly defined.

.github/actions/retry-script/action.yml (3)

1-2: LGTM!

The name and description fields are correctly defined.


3-9: LGTM!

The inputs section is correctly defined with required inputs script and attempts.


11-23: LGTM!

The steps to set the PATH are correctly defined.

.github/actions/docker-build/action.yml (3)

1-2: LGTM!

The name and description fields are correctly defined.


3-17: LGTM!

The inputs section is correctly defined with appropriate defaults for context and multiarch.


19-32: LGTM!

The steps to export tag name and platforms are correctly defined.

.github/actions/upload-artifacts/action.yml (5)

1-2: Metadata section looks good.

The name and description are clear and accurately reflect the action's purpose.


3-9: Inputs section looks good.

The inputs path and runner-id have clear descriptions and are correctly marked as required.


14-22: Set PATH step looks good.

The directories being added to the PATH are correctly formatted and necessary for the action.


24-31: Upload files step looks good.

The commands are correctly formatted and secure. The S3 bucket path appears to be correctly constructed.

However, verify that the S3 bucket path is correct and accessible.


33-44: Print file links step looks good.

The commands are correctly formatted and secure. The URLs appear to be correctly constructed.

However, verify that the URLs are correctly constructed and secure.

Verification successful

Print file links step looks good.

The commands are correctly formatted and secure. The URLs appear to be correctly constructed based on the simulated output.

  • URLs constructed correctly:
    • https://allthings-github-artifacts.auth.eu-west-1.amazoncognito.com/oauth2/authorize?response_type=token&client_id=7pn0enn1f29m6ghpdik78hkp33&redirect_uri=https://cksj34aqloivipgg7nsw6exyam0zogkq.lambda-url.eu-west-1.on.aws&scope=aws.cognito.signin.user.admin+openid+profile&state=file1.txt
    • https://allthings-github-artifacts.auth.eu-west-1.amazoncognito.com/oauth2/authorize?response_type=token&client_id=7pn0enn1f29m6ghpdik78hkp33&redirect_uri=https://cksj34aqloivipgg7nsw6exyam0zogkq.lambda-url.eu-west-1.on.aws&scope=aws.cognito.signin.user.admin+openid+profile&state=file2.log
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the URLs are correctly constructed and secure.

# Test: Check if the URLs are correctly constructed. Expect: The URLs should be valid.
aws-vault exec --backend=pass allthings-development-github-role --duration=12h -- aws s3 ls --region=eu-west-1 --recursive s3://agent-artifacts-eu-west-1/ | grep -Po "\d+\/.*" | sed 's/.*\///' | while read -r file; do
  echo "https://allthings-github-artifacts.auth.eu-west-1.amazoncognito.com/oauth2/authorize?response_type=token&client_id=7pn0enn1f29m6ghpdik78hkp33&redirect_uri=https://cksj34aqloivipgg7nsw6exyam0zogkq.lambda-url.eu-west-1.on.aws&scope=aws.cognito.signin.user.admin+openid+profile&state=$(echo "$file" | jq --slurp --raw-input --raw-output @uri | sed 's/%0A$//')";
done

Length of output: 286


Script:

#!/bin/bash
# Description: Verify the URLs are correctly constructed and secure by simulating the aws s3 ls output.

# Mock output of `aws s3 ls --region=eu-west-1 --recursive s3://agent-artifacts-eu-west-1/`
mock_s3_output="2024-07-29 12:00:00 12345 1234/file1.txt
2024-07-29 12:00:00 67890 5678/file2.log"

# Simulate the URL construction logic
echo "$mock_s3_output" | grep -Po "\d+\/.*" | sed 's/.*\///' | while read -r file; do
  echo "https://allthings-github-artifacts.auth.eu-west-1.amazoncognito.com/oauth2/authorize?response_type=token&client_id=7pn0enn1f29m6ghpdik78hkp33&redirect_uri=https://cksj34aqloivipgg7nsw6exyam0zogkq.lambda-url.eu-west-1.on.aws&scope=aws.cognito.signin.user.admin+openid+profile&state=$(echo "$file" | jq --slurp --raw-input --raw-output @uri | sed 's/%0A$//')";
done

Length of output: 1616


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Comment on lines +21 to +39
- name: print logs
shell: bash
working-directory: ${{ inputs.path }}
run: >
for log in ./*;
do
if [ -d ./"$log" ]; then
for logInDir in "$log"/*;
do
echo "::group::$logInDir";
/bin/cat "$logInDir";
echo "::endgroup::";
done;
else
echo "::group::$log";
/bin/cat "$log";
echo "::endgroup::";
fi;
done
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improve readability and efficiency of log printing steps.

The current logic is correct but can be improved for readability and efficiency. Consider using find to simplify the iteration over files and directories.

-  for log in ./*;
-  do
-    if [ -d ./"$log" ]; then
-      for logInDir in "$log"/*;
-      do
-        echo "::group::$logInDir";
-        /bin/cat "$logInDir";
-        echo "::endgroup::";
-      done;
-    else
-      echo "::group::$log";
-      /bin/cat "$log";
-      echo "::endgroup::";
-    fi;
-  done
+  find . -type f | while read log;
+  do
+    echo "::group::$log";
+    /bin/cat "$log";
+    echo "::endgroup::";
+  done
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: print logs
shell: bash
working-directory: ${{ inputs.path }}
run: >
for log in ./*;
do
if [ -d ./"$log" ]; then
for logInDir in "$log"/*;
do
echo "::group::$logInDir";
/bin/cat "$logInDir";
echo "::endgroup::";
done;
else
echo "::group::$log";
/bin/cat "$log";
echo "::endgroup::";
fi;
done
- name: print logs
shell: bash
working-directory: ${{ inputs.path }}
run: >
find . -type f | while read log;
do
echo "::group::$log";
/bin/cat "$log";
echo "::endgroup::";
done

Comment on lines +24 to +41
- name: retry script
shell: bash
env:
SCRIPT: ${{ inputs.script }}
MAX_ATTEMPTS: ${{ inputs.attempts }}
run: >
set +e && for i in $(seq 1 "${{ env.MAX_ATTEMPTS }}");
do
${{ env.SCRIPT }};
res="$?";
if [[ "$res" == "0" ]]; then
exit "$res";
fi;
if [[ "$i" == "${{ env.MAX_ATTEMPTS }}" ]]; then
exit "$res";
fi;
echo "::warning title=Retry::Current run $i failed of ${{ env.MAX_ATTEMPTS }} attempts";
done
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improve readability and efficiency of script retrying steps.

The current logic is correct but can be improved for readability and efficiency. Consider using a function to encapsulate the retry logic.

-  set +e && for i in $(seq 1 "${{ env.MAX_ATTEMPTS }}");
-  do
-    ${{ env.SCRIPT }};
-    res="$?";
-    if [[ "$res" == "0" ]]; then
-      exit "$res";
-    fi;
-    if [[ "$i" == "${{ env.MAX_ATTEMPTS }}" ]]; then
-      exit "$res";
-    fi;
-    echo "::warning title=Retry::Current run $i failed of ${{ env.MAX_ATTEMPTS }} attempts";
-  done
+  retry() {
+    for i in $(seq 1 "$1"); do
+      $2
+      res="$?"
+      if [[ "$res" == "0" ]]; then
+        return 0
+      fi
+      echo "::warning title=Retry::Current run $i failed of $1 attempts"
+    done
+    return "$res"
+  }
+  set +e
+  retry "${{ env.MAX_ATTEMPTS }}" "${{ env.SCRIPT }}"
+  exit "$?"
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: retry script
shell: bash
env:
SCRIPT: ${{ inputs.script }}
MAX_ATTEMPTS: ${{ inputs.attempts }}
run: >
set +e && for i in $(seq 1 "${{ env.MAX_ATTEMPTS }}");
do
${{ env.SCRIPT }};
res="$?";
if [[ "$res" == "0" ]]; then
exit "$res";
fi;
if [[ "$i" == "${{ env.MAX_ATTEMPTS }}" ]]; then
exit "$res";
fi;
echo "::warning title=Retry::Current run $i failed of ${{ env.MAX_ATTEMPTS }} attempts";
done
- name: retry script
shell: bash
env:
SCRIPT: ${{ inputs.script }}
MAX_ATTEMPTS: ${{ inputs.attempts }}
run: >
retry() {
for i in $(seq 1 "$1"); do
$2
res="$?"
if [[ "$res" == "0" ]]; then
return 0
fi
echo "::warning title=Retry::Current run $i failed of $1 attempts"
done
return "$res"
}
set +e
retry "${{ env.MAX_ATTEMPTS }}" "${{ env.SCRIPT }}"
exit "$?"

Comment on lines +33 to +42
- name: Build and push
uses: docker/build-push-action@v6
env:
PROJECT: ${{ inputs.name }}
with:
no-cache: true
push: true
tags: allthings/${{ env.PROJECT }}:${{ steps.export_tag_name_and_platforms.outputs.tag_name }}
platforms: ${{ steps.export_tag_name_and_platforms.outputs.platforms }}
context: ${{ inputs.context }}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improve readability and efficiency of Docker build and push steps.

The current logic is correct but can be improved for readability and efficiency. Consider using environment variables to simplify the inputs.

-  uses: docker/build-push-action@v6
-  env:
-    PROJECT: ${{ inputs.name }}
-  with:
-    no-cache: true
-    push: true
-    tags: allthings/${{ env.PROJECT }}:${{ steps.export_tag_name_and_platforms.outputs.tag_name }}
-    platforms: ${{ steps.export_tag_name_and_platforms.outputs.platforms }}
-    context: ${{ inputs.context }}
+  uses: docker/build-push-action@v6
+  with:
+    no-cache: true
+    push: true
+    tags: allthings/${{ inputs.name }}:${{ steps.export_tag_name_and_platforms.outputs.tag_name }}
+    platforms: ${{ steps.export_tag_name_and_platforms.outputs.platforms }}
+    context: ${{ inputs.context }}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Build and push
uses: docker/build-push-action@v6
env:
PROJECT: ${{ inputs.name }}
with:
no-cache: true
push: true
tags: allthings/${{ env.PROJECT }}:${{ steps.export_tag_name_and_platforms.outputs.tag_name }}
platforms: ${{ steps.export_tag_name_and_platforms.outputs.platforms }}
context: ${{ inputs.context }}
- name: Build and push
uses: docker/build-push-action@v6
with:
no-cache: true
push: true
tags: allthings/${{ inputs.name }}:${{ steps.export_tag_name_and_platforms.outputs.tag_name }}
platforms: ${{ steps.export_tag_name_and_platforms.outputs.platforms }}
context: ${{ inputs.context }}

@DmitryMarkov DmitryMarkov merged commit f9aa547 into master Jul 29, 2024
3 checks passed
@DmitryMarkov DmitryMarkov deleted the actions-spreader-10143493681 branch July 29, 2024 13:54
@coderabbitai coderabbitai bot mentioned this pull request Sep 25, 2024
@coderabbitai coderabbitai bot mentioned this pull request Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants