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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/actions/docker-build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: docker-build
description: 'Setup up docker and login'
inputs:
context:
description: 'Folder path where Dockerfile is located'
required: false
default: './'
multiarch:
description: 'Decides if arm build is required'
required: false
default: 'false'
name:
description: 'Image name'
required: true
tag:
description: 'Image tag'
required: true

runs:
using: "composite"
steps:
- name: export tag name
id: export_tag_name_and_platforms
shell: bash
env:
BUILD_NUMBER: ${{ github.run_id }}
MULTIARCH: ${{ inputs.multiarch }}
TAG_NAME: ${{ inputs.tag }}
run: |
echo "tag_name=$(echo "${{ env.TAG_NAME }}")" >> $GITHUB_OUTPUT
echo "platforms=$(if [ "${{ env.MULTIARCH }}" != "true" ]; then echo "linux/amd64"; else echo "linux/arm64,linux/amd64"; fi)" >> $GITHUB_OUTPUT

- 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 }}
Comment on lines +33 to +42
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 }}

39 changes: 39 additions & 0 deletions .github/actions/print-logs/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: print-logs
description: 'Prints logs by given path'
inputs:
path:
description: 'Location of logs'
required: true

runs:
using: "composite"
steps:
- name: Set PATH
shell: bash
run: |
echo "/bin" >> $GITHUB_PATH
echo "/sbin" >> $GITHUB_PATH
echo "/usr/bin" >> $GITHUB_PATH
echo "/usr/sbin" >> $GITHUB_PATH
echo "/usr/local/bin" >> $GITHUB_PATH
echo "/usr/local/sbin" >> $GITHUB_PATH

- 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
Comment on lines +21 to +39
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

41 changes: 41 additions & 0 deletions .github/actions/retry-script/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: retry-script
description: 'Retries provided script'
inputs:
script:
description: 'Location of file'
required: true
attempts:
description: 'Attempt until failure'
required: true

runs:
using: "composite"
steps:
- name: Set PATH
shell: bash
run: |
echo "/bin" >> $GITHUB_PATH
echo "/sbin" >> $GITHUB_PATH
echo "/usr/bin" >> $GITHUB_PATH
echo "/usr/sbin" >> $GITHUB_PATH
echo "/usr/local/bin" >> $GITHUB_PATH
echo "/usr/local/sbin" >> $GITHUB_PATH

- 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
Comment on lines +24 to +41
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 "$?"

44 changes: 44 additions & 0 deletions .github/actions/upload-artifacts/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: upload-artifacts
description: 'Uploads files to s3'
inputs:
path:
description: 'Location of files'
required: true
runner-id:
description: 'Id of runner as an identifier'
required: true

runs:
using: "composite"
steps:
- name: Set PATH
shell: bash
run: |
echo "/bin" >> $GITHUB_PATH
echo "/sbin" >> $GITHUB_PATH
echo "/usr/bin" >> $GITHUB_PATH
echo "/usr/sbin" >> $GITHUB_PATH
echo "/usr/local/bin" >> $GITHUB_PATH
echo "/usr/local/sbin" >> $GITHUB_PATH

- name: upload files
shell: bash
working-directory: ${{ inputs.path }}
env:
RUNNER_BUCKET: s3://agent-artifacts-eu-west-1/${{ github.run_id }}/runner-${{ inputs.runner-id }}-${{ github.run_attempt }}
run: >
aws-vault exec --backend=pass allthings-development-github-role --duration=12h --
aws s3 cp --region=eu-west-1 --recursive "./" "${{ env.RUNNER_BUCKET }}" --acl bucket-owner-full-control

- name: print file links
shell: bash
working-directory: ${{ inputs.path }}
env:
RUNNER_BUCKET: s3://agent-artifacts-eu-west-1/${{ github.run_id }}/runner-${{ inputs.runner-id }}-${{ github.run_attempt }}
run: >
while IFS= read -r runnerFile;
do
filePath=$(echo "$runnerFile" | grep -Po "\d+\/.*"); fileName=$(echo "$filePath" | sed 's/.*\///');
echo "$fileName";
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 "$filePath" | jq --slurp --raw-input --raw-output @uri | sed 's/%0A$//')";
done <<< "$(aws-vault exec --backend=pass allthings-development-github-role --duration=12h -- aws s3 ls --region=eu-west-1 --recursive "${{ env.RUNNER_BUCKET }}")"