Skip to content

Commit

Permalink
ci: Add trigger on push event with path filter (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
tungbq authored Apr 28, 2024
1 parent 6e225ab commit 436b925
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 12 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/generate_content.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
name: Update Content

on:
## Trigger on merge event to main brnach
push:
branches: main
paths:
- 'generate_content.sh'
- 'repository_list.txt*'
- '.github/workflows/*'
## Manual trigger
workflow_dispatch:
## Optional: Schedule trigger to update the content regularly
# schedule:
# - cron: '0 0 * * 6' # Run every Saturday at midnight
workflow_dispatch:

jobs:
update-content:
Expand Down Expand Up @@ -35,4 +44,4 @@ jobs:
- Auto-generated by [create-pull-request][1]
[1]: https://github.com/peter-evans/create-pull-request
labels: 'update, automated-pr'
labels: 'update, automated-pr'
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h1 align="center">Repositories Landscape πŸ’Ž</h1>
<p align="center">Welcome to my repositories landscape πŸ‘‹</p>

If you want to create your own repository landscape similar to this, please follow this [**guide**](./create-your-own-repo-landscape.md) πŸ“–
If you want to create your own repository landscape similar to this, please follow this [**guide**](./create-repo-landscape.md) πŸ“–

## 1. devops-basics
- URL: <a href="https://github.com/tungbq/devops-basics">tungbq/devops-basics</a>
Expand Down
Binary file removed assets/add-new-env.png
Binary file not shown.
25 changes: 18 additions & 7 deletions create-your-own-repo-landscape.md β†’ create-repo-landscape.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ Now check the README.md and you would find your repository landscape content
## Configure and use the template πŸ“˜

Below are the steps to help you create and configure your own landscape repository.
<br>
In short we only need to do 4 major steps: `Create new repo from template` > `Set up PAT` > `Update repository list` > `Merge the automated PR`.
<br>
Let's dive into the detailed as below:

### 1. Create a new repo from the template

Expand Down Expand Up @@ -114,16 +118,22 @@ tungbq/awesome-workflow

### 4. Trigger the CI pipeline

- Go to Actions and select `Update content`.
- Select "Run workflow" to trigger the CI:

![action-run](./assets/action-run.png)
#### Automatically trigger on merge event to main

- The CI pipeline will read the repository list and generate your new readme content.
- Then it checks and creates a Pull Request to propose the new repository landscape content.
- Once the `repository_list.txt` is merged into the `main` branch, the CI pipeline Update content will be triggered automatically.
- The CI pipeline will read the repository list and generate your new `README.md` content.
- Then, it will check and create a Pull Request to propose the new repository landscape content.

![pr-automated](./assets/pr-automated.png)

#### Manual trigger (Optional)

- You can also trigger that CI at any moment you want.
- Go to Actions and select Update content.
- Select "Run workflow" to trigger the CI:

![action-run](./assets/action-run.png)

### 5. Review and merge the PR

Once the PR is raised automatically, you just need to review and merge, and that's it! You will have your own landscape content in README.md.
Expand All @@ -134,14 +144,15 @@ Congratulations πŸŽ‰, you've successfully created your own repo landscape! Now c

## Advance CI configuration (Optional)

- In the previous section, we triggered the CI pipeline to run on a manual event. You could improve that by changing the trigger event to run on a timer basis. For example, once a week or once a month. This would help us regularly check and update the landscape, keeping it up to date.
- In the previous section, we triggered the CI pipeline to run on a merge event to `main` branch or manual event. You could improve that by changing the trigger event to run on a timer basis. For example, once a week or once a month. This would help us regularly check and update the landscape, keeping it up to date.
- To do so, add your desired cron trigger to `repos/.github/workflows/generate_content.yaml`

```yaml
on:
schedule:
- cron: '0 0 * * 6' # Run every Saturday at midnight
workflow_dispatch:
# other events as needed
```

- Check https://crontab.guru/ for the CRON syntax
12 changes: 10 additions & 2 deletions generate_content.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#!/bin/bash

REPOSITORY_LIST=$1

if [ -z $REPOSITORY_LIST ]; then
echo "ERROR: epository list is empty!"
echo "Usage: $0 <repository_list_path>"
exit 1
fi

# Function to generate table rows
generate_repo_list() {
local index="$1"
Expand All @@ -22,7 +30,7 @@ generate_repo_list() {
echo "<h1 align=\"center\">Repositories Landscape πŸ’Ž</h1>" >README.md
echo "<p align=\"center\">Welcome to my repositories landscape πŸ‘‹</p>" >>README.md
echo "" >>README.md
echo "If you want to create your own repository landscape similar to this, please follow this [**guide**](./create-your-own-repo-landscape.md) πŸ“–" >>README.md
echo "If you want to create your own repository landscape similar to this, please follow this [**guide**](./create-repo-landscape.md) πŸ“–" >>README.md
## Seperator to create following list
echo "" >>README.md

Expand All @@ -45,7 +53,7 @@ while IFS= read -r repo_name; do

# Increment index
((index++))
done <"$1"
done <"$REPOSITORY_LIST"

echo "" >>README.md
echo "For full list of repositories, click [**here**](https://github.com/tungbq?tab=repositories&q=&type=&language=&sort=stargazers)." >>README.md

0 comments on commit 436b925

Please sign in to comment.