Skip to content

Commit

Permalink
Merge pull request #16 from 0jonjo/15-create-a-dockerfile-to-use-dock…
Browse files Browse the repository at this point in the history
…erized-version-of-woche

15 create a dockerfile to use dockerized version of woche
  • Loading branch information
0jonjo committed May 17, 2024
2 parents bbb9e13 + d1c09b8 commit 8464a15
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 46 deletions.
11 changes: 1 addition & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
name: CI

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- uses: actions/checkout@v4

# Runs a single command using the runners shell
- name: Starting tests
run: |
echo Starting tests
Expand Down
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM bash:latest

RUN mkdir /home/root/

RUN apk add --no-cache coreutils

WORKDIR /woche

COPY . /woche
44 changes: 31 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Woche

Woche is a collection of Bash scripts that assist in managing weekly tasks. It enables the creation of a new Markdown file for the current week and the addition of tasks to specific days. Woche, meaning 'week' in German, uses German day names (Montag, Dienstag, Mittwoch, Donnerstag, Freitag, Samstag, and Sonntag) for educational purposes. You can choose between options with the names of the days in English or German.
Woche is a collection of Bash scripts that assist in managing weekly tasks. It enables the creation of a new Markdown file for the current week and the addition of tasks to specific days. Woche, meaning 'week' in German. You can choose between options with the names of the days in English or German.

## Features

Expand All @@ -10,56 +10,52 @@ Woche is a collection of Bash scripts that assist in managing weekly tasks. It e

## Usage

1. **Create a new Markdown file for the current week (starting on Monday):**
**Create a new Markdown file for the current week (starting on Monday):**

```bash
./woche.sh create
```

This command creates a file using the YYMMDD format.

2. **Add a task to a specific day:**
**Add a task to a specific day:**

```bash
./woche.sh <day> "<task>"
```

Replace <day> with the day of the week (in German: mon, die, mit, don, frei, sam, son) and <task> with the task description.
Replace <day> with the day of the week and <task> with the task description. The days in German are: mon, die, mit, don, frei, sam and son, in English: mond, tue, wed, thu, fri, sat and sun.

3. **Display the tasks of the current week:**
**Display the tasks of the current week:**

```bash
./woche.sh show
```

This command prints the Markdown file with the tasks for the entire week.

4. **Edit a task of the current week:**
**Edit a task of the current week:**

```bash
./woche.sh edit 9 "That task"
```

This command edit the line 9 of Markdown file with the tasks.

5. **Delete a task of the current week:**
**Delete a task of the current week:**

```bash
./woche.sh delete 3
```

This command edit the line 3 of Markdown file.

6. **Access instructions:**
**Access instructions:**

```bash
./woche.sh help
```

## Customization Tips
- Change the file creation path by modifying the path variable in the variables.sh file.
- Switch to English day names by replacing woche_array with week_array in the same file.
- Alter the date format of the Markdown file by adjusting the start_day_of_week method in functions.sh.

## Testing

The test.sh script tests the functionality of woche.sh, checking both correct and incorrect user inputs. This test is mandatory for pull requests to the main branch and should be included in the [GitHub Actions](https://github.com/0jonjo/woche/actions) pipeline for automated testing.
Expand All @@ -69,6 +65,28 @@ To run the tests:
```bash
./test.sh
```

## Docker

To use the dockerized version of Woche, follow these instructions:

```bash
# Build the image
docker build -t woche-app .

# Run the container
docker run -it woche-app
```

## Customization Tips

- Change the file creation path by modifying the path variable in the variables.sh file.
- Switch to German day names by replacing week_array with woche_array in the same file.
- Alter the date format of the Markdown file by adjusting the start_day_of_week method in functions.sh.
- Use dockerized version if not in Ubuntu/Debian like system operation.

---

## License

This project is licensed under the GNU License. See the [LICENSE](LICENSE) file for details.
14 changes: 6 additions & 8 deletions functions.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#!/bin/bash

#Path: functions.sh
#!/usr/bin/env bash

tips() {
echo "tips: woche.sh"
echo "create: a new markdown file for the current week"
echo "${woche_array_string[@]}: to add a task to the day of the week."
echo "${week_array_string[@]}: to add a task to the day of the week."
}

start_day_of_week() {
Expand All @@ -18,27 +16,27 @@ start_day_of_week() {

file_exists() {
if [ ! -e "$start_day.md" ]; then
echo "The file $start_day.md does not exist."
echo "Error: The file $start_day.md does not exist."
exit 1
fi
}

file_already_exists() {
if [ -e "$start_day.md" ]; then
echo "The file $start_day.md already exists."
echo "Error: The file $start_day.md already exists."
exit 1
fi
}

line_exists() {
if [ -z "$(sed -n "${task}p" "$start_day.md")" ]; then
echo "Line $task does not exist."
echo "Error: Line $task does not exist."
exit 1
fi
}

create_file() {
for i in "${woche_array[@]}"; do
for i in "${week_array[@]}"; do
printf "# %s\n\n" "$i" >> "$start_day.md"
done
echo "The file $start_day.md has been created."
Expand Down
11 changes: 5 additions & 6 deletions tests.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/bin/bash
#!/usr/bin/env bash

# Path to the woche.sh script
source $(dirname "$0")/functions.sh
source $(dirname "$0")/variables.sh
source functions.sh
source variables.sh

woche_script_path="./woche.sh"

Expand All @@ -23,7 +22,7 @@ delete_file() {
delete_file

# Test with more than 3 arguments
output=$("$woche_script_path" mon "Test task" "Argument" "Extra argument")
output=$("$woche_script_path" mont "Test task" "Argument" "Extra argument")
if [[ "$output" == *"tips: woche.sh"* ]]; then
echo "Test 'more than 3 arguments' command: PASSED"
else
Expand Down Expand Up @@ -67,7 +66,7 @@ else
fi

# Test add task to a day command
output=$("$woche_script_path" mon "Test task")
output=$("$woche_script_path" mond "Test task")
if [[ "$output" == *"Task 'Test task' added to"* ]]; then
echo "Test 'add task to a day' command: PASSED"
else
Expand Down
7 changes: 3 additions & 4 deletions variables.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/bin/bash

#Path: variables.sh
#!/usr/bin/env bash

# The path to create and edit the file
path="/home/$(whoami)/"
Expand All @@ -26,7 +24,8 @@ woche_array=($mon $die $mit $don $fre $sam $son)
week_array=($mond $tue $wed $thu $fri $sat $sun)

woche_array_string=("mon" "die" "mit" "don" "fre" "sam" "son")
week_array_string=("mond" "tue" "wed" "thu" "fri" "sat" "sun")
options=("create" "show" "help" "delete" "edit")

# Create an array that is options + woche_array name of variables as strings
options_to_check=("${options[@]}" "${woche_array_string[@]}")
options_to_check=("${options[@]}" "${week_array_string[@]}")
9 changes: 4 additions & 5 deletions woche.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/bin/bash
#!/usr/bin/env bash

# Path: woche.sh
source $(dirname "$0")/functions.sh
source $(dirname "$0")/variables.sh
source functions.sh
source variables.sh

cd "$path"

Expand All @@ -19,7 +18,7 @@ fi

# Check if $1 is in the options to check
if [[ ! " ${options_to_check[@]} " =~ " $1 " ]]; then
echo "Invalid command."
echo "Error: Invalid command."
tips
exit 1
fi
Expand Down

0 comments on commit 8464a15

Please sign in to comment.