feat: add demo workflows
All checks were successful
Caching Primes / build (push) Successful in 9s
/ ls (push) Successful in 4s

This commit is contained in:
kiper220 2025-02-07 22:48:39 +04:00
parent 5fd75b2221
commit a5430fb5fb
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: 072C9617CC7CD104
4 changed files with 112 additions and 0 deletions

View file

@ -0,0 +1,18 @@
name: Caching Primes
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cache Primes
id: cache-primes
uses: actions/cache@v4
with:
path: prime-numbers
key: ${{ runner.os }}-primes
- name: Generate Prime Numbers
if: steps.cache-primes.outputs.cache-hit != 'true'
run: ./generate-primes.sh -d prime-numbers
- name: Use Prime Numbers
run: ./primes.sh -d prime-numbers

View file

@ -0,0 +1,8 @@
on: [push]
jobs:
ls:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
ls ${{ github.workspace }}

52
generate-primes.sh Executable file
View file

@ -0,0 +1,52 @@
#!/bin/bash
# Function to check if a number is prime
is_prime() {
local num=$1
if [ $num -lt 2 ]; then
return 1
fi
for (( i=2; i*i<=num; i++ )); do
if [ $((num % i)) -eq 0 ]; then
return 1
fi
done
return 0
}
# Handling arguments
generate_primes() {
local count=0
local num=2
while [ $count -lt 1000 ]; do
if is_prime $num; then
echo -n "$num "
count=$((count + 1))
fi
num=$((num + 1))
done
echo
}
# Обработка аргументов
while getopts "d:" opt; do
case $opt in
d)
file_name=$OPTARG
;;
*)
echo "Usage: $0 -d <file_name>"
exit 1
;;
esac
done
if [ -z "$file_name" ]; then
echo "No file name specified. Usage: $0 -d <file_name>"
exit 1
fi
# Generate prime numbers and write to file
generate_primes > "$file_name"
echo "Prime numbers successfully written to file $file_name"

34
primes.sh Executable file
View file

@ -0,0 +1,34 @@
#!/bin/bash
# Handling arguments
while getopts "d:" opt; do
case $opt in
d)
file_name=$OPTARG
;;
*)
echo "Usage: $0 -d <file_name>"
exit 1
;;
esac
done
if [ -z "$file_name" ] || [ ! -f "$file_name" ]; then
echo "File not found or not specified. Usage: $0 -d <file_name>"
exit 1
fi
# Reading a file and converting its contents into an array
mapfile -t numbers < <(tr ' ' '\n' < "$file_name")
# Number of elements
count=${#numbers[@]}
echo "Number of elements: $count"
# First 10 elements
first_ten=("${numbers[@]:0:10}")
echo "First 10 elements: ${first_ten[*]/,/, }"
# Last 10 elements
last_ten=("${numbers[@]: -10}")
echo "Last 10 elements: ${last_ten[*]/,/, }"