diff --git a/.github/workflows/conditional.yml b/.github/workflows/conditional.yml new file mode 100644 index 000000000..19f035c1c --- /dev/null +++ b/.github/workflows/conditional.yml @@ -0,0 +1,14 @@ +name: conditional-example-workflow +on: [push] +jobs: + hello-world: + if: github.repository == 'chaitu092/Github-Examples' + runs-on: ubuntu-latest + steps: + - name: "Hello World" + run: echo "Hello World!" + goodbye-moon: + runs-on: ubuntu-latest + steps: + - name: "Goodbye Moon" + run: echo "Goodbye Moon!" \ No newline at end of file diff --git a/.github/workflows/context.yml b/.github/workflows/context.yml new file mode 100644 index 000000000..30fb228ef --- /dev/null +++ b/.github/workflows/context.yml @@ -0,0 +1,20 @@ +name: Context examples + +on: + push: + branches: + - main + +jobs: + my_context: + runs-on: ubuntu-latest + steps: + - name: "My step" + run: echo "Hello! $MY_ACTION" + env: + MY_ACTION: ${{ github.action }} + + - name: "My second step" + run: echo "bye! $MY_ACTION" + env: + MY_ACTION: ${{ github.action }} \ No newline at end of file diff --git a/.github/workflows/custom-action.yml b/.github/workflows/custom-action.yml deleted file mode 100644 index 7a87b53f1..000000000 --- a/.github/workflows/custom-action.yml +++ /dev/null @@ -1,15 +0,0 @@ -on: [push] - -jobs: - my-job: - runs-on: ubuntu-latest - name: A job to say hello - steps: - - name: Hello world action step - id: hello - uses: omenking/barsoom@0.0.6 - with: - name: 'Brown' - # Use the output from the `hello` step - - name: Get the Output - run: echo "The time was ${{ steps.hello.outputs.greeting }}" \ No newline at end of file diff --git a/.github/workflows/expression-functions.yml b/.github/workflows/expression-functions.yml new file mode 100644 index 000000000..ad80f01df --- /dev/null +++ b/.github/workflows/expression-functions.yml @@ -0,0 +1,34 @@ +name: Expression Functions Demo + +on: + push: + branches: + - main + +jobs: + expression-functions: + runs-on: ubuntu-latest + steps: + - name: Check if string contains substring + if: contains('Hello world', 'llo') + run: echo "The string contains the substring." + - name: Check if string starts with + if: startsWith('Hello world', 'He') + run: echo "The string starts with 'He'." + - name: Check if string ends with + if: endsWith('Hello world', 'ld') + run: echo "The string ends with 'ld'." + - name: Format and echo string + run: echo ${{ format('Hello {0} {1} {2}', 'Mona', 'the', 'Octocat') }} + - name: Convert job context to JSON + run: "echo \"Job context in JSON: ${{ toJSON(github.job) }}\"" + - name: Parse JSON string + run: "echo \"Parsed JSON: ${{ fromJSON('{\"hello\":\"world\"}').hello }}\"" + - name: Hash files + run: "echo \"Hash of files: ${{ hashFiles('**/package-lock.json', '**/Gemfile.lock') }}\"" + - name: The job has succeeded + if: ${{ success() }} + run: echo "SUCCESS!" + - name: The job has failed + if: ${{ failure() }} + run: echo "Failure!" \ No newline at end of file diff --git a/.github/workflows/jobs-withoutdepends.yml b/.github/workflows/jobs-withoutdepends.yml new file mode 100644 index 000000000..8d96bcf1f --- /dev/null +++ b/.github/workflows/jobs-withoutdepends.yml @@ -0,0 +1,19 @@ +name: Jobs without depends + +on: + push: + branches: + - main + +jobs: + job2: + runs-on: ubuntu-latest + steps: + - name: stepA + run: echo "Chaitu" + + job1: + runs-on: ubuntu-latest + steps: + - name: stepB + run: echo "Hi" \ No newline at end of file diff --git a/.github/workflows/jobs.yml b/.github/workflows/jobs.yml new file mode 100644 index 000000000..ef0651de2 --- /dev/null +++ b/.github/workflows/jobs.yml @@ -0,0 +1,19 @@ +name: Jobsssss + +on: + push: + branches: + - main + +jobs: + job2: + runs-on: ubuntu-latest + needs: job1 + steps: + - name: stepA + run: echo "Saiii" + job1: + runs-on: ubuntu-latest + steps: + - name: stepB + run: echo "Hello" \ No newline at end of file diff --git a/.github/workflows/manual.yml b/.github/workflows/manual.yml new file mode 100644 index 000000000..081adf3a6 --- /dev/null +++ b/.github/workflows/manual.yml @@ -0,0 +1,32 @@ +name: Manual Trigger with Params + +on: + workflow_dispatch: + inputs: + name: + description: 'Name of the person to greet' + required: true + type: string + greeting: + description: 'Type of greeting' + required: true + type: string + data: + description: 'Base64 encoded content of a file' + required: false + type: string + +jobs: + greet: + runs-on: ubuntu-latest + steps: + - name: Decode File Content + run: | + echo "${{ inputs.data }}" | base64 --decode > ./decoded_file.txt + - name: Display Greeting + run: | + echo "${{ inputs.greeting }}, ${{ inputs.name }}!" + - name: Display File Content + run: | + echo "Contents of the file:" + cat ./decoded_file.txt \ No newline at end of file diff --git a/github-actions/templates/multi-event.yml b/.github/workflows/multi-event.yml similarity index 95% rename from github-actions/templates/multi-event.yml rename to .github/workflows/multi-event.yml index a3275be38..2e9fb1374 100644 --- a/github-actions/templates/multi-event.yml +++ b/.github/workflows/multi-event.yml @@ -1,3 +1,4 @@ +name: multi-event on: push: branches: diff --git a/.github/workflows/runner-macos.yml b/.github/workflows/runner-macos.yml new file mode 100644 index 000000000..6baa5adf6 --- /dev/null +++ b/.github/workflows/runner-macos.yml @@ -0,0 +1,30 @@ +name: macOS Workflow Example + +on: + push: + branches: + - main + +jobs: + build-and-test: + runs-on: macos-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Create Swift File + run: | + echo 'print("Hello from Swift on macOS")' > hello.swift + + - name: Install dependencies + run: | + brew install swiftlint + + - name: Run SwiftLint + run: swiftlint + + - name: Compile and run Swift program + run: | + swiftc hello.swift + ./hello \ No newline at end of file diff --git a/.github/workflows/runner-self-hosted.yml b/.github/workflows/runner-self-hosted.yml new file mode 100644 index 000000000..23bb12e71 --- /dev/null +++ b/.github/workflows/runner-self-hosted.yml @@ -0,0 +1,17 @@ +# If you don't create a self-hosted runner you will see: +# Waiting for a runner to pick up this job... +name: Self-hosted Runner Workflow + +on: + push: + branches: + - main + +jobs: + example-job: + runs-on: self-hosted + steps: + - name: Check out repository + uses: actions/checkout@v3 + - name: Run a one-line script + run: echo "Hello from a self-hosted runner!" \ No newline at end of file diff --git a/.github/workflows/runner-windows.yml b/.github/workflows/runner-windows.yml new file mode 100644 index 000000000..3b73f2b2e --- /dev/null +++ b/.github/workflows/runner-windows.yml @@ -0,0 +1,38 @@ +name: Windows Workflow Example + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build-and-test: + runs-on: windows-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Install dependencies + run: choco install dotnetcore-sdk + shell: powershell + + - name: Compile and run C# program + run: | + Add-Content -Path "Hello.cs" -Value @" + using System; + public class Hello + { + public static void Main() + { + Console.WriteLine("Hello, Windows from C#"); + } + } + "@ + dotnet new console --force --no-restore + Move-Item -Path "Hello.cs" -Destination "Program.cs" -Force + dotnet run + shell: powershell \ No newline at end of file diff --git a/github-actions/templates/schedule.yml b/.github/workflows/schedule.yml similarity index 76% rename from github-actions/templates/schedule.yml rename to .github/workflows/schedule.yml index a88231de6..483fc32da 100644 --- a/github-actions/templates/schedule.yml +++ b/.github/workflows/schedule.yml @@ -1,6 +1,7 @@ +name: scheduled events on: schedule: - - cron: '*/5 * * * *' + - cron: '*/1 * * * *' jobs: hello_world: diff --git a/.github/workflows/webhook.yml b/.github/workflows/webhook.yml new file mode 100644 index 000000000..bbf34b782 --- /dev/null +++ b/.github/workflows/webhook.yml @@ -0,0 +1,15 @@ +name: Webhook Event example + +on: + repository_dispatch: + types: + - webhook + +jobs: + respond-to-dispatch: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v2 + - name: "Run a script" + run: 'echo "Event of type: $GITHUB_EVENT_NAME"' diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml new file mode 100644 index 000000000..830e5dc0e --- /dev/null +++ b/.github/workflows/workflow.yml @@ -0,0 +1,26 @@ +name: Worflow Commands + +on: + push: + branches: + - main +jobs: + my-job: + runs-on: ubuntu-latest + steps: + - name: "group logging" + run: | + echo "::group:: My Group Message" + echo "Msg 1" + echo "Msg 2" + echo "::endgroup::" + + - name: "step 1" + run: | + echo "MY_VAL = hello" >> $GITHUB_ENV + + - name: "step 2" + run: | + echo $MY_VAL + + \ No newline at end of file