Create new Console Project#
I am going to create dotnet project to demonstrate this but applicable for all ather programming also
- Open any folder, In there Open Terminal
- In Terminal Create new dotnet console Project using below command
1
2
3
4
5
6
7
8
| dotnet new console -n GitCiCd
cd .\GitCiCd\
code .
mkdir .github
cd .\.github\
mkdir workflows
cd .\workflows\
echo "" > "dotnet.yaml"
|
- In dotnet.yaml file Paste Below Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
| name: workflows
on:
push:
branches: [ "master" ]
jobs:
scrape_videos:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: '8.0.x' # Use the latest .NET version
- name: Restore dependencies
run: dotnet restore
- name: Build the project
run: dotnet build --configuration Release
- name: Run the scraping script
run: dotnet run --project GetYoutubeVideo.csproj
- name: Commit and Push Changes
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add Text.txt
git commit -m "Update Text.txt list"
git push
|
- Inside Program.cs file paste below code for.
1
2
3
4
5
6
7
8
9
10
11
| var ls = Enumerable.Range(1,8).Select(i => i.ToString() + DateTime.Now).ToList();
SaveToFile(ls, "Text.txt");
static void SaveToFile(List<string> videos, string filePath)
{
using StreamWriter file = new(filePath);
foreach (var video in videos)
{
file.WriteLine(video);
}
}
|
- The code Responsible for operation is below code
1
2
3
4
5
6
7
| - name: Commit and Push Changes
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add Text.txt
git commit -m "Update Text.txt list"
git push
|
- Push to github
- Now Go to Repository Setting Tab
- Then Expand Action and click on General
- Now then Scroll To Bottom And Select Read and Write Permission and Tick Allow Github action to create and approve pull request
- then Ater go to action tab
- Open Any WorkFlows File and Click On Re Run XXX