diff --git a/.github/workflows/conditional.yml b/.github/workflows/conditional.yml new file mode 100644 index 00000000..69b760d6 --- /dev/null +++ b/.github/workflows/conditional.yml @@ -0,0 +1,14 @@ +name: example-workflow +on: [push] +jobs: + hello-world: + if: github.repository == 'Bhodgkinson94/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 00000000..89b42b5b --- /dev/null +++ b/.github/workflows/context.yml @@ -0,0 +1,15 @@ +name: Context Examples + +on: [push] + +jobs: + my-context: + runs-on: ubuntu-latest + steps: + - name: My Step + run: | + echo "Action! $MY_ACTION" + echo "Actor! $MY_ACTOR" + env: + MY_ACTION: '${{ github.action }}' + MY_ACTOR: '${{ github.actor }}' \ No newline at end of file diff --git a/.github/workflows/custom-action.yml b/.github/workflows/custom-action.yml index 7a87b53f..0d509638 100644 --- a/.github/workflows/custom-action.yml +++ b/.github/workflows/custom-action.yml @@ -1,3 +1,5 @@ +name: "Custom Action" + on: [push] jobs: diff --git a/.github/workflows/dependent-jobs.yml b/.github/workflows/dependent-jobs.yml new file mode 100644 index 00000000..6c6a1752 --- /dev/null +++ b/.github/workflows/dependent-jobs.yml @@ -0,0 +1,31 @@ +name: Build, Test, and Deploy Workflow + +on: + push: + branches: + - main + +jobs: + deploy: + needs: [build, test] + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Deploy application + run: echo "Deploying to production..." + build: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Build application + run: echo "Building the application..." + test: + needs: build + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Test application + run: echo "Running tests..." \ 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 00000000..10aa80ce --- /dev/null +++ b/.github/workflows/expression-functions.yml @@ -0,0 +1,39 @@ +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 ${{ format('Hello {0} {1} {2}', '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: ${{ 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.yml b/.github/workflows/jobs.yml new file mode 100644 index 00000000..94fb0950 --- /dev/null +++ b/.github/workflows/jobs.yml @@ -0,0 +1,16 @@ +name: "Dep Jobs Example" + +on: ['push'] + +jobs: + job2: + runs-on: ubuntu-latest + needs: job1 + steps: + - name: StepA + run: echo "World" + 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 00000000..081adf3a --- /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.yml b/.github/workflows/multi-event.yml new file mode 100644 index 00000000..c9feeac1 --- /dev/null +++ b/.github/workflows/multi-event.yml @@ -0,0 +1,21 @@ +name: "Multi Event" + +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" + echo "Action: $GITHUB_ACTION" + echo "Actor: $GITHUB_ACTOR" \ No newline at end of file diff --git a/.github/workflows/runner-macos.yml b/.github/workflows/runner-macos.yml new file mode 100644 index 00000000..6baa5adf --- /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 00000000..68330be2 --- /dev/null +++ b/.github/workflows/runner-windows.yml @@ -0,0 +1,35 @@ +name: Windows Workflow Example + +on: + push: + 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/webhook.yml b/.github/workflows/webhook.yml new file mode 100644 index 00000000..f1483c6b --- /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: Run a script + run: 'echo "Event of type: $GITHUB_EVENT_NAME"' + diff --git a/.github/workflows/workflow-commands.yml b/.github/workflows/workflow-commands.yml new file mode 100644 index 00000000..dc1141e3 --- /dev/null +++ b/.github/workflows/workflow-commands.yml @@ -0,0 +1,18 @@ +name: "workflow Commands" +on: ['push'] +jobs: + my-job: + runs-on: ubuntu-latest + steps: + - name: "Group Logging" + run: + echo "::group::My Group Message" + echo "Msg 1" + echo "Msg 2" + echo "::engroup::" + - name: "step 1" + run: + echo "MY_VAL=hello" >> $GITHUB_ENV + - name: "step 2" + run: + echo $MY_VAL \ No newline at end of file