diff --git a/.github/workflows/conditional.yml b/.github/workflows/conditional.yml new file mode 100644 index 000000000..a702cd8c5 --- /dev/null +++ b/.github/workflows/conditional.yml @@ -0,0 +1,14 @@ +name: example-workflow +on: [push] +jobs: + hello-world: + if: github.repository == 'octo-org/octo-repo-prod' + 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/expression-functions.yml b/.github/workflows/expression-functions.yml new file mode 100644 index 000000000..fedef1bf6 --- /dev/null +++ b/.github/workflows/expression-functions.yml @@ -0,0 +1,52 @@ +name: Expression Functions Demo + +on: + push: + branches: + - main + issues: + types: [opened, labeled] + +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 "Hello Mona the Octocat" + + - name: Join issue labels + if: github.event_name == 'issues' + run: | + echo "Issue labels: ${{ join(github.event.issue.labels.*.name, ', ') }}" + + - name: Convert job context to JSON + run: | + echo "Job context in JSON: ${{ toJSON(github.job) }}" + + - name: Parse JSON string + run: | + echo "Parsed JSON: world" + + - name: Hash files + run: | + echo "Hash of files: ${{ hashFiles('**/package-lock.json', '**/Gemfile.lock') }}" + + - name: The job has succeeded + if: success() + run: echo "Job succeeded" + + - name: The job has failed + if: failure() + run: echo "Job failed" \ No newline at end of file diff --git a/.github/workflows/greetings.yml b/.github/workflows/greetings.yml new file mode 100644 index 000000000..46774343e --- /dev/null +++ b/.github/workflows/greetings.yml @@ -0,0 +1,16 @@ +name: Greetings + +on: [pull_request_target, issues] + +jobs: + greeting: + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + steps: + - uses: actions/first-interaction@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + issue-message: "Message that will be displayed on users' first issue" + pr-message: "Message that will be displayed on users' first pull request" 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/workflows/multi-event.yaml b/.github/workflows/multi-event.yaml new file mode 100644 index 000000000..13c93a44a --- /dev/null +++ b/.github/workflows/multi-event.yaml @@ -0,0 +1,19 @@ +name: CI + +on: + push: + branches: + - main + - dev + pull_request: + branches: + - main + +jobs: + hello_world: + runs-on: ubuntu-latest + steps: + - name: Echo Basic Information + run: | + echo "Ref: $GITHUB_REF" + echo "Job id: $GITHUB_JOB" diff --git a/.github/workflows/runner-macos.yml b/.github/workflows/runner-macos.yml new file mode 100644 index 000000000..9863ad486 --- /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-windows.yml b/.github/workflows/runner-windows.yml new file mode 100644 index 000000000..389ccefe2 --- /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/workflows/schedule.yaml b/.github/workflows/schedule.yaml new file mode 100644 index 000000000..700fed02b --- /dev/null +++ b/.github/workflows/schedule.yaml @@ -0,0 +1,12 @@ +name: Scheduled Job + +on: + schedule: + - cron: '*/1 * * * *' # every 1 minute + +jobs: + hello_world: + runs-on: ubuntu-latest + steps: + - name: Echo current time + run: echo "The current server time is $(date)" diff --git a/.github/workflows/webhook.yml b/.github/workflows/webhook.yml new file mode 100644 index 000000000..87393485c --- /dev/null +++ b/.github/workflows/webhook.yml @@ -0,0 +1,13 @@ +name: "Webhook Event example" + +on: + repository_dispatch: + types: + - webhook + +jobs: + respond-to-dispatch: + runs-on: ubuntu-latest + steps: + - name: Run a script + run: 'echo "Event of type: $GITHUB_EVENT_NAME"' diff --git a/github-actions/Readme.me b/github-actions/Readme.me index 9be613aad..babc94238 100644 --- a/github-actions/Readme.me +++ b/github-actions/Readme.me @@ -10,7 +10,11 @@ echo '{"name":"mona", "greeting":"hello"}' | gh workflow run greet.yml --json ```sh curl -X POST \ -H "Accept: application/vnd.github+json" \ --H "Authorization: token {PAT} \ +-H "Authorization: token {gh +p_Yb21g6bpDT9gQmuOVNMZoZBnxfXsFj4fxwMI} \ -d '{"event_type": "webhook", "client_payload": {"key": "value"} }' \ -https://api.github.com/repos/{owner}/{repo}/dispatches -``` \ No newline at end of file +https://github.com/repos/george00-byte/Github-Examples/dispatches +``` + + +https://api.github.com/repos/{owner}/{repo}/dispatches \ No newline at end of file diff --git a/github-actions/manual.yml b/github-actions/manual.yml new file mode 100644 index 000000000..081adf3a6 --- /dev/null +++ b/github-actions/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/mydata.json b/github-actions/mydata.json new file mode 100644 index 000000000..b895666bf --- /dev/null +++ b/github-actions/mydata.json @@ -0,0 +1 @@ +SGVsbG8gbWFycw== \ No newline at end of file diff --git a/github-actions/templates/webhook.yml b/github-actions/templates/webhook.yml index dbdf1e47d..8d112e1aa 100644 --- a/github-actions/templates/webhook.yml +++ b/github-actions/templates/webhook.yml @@ -2,14 +2,14 @@ name: "Webhook Event example" on: repository_dispatch: - types: - - webhook + types: [webhook] jobs: respond-to-dispatch: runs-on: ubuntu-latest steps: - - name Checkout repo - uses: actions/checkout@v2 + - name: Checkout repo + uses: actions/checkout@v3 + - name: Run a script - run: echo "Event of type: $GITHUB_EVENT_NAME" + run: echo "Event of type: ${{ github.event_name }}" \ No newline at end of file