├── .github └── workflows │ ├── 01-hello-world.yml │ ├── 02-event-triggers.yml │ ├── 03-actions.yml │ ├── 04-environment-variables.yml │ ├── 05-parallel-jobs.yml │ ├── 06-job-ordering.yml │ ├── 07-job-matrix.yml │ ├── 08-outputs.yml │ ├── 09-context-variables.yml │ ├── 10-context-expressions.yml │ ├── 11-tmate.yml │ ├── 12-postgres-example.yml │ └── 13-get-secret-value.yml ├── 01-hello-world └── .gitkeep ├── 02-event-triggers └── .gitkeep ├── 03-actions └── helloWorld.js ├── 04-environment-variables └── .gitkeep ├── 05-parallel-jobs └── .gitkeep ├── 06-job-ordering └── .gitkeep ├── 07-job-matrix ├── .gitignore ├── Dockerfile ├── README.md ├── index.js ├── package-lock.json ├── package.json ├── tests │ └── First.test.js └── workflows │ ├── self-hosted-containers-wf.yml │ ├── self-hosted-labels-tmate-container-wf.yml │ ├── self-hosted-labels-tmate-wf.yml │ ├── self-hosted-labels-wf.yml │ └── self-hosted-wf.yml ├── 08-outputs └── .gitkeep ├── 09-context-variables └── workRequiringASecret.sh ├── 10-context-expressions └── .gitkeep ├── 11-tmate ├── .gitignore ├── index.js ├── package-lock.json ├── package.json └── tests │ └── First.test.js ├── 12-postgres └── .gitkeep ├── 13-get-secret └── .gitkeep ├── LICENSE ├── README.md ├── README_SELFHOSTED_RUNNERS.md └── images ├── add_runner.png ├── delete_runner.png ├── fork.png └── tmate.png /.github/workflows/01-hello-world.yml: -------------------------------------------------------------------------------- 1 | name: hello-world-example 2 | on: 3 | push: 4 | paths: 5 | - '.github/workflows/01-hello-world.yml' 6 | jobs: 7 | say-hello: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v3 11 | 12 | - name: Print current path 13 | working-directory: ./01-hello-world 14 | run: pwd 15 | 16 | - name: Say Hello 17 | run: echo "Hello world!" 18 | 19 | - name: Do stuff 20 | run: | 21 | echo "Step 1..." 22 | echo "Step 2..." 23 | echo "Step 3..." 24 | echo "Step 4..." 25 | 26 | - name: Say Goodbye 27 | run: echo "Goodbye!" -------------------------------------------------------------------------------- /.github/workflows/02-event-triggers.yml: -------------------------------------------------------------------------------- 1 | name: event-triggers-example 2 | on: 3 | push: 4 | branches: 5 | - '02-develop' 6 | - '02-foo/*' 7 | - '02-foo/**' 8 | - '!02-foo/*/456' 9 | tags: 10 | - '*' 11 | paths: 12 | - '.github/workflows/02-event-triggers.yml' 13 | pull_request: 14 | branches: 15 | - '02-develop' 16 | paths: 17 | - '.github/workflows/02-event-triggers.yml' 18 | schedule: 19 | - cron: '*/45 9-12 * * 1,4' 20 | jobs: 21 | say-hello: 22 | runs-on: ubuntu-latest 23 | steps: 24 | - uses: actions/checkout@v3 25 | 26 | - name: Print current path 27 | working-directory: ./02-event-triggers 28 | run: pwd 29 | 30 | - name: Event 31 | run: echo "Triggered by $GITHUB_EVENT_NAME" 32 | 33 | - name: Say Hello 34 | run: echo "Hello world!" -------------------------------------------------------------------------------- /.github/workflows/03-actions.yml: -------------------------------------------------------------------------------- 1 | name: actions-example 2 | on: 3 | push: 4 | paths: 5 | - '03-actions/**.js' 6 | - '.github/workflows/03-actions.yml' 7 | jobs: 8 | use-actions: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v3 12 | - uses: actions/setup-node@v3 13 | with: 14 | node-version: '15.8.0' 15 | - 16 | name: Install repo dependencies 17 | working-directory: ./03-actions 18 | run: npm install 19 | - 20 | name: Run script from repo 21 | working-directory: ./03-actions 22 | run: node helloWorld.js -------------------------------------------------------------------------------- /.github/workflows/04-environment-variables.yml: -------------------------------------------------------------------------------- 1 | name: env-vars-example 2 | on: 3 | push: 4 | paths: 5 | - '.github/workflows/04-environment-variables.yml' 6 | env: 7 | VENI: 'I came' 8 | jobs: 9 | use-env-vars: 10 | runs-on: ubuntu-latest 11 | env: 12 | VIDI: 'I saw' 13 | steps: 14 | - uses: actions/checkout@v3 15 | 16 | - name: Print current path 17 | working-directory: ./04-environment-variables 18 | run: pwd 19 | 20 | - name: Show me the vars 21 | run: echo "$VENI, $VIDI, $VICI" 22 | env: 23 | VICI: 'I conquered' 24 | 25 | - name: Create env var 26 | run: echo "foo=bar" >> $GITHUB_ENV 27 | 28 | - name: Useful default vars 29 | run: | 30 | echo "Workflow name: $GITHUB_WORKFLOW" 31 | echo "Workspace: $GITHUB_WORKSPACE" 32 | echo "Event: $GITHUB_EVENT_NAME" 33 | echo "SHA: $GITHUB_SHA" 34 | echo "Ref: $GITHUB_REF" 35 | 36 | - name: Show env variables list 37 | run: env -------------------------------------------------------------------------------- /.github/workflows/05-parallel-jobs.yml: -------------------------------------------------------------------------------- 1 | 2 | name: parallel-jobs 3 | on: 4 | push: 5 | paths: 6 | - '.github/workflows/05-parallel-jobs.yml' 7 | 8 | jobs: 9 | job-a: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - run: echo "Doing work" 13 | job-b: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v3 17 | 18 | - name: Print current path 19 | working-directory: ./05-parallel-jobs 20 | run: pwd 21 | 22 | - run: echo "More work at the same time" -------------------------------------------------------------------------------- /.github/workflows/06-job-ordering.yml: -------------------------------------------------------------------------------- 1 | name: job-ordering 2 | on: 3 | push: 4 | paths: 5 | - '.github/workflows/06-job-ordering.yml' 6 | jobs: 7 | job1: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v3 11 | 12 | - name: Print current path 13 | working-directory: ./06-job-ordering 14 | run: pwd 15 | 16 | - run: echo "Doing work parallel with job2" 17 | job2: 18 | runs-on: ubuntu-latest 19 | steps: 20 | - run: echo "Doing work parallel with job1" 21 | job3: 22 | runs-on: ubuntu-latest 23 | needs: job1 24 | steps: 25 | - run: echo "job1 done, running job3" 26 | job4: 27 | runs-on: ubuntu-latest 28 | needs: [job2, job3] 29 | steps: 30 | - run: echo "job2 & job3 done, running job4" 31 | job5: 32 | runs-on: ubuntu-latest 33 | if: ${{ always() }} 34 | needs: job1 35 | steps: 36 | - run: echo "job1 completed with status ${{ needs.job1.result }}, running job5" -------------------------------------------------------------------------------- /.github/workflows/07-job-matrix.yml: -------------------------------------------------------------------------------- 1 | name: job-matrix 2 | 3 | on: 4 | push: 5 | paths: 6 | - '07-job-matrix/**' 7 | - '.github/workflows/07-job-matrix.yml' 8 | 9 | jobs: 10 | my-job: 11 | strategy: 12 | matrix: 13 | os: [ubuntu-18.04, ubuntu-22.04] 14 | node: [14, 16, 18] 15 | exclude: 16 | - os: ubuntu-18.04 17 | node: 14 18 | 19 | runs-on: ${{ matrix.os }} 20 | steps: 21 | - uses: actions/checkout@v3 22 | - name: Set up Node.js 23 | uses: actions/setup-node@v3 24 | with: 25 | node-version: ${{ matrix.node }} 26 | 27 | - name: Print OS-release 28 | run: cat /etc/os-release 29 | 30 | - name: Install dependencies 31 | working-directory: ./07-job-matrix 32 | run: npm ci 33 | 34 | - name: Run tests 35 | working-directory: ./07-job-matrix 36 | run: npm test 37 | -------------------------------------------------------------------------------- /.github/workflows/08-outputs.yml: -------------------------------------------------------------------------------- 1 | name: outputs 2 | on: 3 | push: 4 | paths: 5 | - '.github/workflows/08-outputs.yml' 6 | jobs: 7 | job1: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v3 11 | 12 | - name: Print current path 13 | working-directory: ./08-outputs 14 | run: pwd 15 | 16 | - name: Do Work 17 | run: | 18 | echo "FAV_NUMBER=3" >> $GITHUB_OUTPUT 19 | echo "FAV_COLOR=blue" >> $GITHUB_OUTPUT 20 | id: abc 21 | 22 | - name: Read output 23 | run: | 24 | echo "${{steps.abc.outputs.FAV_NUMBER}}" 25 | echo "${{steps.abc.outputs.FAV_COLOR}}" 26 | outputs: 27 | fav-animal: tiger 28 | fav-number: ${{steps.abc.outputs.FAV_NUMBER}} 29 | job2: 30 | runs-on: ubuntu-latest 31 | needs: job1 32 | steps: 33 | - run: | 34 | echo "${{needs.job1.outputs.fav-animal}}" 35 | echo "${{needs.job1.outputs.fav-number}}" 36 | -------------------------------------------------------------------------------- /.github/workflows/09-context-variables.yml: -------------------------------------------------------------------------------- 1 | name: contexts-example 2 | 3 | on: 4 | push: 5 | paths: 6 | - '09-context-variables/**' 7 | - '.github/workflows/09-context-variables.yml' 8 | 9 | pull_request: 10 | paths: 11 | - '09-context-variables/**' 12 | - '.github/workflows/09-context-variables.yml' 13 | 14 | jobs: 15 | use-contexts: 16 | runs-on: ubuntu-latest 17 | 18 | strategy: 19 | matrix: 20 | greeting: [Hello, Howdy, Hey] 21 | 22 | steps: 23 | - uses: actions/checkout@v3 24 | - name: Print greeting 25 | run: echo ${{ matrix.greeting }} 26 | env: 27 | GREETING: ${{ matrix.greeting }} 28 | 29 | - name: Do work with a secret 30 | working-directory: ./09-context-variables 31 | run: ./workRequiringASecret.sh 32 | env: 33 | A_SECRET: ${{ secrets.USERNAME }} 34 | 35 | - name: Run only for pulls 36 | if: ${{ github.event_name == 'pull_request' }} 37 | run: echo "Triggered by a pull request" 38 | -------------------------------------------------------------------------------- /.github/workflows/10-context-expressions.yml: -------------------------------------------------------------------------------- 1 | name: expressions-example 2 | on: 3 | push: 4 | paths: 5 | - '.github/workflows/10-context-expressions.yml' 6 | jobs: 7 | use-expressions: 8 | strategy: 9 | matrix: 10 | greeting: [Hello, Howdy, Hey] 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v3 14 | - name: Print current path 15 | working-directory: ./10-context-expressions 16 | run: pwd 17 | - name: Print if 'Hello' 18 | if: ${{ matrix.greeting == 'Hello' }} 19 | run: echo "greeting is Hello" 20 | - name: Print if starts with 'He' 21 | if: ${{ startsWith(matrix.greeting, 'He') }} 22 | run: echo "greeting starts with He" 23 | - name: Print if ends with 'y' 24 | if: ${{ endsWith(matrix.greeting, 'y') }} 25 | run: echo "greeting ends with y" 26 | - name: Print if contains 'ow' 27 | if: ${{ contains(matrix.greeting, 'ow') }} 28 | run: echo "greeting contains ow" 29 | - name: Print formatted greeting 30 | run: | 31 | echo "${{ format('{0} says {1}', github.actor, matrix.greeting) }}" 32 | - name: To JSON 33 | run: echo 'Job context is ${{ toJSON(job) }}' 34 | - name: From JSON 35 | env: ${{ fromJSON('{"FAVORITE_FRUIT":"APPLE", "FAVORITE_COLOR":"BLUE"}') }} 36 | run: echo "I would like a ${FAVORITE_COLOR} ${FAVORITE_FRUIT}" 37 | - name: Success 38 | if: ${{ success() }} 39 | run: echo "Still running..." 40 | - name: Always 41 | if: ${{ always() }} 42 | run: echo "You will always see this" 43 | - name: Cancelled 44 | if: ${{ cancelled() }} 45 | run: echo "You canceled the workflow" 46 | - name: Failure 47 | if: ${{ failure() }} 48 | run: echo "Something went wrong..." -------------------------------------------------------------------------------- /.github/workflows/11-tmate.yml: -------------------------------------------------------------------------------- 1 | name: tmate 2 | 3 | on: 4 | push: 5 | paths: 6 | - '11-tmate/**' 7 | - '.github/workflows/11-tmate.yml' 8 | 9 | jobs: 10 | my-job: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v3 14 | - name: Set up Node.js 15 | uses: actions/setup-node@v3 16 | with: 17 | node-version: 14 18 | 19 | - name: Print OS-release 20 | run: cat /etc/os-release 21 | 22 | - name: Run tests 23 | working-directory: ./11-tmate 24 | run: npm test 25 | 26 | - name: Setup tmate session 27 | if: ${{ failure() }} 28 | uses: mxschmitt/action-tmate@v3.11 29 | 30 | -------------------------------------------------------------------------------- /.github/workflows/12-postgres-example.yml: -------------------------------------------------------------------------------- 1 | name: PostgreSQL Service Example 2 | on: 3 | push: 4 | paths: 5 | - '.github/workflows/12-postgres-example.yml' 6 | 7 | jobs: 8 | postgres-job: 9 | runs-on: ubuntu-latest 10 | services: 11 | postgres: 12 | image: postgres 13 | env: 14 | POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }} 15 | options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 16 | ports: 17 | # Maps TCP port 5432 in the service container to a randomly chosen available port on the host. 18 | - 5432:5432 19 | 20 | steps: 21 | - uses: actions/checkout@v3 22 | - name: run postgres 23 | run: pg_isready -h localhost -------------------------------------------------------------------------------- /.github/workflows/13-get-secret-value.yml: -------------------------------------------------------------------------------- 1 | name: Get secret value 2 | 3 | on: 4 | push: 5 | paths: 6 | - '.github/workflows/13-get-secret-value.yml' 7 | 8 | # Create a secret with the name `NEW_SECRET` or replace it with the name of the existing secret to see the value of secret 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - name: Echo secret's value 15 | run: | 16 | echo "MASKED=${{ secrets.NEW_SECRET }}" >> $GITHUB_ENV 17 | 18 | - name: Echo unmasked secret's value 19 | run: | 20 | echo ${{ secrets.NEW_SECRET }} | sed 's/./& /g' | sed 's/ //g' 21 | unmasked=$(echo ${{ secrets.NEW_SECRET }} | sed 's/./& /g' | sed 's/ //g') 22 | echo "UNMASKED=$unmasked" >> $GITHUB_ENV 23 | 24 | - name: Echo env secrets 25 | run: | 26 | echo "masked: ${{ env.MASKED }}" 27 | echo "unmasked: ${{ env.UNMASKED }}" -------------------------------------------------------------------------------- /01-hello-world/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alliedium/awesome-github-actions/a9f197fdb5d66192d9f90d8b3b0d2f980f9f925e/01-hello-world/.gitkeep -------------------------------------------------------------------------------- /02-event-triggers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alliedium/awesome-github-actions/a9f197fdb5d66192d9f90d8b3b0d2f980f9f925e/02-event-triggers/.gitkeep -------------------------------------------------------------------------------- /03-actions/helloWorld.js: -------------------------------------------------------------------------------- 1 | console.log("Hello, World!"); -------------------------------------------------------------------------------- /04-environment-variables/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alliedium/awesome-github-actions/a9f197fdb5d66192d9f90d8b3b0d2f980f9f925e/04-environment-variables/.gitkeep -------------------------------------------------------------------------------- /05-parallel-jobs/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alliedium/awesome-github-actions/a9f197fdb5d66192d9f90d8b3b0d2f980f9f925e/05-parallel-jobs/.gitkeep -------------------------------------------------------------------------------- /06-job-ordering/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alliedium/awesome-github-actions/a9f197fdb5d66192d9f90d8b3b0d2f980f9f925e/06-job-ordering/.gitkeep -------------------------------------------------------------------------------- /07-job-matrix/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /07-job-matrix/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:18.04 2 | 3 | ARG U_ID=1000 4 | ARG G_ID=1000 5 | ARG REPO_URL 6 | ARG TOKEN 7 | ARG LABELS='ubuntu-18.04' 8 | ARG RUNNER_NAME='docker-runner' 9 | 10 | RUN if [ -z $REPO_URL ];then \ 11 | >&2 echo "REPO_URL is empty!" ; \ 12 | >&2 exit1 ; \ 13 | fi 14 | RUN if [ -z $TOKEN ];then \ 15 | >&2 echo "TOKEN is empty!" ; \ 16 | >&2 exit1 ; \ 17 | fi 18 | 19 | ENV UID=${U_ID} 20 | ENV GID=${G_ID} 21 | 22 | # Install dependencies 23 | RUN apt-get update && apt-get install -y curl git && apt-get install sudo -y 24 | 25 | RUN apt-get install python3-pip -y 26 | RUN pip3 install lastversion 27 | RUN apt-get install tmate -y 28 | 29 | RUN groupadd -g $GID runner 30 | RUN useradd -rm -u $UID -g $GID -s /bin/sh runner 31 | 32 | WORKDIR /home/runner 33 | 34 | RUN echo "runner ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/runner 35 | 36 | # Install the runner software 37 | RUN curl -o actions-runner-linux-x64-latest.tar.gz -L $(lastversion --assets https://github.com/actions/runner/releases/download --filter "actions-runner-linux-x64-(\d{0,3}.\d{0,3}.\d{0,3}).tar.gz") \ 38 | && tar xzf ./actions-runner-linux-x64-latest.tar.gz && rm actions-runner-linux-x64-latest.tar.gz 39 | 40 | RUN /home/runner/bin/installdependencies.sh 41 | 42 | RUN chown -R $UID:$GID /home/runner 43 | 44 | USER runner 45 | 46 | # Configure the runner 47 | RUN (echo ''; echo "${RUNNER_NAME}"; echo "${LABELS}";) | ./config.sh --url $REPO_URL --token $TOKEN 48 | # Start the runner 49 | ENTRYPOINT ["./run.sh"] 50 | 51 | -------------------------------------------------------------------------------- /07-job-matrix/README.md: -------------------------------------------------------------------------------- 1 | awesome-github-actions-07-job-matrix 2 | -------------------------------------------------------------------------------- /07-job-matrix/index.js: -------------------------------------------------------------------------------- 1 | const chalk = require("chalk"); 2 | const boxen = require("boxen"); 3 | 4 | const greeting = chalk.white.bold("Hello!"); 5 | 6 | const boxenOptions = { 7 | padding: 1, 8 | margin: 1, 9 | borderStyle: "round", 10 | borderColor: "green", 11 | backgroundColor: "#555555" 12 | }; 13 | const msgBox = boxen( greeting, boxenOptions ); 14 | 15 | console.log(msgBox); 16 | -------------------------------------------------------------------------------- /07-job-matrix/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hello-cli", 3 | "version": "1.0.0", 4 | "description": "", 5 | "scripts": { 6 | "start": "node index.js", 7 | "test": "jest" 8 | }, 9 | "keywords": [], 10 | "author": "Alliedium devOps", 11 | "license": "MIT", 12 | "dependencies": { 13 | "boxen": "4.0", 14 | "chalk": "2.4", 15 | "jest": "^26.6.3" 16 | }, 17 | "jest": { 18 | "testRegex": ".*/*\\.test.js$" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /07-job-matrix/tests/First.test.js: -------------------------------------------------------------------------------- 1 | describe("PostgreSqlContainer", () => { 2 | test('This is first test', () => { 3 | console.log("Test Output") 4 | }) 5 | }); 6 | -------------------------------------------------------------------------------- /07-job-matrix/workflows/self-hosted-containers-wf.yml: -------------------------------------------------------------------------------- 1 | name: job-matrix 2 | 3 | on: 4 | push: 5 | paths: 6 | - '07-job-matrix/**' 7 | - '.github/workflows/07-job-matrix.yml' 8 | 9 | jobs: 10 | my-job: 11 | strategy: 12 | matrix: 13 | os: [ 'ubuntu:18.04', 'ubuntu:20.04' ] 14 | node: [12, 14, 16] 15 | exclude: 16 | - os: 'ubuntu:18.04' 17 | node: 12 18 | 19 | runs-on: [self-hosted, linux, docker ] 20 | container: ${{ matrix.os }} 21 | steps: 22 | - uses: actions/checkout@v2 23 | - name: Set up Node.js 24 | uses: actions/setup-node@v2 25 | with: 26 | node-version: ${{ matrix.node }} 27 | 28 | - name: Print OS-release 29 | run: cat /etc/os-release 30 | 31 | - name: Install dependencies 32 | working-directory: ./07-job-matrix 33 | run: npm ci 34 | 35 | - name: Run tests 36 | working-directory: ./07-job-matrix 37 | run: npm test 38 | -------------------------------------------------------------------------------- /07-job-matrix/workflows/self-hosted-labels-tmate-container-wf.yml: -------------------------------------------------------------------------------- 1 | name: job-matrix 2 | 3 | on: 4 | push: 5 | paths: 6 | - '07-job-matrix/**' 7 | - '.github/workflows/07-job-matrix.yml' 8 | 9 | jobs: 10 | my-job: 11 | strategy: 12 | matrix: 13 | os: ['ubuntu:18.04', 'ubuntu:20.04'] 14 | node: [12, 14, 16] 15 | exclude: 16 | - os: ubuntu-18.04 17 | node: 12 18 | 19 | runs-on: [ self-hosted, Linux, docker ] 20 | container: ${{ matrix.os }} 21 | steps: 22 | - uses: actions/checkout@v2 23 | - name: Set up Node.js 24 | uses: actions/setup-node@v2 25 | with: 26 | node-version: ${{ matrix.node }} 27 | 28 | 29 | - name: Print OS-release 30 | run: cat /etc/os-release 31 | 32 | - name: Run tests 33 | working-directory: ./07-job-matrix 34 | run: npm test 35 | 36 | - name: Install tmate 37 | if: ${{ failure() }} 38 | run: apt update && apt install tmate -y && apt install sudo -y 39 | 40 | - name: Setup tmate session 41 | if: ${{ failure() }} 42 | uses: mxschmitt/action-tmate@v3.11 -------------------------------------------------------------------------------- /07-job-matrix/workflows/self-hosted-labels-tmate-wf.yml: -------------------------------------------------------------------------------- 1 | name: job-matrix 2 | 3 | on: 4 | push: 5 | paths: 6 | - '07-job-matrix/**' 7 | - '.github/workflows/07-job-matrix.yml' 8 | 9 | jobs: 10 | my-job: 11 | strategy: 12 | matrix: 13 | os: [ubuntu-18.04, ubuntu-22.04] 14 | node: [ 14, 16] 15 | exclude: 16 | - os: ubuntu-22.04 17 | node: 12 18 | 19 | runs-on: [ self-hosted, Linux, '${{ matrix.os }}' ] 20 | steps: 21 | - uses: actions/checkout@v2 22 | - name: Set up Node.js 23 | uses: actions/setup-node@v2 24 | with: 25 | node-version: ${{ matrix.node }} 26 | 27 | - name: Print OS-release 28 | run: cat /etc/os-release 29 | 30 | - name: Run tests 31 | working-directory: ./07-job-matrix 32 | run: npm test 33 | 34 | - name: Setup tmate session 35 | if: ${{ failure() }} 36 | uses: mxschmitt/action-tmate@v3.11 -------------------------------------------------------------------------------- /07-job-matrix/workflows/self-hosted-labels-wf.yml: -------------------------------------------------------------------------------- 1 | name: job-matrix 2 | 3 | on: 4 | push: 5 | paths: 6 | - '07-job-matrix/**' 7 | - '.github/workflows/07-job-matrix.yml' 8 | 9 | jobs: 10 | my-job: 11 | strategy: 12 | matrix: 13 | os: [ubuntu-18.04, ubuntu-22.04] 14 | node: [12, 14, 16] 15 | exclude: 16 | - os: ubuntu-22.04 17 | node: 12 18 | 19 | runs-on: [ self-hosted, Linux, '${{ matrix.os }}' ] 20 | steps: 21 | - uses: actions/checkout@v2 22 | - name: Set up Node.js 23 | uses: actions/setup-node@v2 24 | with: 25 | node-version: ${{ matrix.node }} 26 | 27 | - name: Print OS-release 28 | run: cat /etc/os-release 29 | 30 | - name: Install dependencies 31 | working-directory: ./07-job-matrix 32 | run: npm ci 33 | 34 | - name: Run tests 35 | working-directory: ./07-job-matrix 36 | run: npm test -------------------------------------------------------------------------------- /07-job-matrix/workflows/self-hosted-wf.yml: -------------------------------------------------------------------------------- 1 | name: job-matrix 2 | 3 | on: 4 | push: 5 | paths: 6 | - '07-job-matrix/**' 7 | - '.github/workflows/07-job-matrix.yml' 8 | 9 | jobs: 10 | my-job: 11 | strategy: 12 | matrix: 13 | os: [ubuntu-18.04, ubuntu-22.04] 14 | node: [12, 14, 16] 15 | exclude: 16 | - os: ubuntu-22.04 17 | node: 12 18 | 19 | runs-on: [ self-hosted, Linux ] 20 | steps: 21 | - uses: actions/checkout@v2 22 | - name: Set up Node.js 23 | uses: actions/setup-node@v2 24 | with: 25 | node-version: ${{ matrix.node }} 26 | 27 | - name: Print OS-release 28 | run: cat /etc/os-release 29 | 30 | - name: Install dependencies 31 | working-directory: ./07-job-matrix 32 | run: npm ci 33 | 34 | - name: Run tests 35 | working-directory: ./07-job-matrix 36 | run: npm test -------------------------------------------------------------------------------- /08-outputs/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alliedium/awesome-github-actions/a9f197fdb5d66192d9f90d8b3b0d2f980f9f925e/08-outputs/.gitkeep -------------------------------------------------------------------------------- /09-context-variables/workRequiringASecret.sh: -------------------------------------------------------------------------------- 1 | echo "This is our new example. Print secret [$A_SECRET] " 2 | -------------------------------------------------------------------------------- /10-context-expressions/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alliedium/awesome-github-actions/a9f197fdb5d66192d9f90d8b3b0d2f980f9f925e/10-context-expressions/.gitkeep -------------------------------------------------------------------------------- /11-tmate/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /11-tmate/index.js: -------------------------------------------------------------------------------- 1 | const chalk = require("chalk"); 2 | const boxen = require("boxen"); 3 | 4 | const greeting = chalk.white.bold("Hello!"); 5 | 6 | const boxenOptions = { 7 | padding: 1, 8 | margin: 1, 9 | borderStyle: "round", 10 | borderColor: "green", 11 | backgroundColor: "#555555" 12 | }; 13 | const msgBox = boxen( greeting, boxenOptions ); 14 | 15 | console.log(msgBox); 16 | -------------------------------------------------------------------------------- /11-tmate/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hello-cli", 3 | "version": "1.0.0", 4 | "description": "", 5 | "scripts": { 6 | "start": "node index.js", 7 | "test": "jest" 8 | }, 9 | "keywords": [], 10 | "author": "Alliedium devOps", 11 | "license": "MIT", 12 | "dependencies": { 13 | "boxen": "4.0", 14 | "chalk": "2.4", 15 | "jest": "^26.6.3" 16 | }, 17 | "jest": { 18 | "testRegex": ".*/*\\.test.js$" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /11-tmate/tests/First.test.js: -------------------------------------------------------------------------------- 1 | describe("PostgreSqlContainer", () => { 2 | test('This is first test', () => { 3 | console.log("Test Output") 4 | }) 5 | }); 6 | -------------------------------------------------------------------------------- /12-postgres/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alliedium/awesome-github-actions/a9f197fdb5d66192d9f90d8b3b0d2f980f9f925e/12-postgres/.gitkeep -------------------------------------------------------------------------------- /13-get-secret/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alliedium/awesome-github-actions/a9f197fdb5d66192d9f90d8b3b0d2f980f9f925e/13-get-secret/.gitkeep -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Awesome GitHub Actions 2 | 3 | This repository serves as a comprehensive collection of GitHub Actions workflow examples. 4 | It provides a variety of workflow configurations that demonstrate different use cases and 5 | best practices for automating CI/CD processes using GitHub Actions. Each 6 | example includes a name for the workflow, a list of trigger events, and a set of jobs. Each 7 | job contains a list of steps that execute in order when the job runs. These steps may access 8 | environment variables, conditions, expressions, and secrets to perform various actions, 9 | such as checking out the source repository, running scripts, and setting up a `tmate` session 10 | for debugging purposes. Examples cover different areas of functionality, such as job 11 | matrix, parallel jobs, job ordering, context variables, expression evaluation, outputting 12 | variables, and event triggers. 13 | 14 | ## GitHub Actions 15 | GitHub Actions is a CI/CD platform for automatic build, test, and deployment. GitHub Actions allows you to run workflows when a `push`, `pull request`, or other `event` happens in your repository. You can use virtual machines provided by GitHub or manage your own runners in your own infrastructure. 16 | Workflow is a process that runs one or more jobs. They can be run either in parallel or in sequential order. 17 | Workflow basics: 18 | - One or more `events` that will trigger the workflow. `Event` is a specific activity in a repository. 19 | - One or more `jobs`, each of which will execute on a `runner` machine and run a series of one or more `steps`. By default, every job is independent 20 | - Each `step` can either run a script that you define or run an `action`, which is a reusable extension that can simplify your workflow 21 | - Each `Runner` is a newly-provisioned virtual machine. GitHub provides Ubuntu Linux, MS Windows, and macOS runners. You can host your runner as well. Every runner executes a single job. 22 | 23 | Workflow files are `yaml` files and are placed in the `.github/workflows` directory in your repository on GitHub. 24 | 25 | ## Examples 26 | **Note** **_By default, all workflows will be executed on the `ubuntu-latest ` image unless otherwise specified_** 27 | 28 | ## Example 01: Hello world! 29 | 30 | *_Get familiar with basic workflow syntax_* 31 | 32 | This example workflow prints `current path`, `Hello world`, followed by `Step 1…`, `Step 2…`, `Step 3…`, and finally `Goodbye`. 33 | 34 | **Elements of current workflow:** 35 | 1. Name of workflow (optional element) 36 | ```yaml 37 | name: hello-world-example 38 | ``` 39 | 2. The `on` section defines what event triggers the workflow. Here, the trigger event is `push`. 40 | The optional parameter `paths` allows to run a workflow based on what files or directories are changed. 41 | 42 | ```yaml 43 | on: 44 | push: 45 | paths: 46 | - '.github/workflows/01-hello-world.yml' 47 | ``` 48 | 3. Job. The job name is `say-hello`. 49 | The keyword `runs-on` configures the job to run on the latest version of an Ubuntu Linux runner. 50 | ```yaml 51 | jobs: 52 | say-hello: 53 | runs-on: ubuntu-latest 54 | ``` 55 | 56 | 4. `Steps` are a list of commands to run. The `uses` keyword specifies the action used in this job: `actions/checkout` version`v2`. 57 | This is an action that checks out your repository onto the runner. 58 | You should use the `checkout action` any time your workflow will run against the repository's code. 59 | The Next step sets the option `working-directory` to the indicated path and prints the current path. 60 | ```yaml 61 | steps: 62 | - uses: actions/checkout@v3 63 | 64 | - name: Print current path 65 | working-directory: ./01-hello-world 66 | run: pwd 67 | ``` 68 | 5. Pipe `|` is used to start multiple strings in a `yaml` file 69 | ```yaml 70 | - name: Do stuff 71 | run: | 72 | echo "Step 1..." 73 | echo "Step 2..." 74 | echo "Step 3..." 75 | echo "Step 4..." 76 | ``` 77 | 78 | ## Example 02: Event triggers 79 | 80 | *_This example demonstrates how to trigger workflow on different events_* 81 | 82 | The `on` section defines what event triggers the workflow. List of events you can see [here](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows). 83 | Optionally, you may include/exclude `branches`, `tags`, or `paths` that trigger workflow by indicating their name or pattern to match. 84 | You may define multiple events and options for them to customize your workflow run. Also, it is possible to set a schedule to run your workflow, 85 | specified with [POSIX cron syntax](https://crontab.guru/). 86 | 87 | ```yaml 88 | on: 89 | push: 90 | branches: 91 | - '02-develop' 92 | - '02-foo/*' 93 | - '02-foo/**' 94 | - '!02-foo/*/456' #except 95 | tags: 96 | - '*' 97 | paths: 98 | - '.github/workflows/02-event-triggers.yml' 99 | pull_request: 100 | branches: 101 | - '02-develop' 102 | paths: 103 | - '.github/workflows/02-event-triggers.yml' 104 | schedule: 105 | - cron: '*/15 * * * *' 106 | ``` 107 | Step prints the event name that triggered it.: 108 | ```yaml 109 | - name: Event 110 | run: echo "Triggered by $GITHUB_EVENT_NAME" 111 | ``` 112 | 113 | ## Example 03: Actions 114 | 115 | *_This example demonstrates the usage of different actions type in one workflow_* 116 | 117 | Actions reduce number of steps by providing reusable `code` for common tasks, such as checkout to gitHub repository or installing node. 118 | To run an action include keyword `uses` pointing to a GitHub repo with the pattern `{owner}/{repo}@{ref}` or `{owner}/{repo}/{path}@{ref}`. A `ref` can be a branch, tag or SHA. Some actions have required or optional parameters. 119 | GitHub officially supports many common [actions](https://github.com/actions). 120 | 121 | Example of usage of the different actions in workflow: 122 | ```yaml 123 | steps: 124 | - uses: actions/checkout@v3 125 | - uses: actions/setup-node@v3 126 | with: 127 | node-version: '15.8.0' 128 | ``` 129 | 130 | In these steps : 131 | - [actions/checkout](https://github.com/actions/checkout) checks out your repo into the working directory at the event that triggered workflow (e.g., branch push) 132 | - [actions/setup-node](https://github.com/actions/setup-node) sets up your workflow with a specific node version, and makes node and npm available in the following steps. 133 | 134 | ## Example 04: Environment variables 135 | 136 | *_Using environment variables in different contexts_* 137 | 138 | Environment variables can be: 139 | * default. Find the list of default variables [here](https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables) and defined by the user. 140 | * or custom for: 141 | * **a single workflow**. Use the `env` key within the workflow file to create a variable for a single workflow. The scope of the variables can be: the entire workflow, job, or a specific step. The variable's scope is limited to the element in which it is defined. 142 | * **multiple workflows**. Variables and secrets can be created at different levels: [organization](https://docs.github.com/en/actions/learn-github-actions/variables#creating-configuration-variables-for-an-organization), [repository](https://docs.github.com/en/actions/learn-github-actions/variables#creating-configuration-variables-for-a-repository) and [environment](https://docs.github.com/en/actions/learn-github-actions/variables#creating-configuration-variables-for-an-environment) levels. 143 | 144 | Job: 145 | ```yaml 146 | jobs: 147 | use-env-vars: 148 | runs-on: ubuntu-latest 149 | env: 150 | VIDI: 'I saw' 151 | ``` 152 | Step: 153 | ```yaml 154 | steps: 155 | ... 156 | - name: Show me the vars 157 | run: echo "$VENI, $VIDI, $VICI" 158 | env: 159 | VICI: 'I conquered' 160 | ``` 161 | Also, you can set new environment variables by adding it to GITHUB_ENV. The variable will be available in next steps. 162 | ```yaml 163 | - name: Create env var 164 | run: echo "foo=bar" >> $GITHUB_ENV 165 | ``` 166 | Get values of the environment variables: 167 | ```yaml 168 | - name: Useful default vars 169 | run: | 170 | echo "Workflow name: $GITHUB_WORKFLOW" 171 | echo "Workspace: $GITHUB_WORKSPACE" 172 | echo "Event: $GITHUB_EVENT_NAME" 173 | echo "SHA: $GITHUB_SHA" 174 | echo "Ref: $GITHUB_REF" 175 | ``` 176 | Get list of all environment variables: 177 | ```yaml 178 | - name: Show env variables list 179 | run: env 180 | ``` 181 | 182 | ## Example 05: Parallel jobs 183 | 184 | _*Running jobs in parallel*_ 185 | 186 | Multiple jobs are running in parallel by default and have a particular runner: 187 | ```yaml 188 | jobs: 189 | job-a: 190 | runs-on: ubuntu-latest 191 | steps: 192 | - run: echo "Doing work" 193 | job-b: 194 | runs-on: ubuntu-latest 195 | steps: 196 | - uses: actions/checkout@v3 197 | ``` 198 | 199 | ## Example 06: Job ordering 200 | 201 | _*By default, all jobs are running in parallel. To force job ordering use the `needs` keyword*_ 202 | 203 | It is possible to wait for one or more jobs: 204 | ```yaml 205 | job3: 206 | runs-on: ubuntu-latest 207 | needs: job1 208 | steps: 209 | - run: echo "job1 done, running job3" 210 | job4: 211 | runs-on: ubuntu-latest 212 | needs: [job2, job3] 213 | steps: 214 | - run: echo "job2 & job3 done, running job4" 215 | ``` 216 | `job5` will run even if `job1` will fail 217 | ```yaml 218 | job5: 219 | runs-on: ubuntu-latest 220 | if: ${{ always() }} 221 | needs: job1 222 | steps: 223 | - run: echo "job1 completed with status ${{ needs.job1.result }}, running job5 224 | ``` 225 | The diagram of the job running sequence is provided 226 | ```mermaid 227 | %%{init: {'flowchart': {"curve":"linear"} } }%% 228 | graph LR 229 | A[job1] --> |on success| C[job3] 230 | B[job2] & C[job3] --> |on success| D[job4] 231 | A[job1] --> |always| E[job5] 232 | ``` 233 | 234 | ## Example 07: Job matrix 235 | 236 | _*You can run multiple jobs with different configurations by using a job matrix. Jobs defined by matrix run in parallel by default*_ 237 | 238 | The `matrix` keyword is how you define a job matrix. Each user-defined key is a matrix parameter. Here we’ve defined two parameters: `os`, for the 239 | runner's OS, and `node`, to indicate the node version. Each value of the parameters from the list is used in a `cartesian product` to create jobs. 240 | This section defines a 2 x 3 matrix of 6 jobs, each with a different combination of `os` and `node`. The `exclude` keyword prevents jobs with 241 | specific configurations from running. The `include` allows you to add new jobs to the matrix. Note that the `include` rules are always 242 | evaluated after the `exclude` rules. 243 | ```yaml 244 | my-job: 245 | strategy: 246 | matrix: 247 | os: [ubuntu-18.04, ubuntu-22.04] 248 | node: [14, 16, 18] 249 | exclude: 250 | - os: ubuntu-18.04 251 | node: 14 252 | ``` 253 | 254 | ## Example 07a: [Self-hosted runners for multiple jobs](./README_SELFHOSTED_RUNNERS.md) 255 | 256 | A `runner` is a server that runs your workflows when they're triggered. Each runner can run a single job at a time. GitHub provides Ubuntu Linux, Microsoft Windows, and macOS runners to run your workflows; each workflow run executes in a fresh, newly-provisioned virtual machine. If you need a different operating system or require a specific hardware configuration, you can host your [own runners](https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/about-self-hosted-runners). 257 | A self-hosted runner is a system that you deploy and manage to execute jobs from GitHub Actions on GitHub.com. 258 | 259 | ## Example 08: Outputs 260 | 261 | Output data can be shared between `jobs` and `steps`. 262 | Create outputs for a step by writing to stdout in the format of =: 263 | 264 | ```yaml 265 | - name: Do Work 266 | run: | 267 | echo "FAV_NUMBER=3" >> $GITHUB_OUTPUT 268 | echo "FAV_COLOR=blue" >> $GITHUB_OUTPUT 269 | id: abc 270 | ``` 271 | A step can have multiple outputs. Steps that create outputs must have a unique `id`. 272 | Use the steps context variable and step `id` to get the value `${{steps..outputs.}}`: 273 | ```yaml 274 | - name: Read output 275 | run: | 276 | echo "${{steps.abc.outputs.FAV_NUMBER}}" 277 | echo "${{steps.abc.outputs.FAV_COLOR}}" 278 | ``` 279 | Create outputs for a job that will be available to other jobs that need it (see Job Ordering). 280 | You can include output from steps that ran for the job. 281 | ```yaml 282 | job1: 283 | outputs: 284 | fav-animal: tiger 285 | fav-number: ${{steps.abc.outputs.FAV_NUMBER}} 286 | ``` 287 | Use context expressions to grab outputs from a job included in needs 288 | `needs: `, to address output `${{needs..outputs.}}`: 289 | ```yaml 290 | job2: 291 | runs-on: ubuntu-latest 292 | needs: job1 293 | steps: 294 | - run: | 295 | echo "${{needs.job1.outputs.fav-animal}}" 296 | echo "${{needs.job1.outputs.fav-number}}" 297 | ``` 298 | 299 | ## Example 09: Context 300 | 301 | _*`Contexts` are a way to access information about workflow runs, variables, runner environments, jobs, and steps. Each context is an object that contains properties, which can be strings or other objects. Context variables are accessible outside the run commands.*_ 302 | 303 | Using values of the `matrix` context: 304 | ```yaml 305 | env: 306 | GREETING: ${{ matrix.greeting }} 307 | ``` 308 | Accessing value of the secret `USERNAME` defined in the GitHub: 309 | ```yaml 310 | env: 311 | A_SECRET: ${{ secrets.USERNAME }} 312 | ``` 313 | Using event name in expression: 314 | ```yaml 315 | if: ${{ github.event_name == 'pull_request' }} 316 | ``` 317 | 318 | ## Example 10: Expressions 319 | 320 | _*Workflows support evaluating expressions,comparisons and simple functions.*_ 321 | 322 | String comparison: 323 | ```yaml 324 | - name: Print if 'Hello' 325 | if: ${{ matrix.greeting == 'Hello' }} 326 | run: echo "greeting is Hello" 327 | - name: Print if starts with 'He' 328 | if: ${{ startsWith(matrix.greeting, 'He') }} 329 | run: echo "greeting starts with He" 330 | - name: Print if ends with 'y' 331 | if: ${{ endsWith(matrix.greeting, 'y') }} 332 | run: echo "greeting ends with y" 333 | - name: Print if contains 'ow' 334 | if: ${{ contains(matrix.greeting, 'ow') }} 335 | run: echo "greeting contains ow" 336 | ``` 337 | Formatting: 338 | ```yaml 339 | - name: Print formatted greeting 340 | run: | 341 | echo "${{ format('{0} says {1}', github.actor, matrix.greeting) }}" 342 | ``` 343 | Working with `JSON`: 344 | ```yaml 345 | - name: To JSON 346 | run: echo 'Job context is ${{ toJSON(job) }}' 347 | - name: From JSON 348 | env: ${{ fromJSON('{"FAVORITE_FRUIT":"APPLE", "FAVORITE_COLOR":"BLUE"}') }} 349 | run: echo "I would like a ${FAVORITE_COLOR} ${FAVORITE_FRUIT}" 350 | ``` 351 | Running basing on previous results: 352 | ```yaml 353 | - name: Success 354 | if: ${{ success() }} 355 | run: echo "Still running..." 356 | - name: Always 357 | if: ${{ always() }} 358 | run: echo "You will always see this" 359 | - name: Cancelled 360 | if: ${{ cancelled() }} 361 | run: echo "You canceled the workflow" 362 | - name: Failure 363 | if: ${{ failure() }} 364 | run: echo "Something went wrong..." 365 | ``` 366 | 367 | ## Example 11: `Tmate` terminal 368 | 369 | _*The `Tmate` session will be started after fail on the previous step. Use this failing workflow for training*_ 370 | 371 | The workflow will fail on the following step because `npm` is not installed and no node action is used in this workflow. 372 | 373 | ```yaml 374 | - name: Run tests 375 | working-directory: ./11-tmate 376 | run: npm test 377 | ``` 378 | Open the `tmate` session using the HTTP link from your workflow logs. 379 | If `tmate` is [installed](./README_SELFHOSTED_RUNNERS.md#7-debugging-running-workflow) on your machine you may also connect to the session throw terminal. The command is provided in your logs as well. 380 | 381 | ![tmate.png](./images/tmate.png) 382 | 383 | Run npm install: 384 | 385 | ```shell 386 | npm ci 387 | ``` 388 | 389 | and check if tests will pass: 390 | 391 | ```shell 392 | npm test 393 | ``` 394 | 395 | continue workflow run by creating a file: 396 | 397 | ```shell 398 | touch /continue 399 | ``` 400 | 401 | ## Example 12: Postgres service 402 | This example workflow configures a `PostgreSQL` service container, and automatically maps port `5432` in the service container to a _randomly_ chosen available port on the `host`. The `job context` is used to access the number of the port that was assigned on the host. 403 | **Create a secret at the repository level with the name `POSTGRES_PASSWORD`** 404 | ```yaml 405 | jobs: 406 | postgres-job: 407 | runs-on: ubuntu-latest 408 | services: 409 | postgres: 410 | image: postgres 411 | env: 412 | POSTGRES_PASSWORD: postgres 413 | options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 414 | ports: 415 | # Maps TCP port 5432 in the service container to a randomly chosen available port on the host. 416 | - 5432 417 | ``` 418 | 419 | ## Example 13: Get secret value 420 | Get a value of the secret with the name `NEW_SECRET`. If the secret does not exist value will be empty. Please create a secret with the same name or replace name with the one of an existing secret 421 | ```yaml 422 | steps: 423 | - name: Echo secret's value 424 | run: | 425 | echo "Masked: " 426 | echo ${{ secrets.NEW_SECRET }} 427 | echo "Unmasked: " 428 | echo ${{ secrets.NEW_SECRET }} | sed 's/./& /g' 429 | ``` 430 | ## Nektos Act 431 | ### Install Nektos Act on Ubuntu Jammy 432 | 433 | ```shell 434 | sudo apt install act 435 | ``` 436 | To install `Nektos Act` on other OS follow the instructions from [section](https://github.com/nektos/act#installation-through-package-managers) 437 | 438 | To run the following commands you should clone a GitHub project with existing GitHub Actions workflows and go to its directory. You can use the current project, too. 439 | 440 | 1. View all jobs that are triggered by pull_request event 441 | ```shell 442 | act -l 443 | ``` 444 | 2. View all jobs triggered by events, e.g. by the `pull_request` 445 | ```shell 446 | act -l 447 | ``` 448 | ```shell 449 | act pull_request -l 450 | ``` 451 | or in the certain workflow file, e.g. in `main.yaml` 452 | ```shell 453 | act -l 454 | ``` 455 | ```shell 456 | act main.yaml -l 457 | ``` 458 | 3. Run a job with a specific name: 459 | ```shell 460 | act -j 461 | ``` 462 | 4. You may also explicitly indicate the workflow and job to run using flags `--workflow`and `--job`, respectively, flag `--verbosity` enables additional logging. 463 | ```shell 464 | act --workflows .github/workflows/main.yml --verbose --job my-job 465 | ``` 466 | 5. Use an alternative environment to run your workflows. `runner-image-name` - should be the same as in the workflow `yaml` file 467 | ```shell 468 | act -P = 469 | ``` 470 | ```shell 471 | act -P ubuntu-latest=catthehacker/ubuntu:act-20.04 472 | ``` 473 | 6. If your workflow file has a `tmate` section (See Example 11) you may access it using docker commands 474 | ```shell 475 | watch docker ps 476 | ``` 477 | copy the first three symbols of the container's ID and run the command 478 | ```shell 479 | docker exec -it sh 480 | ``` 481 | 482 | ## [Ignite migration tool](https://github.com/Alliedium/ignite-migration-tool) 483 | 484 | 1. [About project](https://github.com/Alliedium/ignite-migration-tool/blob/main/README.md) 485 | 2. [Apache Ignite Migration Tool CI/CD](https://github.com/Alliedium/ignite-migration-tool/blob/main/README_CI.md) 486 | 3. [Apache Ignite Migration Tool CI/CD GPG](https://github.com/Alliedium/ignite-migration-tool/blob/main/README_GPG.md) 487 | 488 | 489 | ## References 490 | #### GitHub Actions 491 | 1. [GitHub Actions workflows](https://docs.github.com/en/actions/using-workflows/about-workflows) 492 | 2. [GitHub Actions workflows basics, examples and a quick tutorial](https://codefresh.io/learn/github-actions/github-actions-workflows-basics-examples-and-a-quick-tutorial/) 493 | 3. [Trigger a workflow](https://docs.github.com/en/actions/using-workflows/triggering-a-workflow) 494 | 4. [Job environments](https://docs.github.com/en/actions/using-jobs/using-environments-for-jobs) 495 | 5. [Expressions in GitHub Actions](https://docs.github.com/en/actions/learn-github-actions/expressions) 496 | 6. [GitHub Actions contexts](https://docs.github.com/en/actions/learn-github-actions/contexts) 497 | 7. [GitHub Actions variables](https://docs.github.com/en/actions/learn-github-actions/variables) 498 | 8. [GitHub Actions common actions](https://github.com/actions) 499 | 9. [Good security practices for using GitHub Actions features](https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions) 500 | 10. [Encrypted secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets) 501 | 11. [Outputs for jobs](https://docs.github.com/en/actions/using-jobs/defining-outputs-for-jobs) 502 | 12. [Output commands](https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/) 503 | 13. [Tmate actions](https://github.com/mxschmitt/action-tmate) 504 | 14. [Job services](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idservices) 505 | 506 | #### Act 507 | 15. [Act](https://github.com/nektos/act) 508 | 16. [GitHub Actions on your local machine](https://dev.to/ken_mwaura1/run-github-actions-on-your-local-machine-bdm) 509 | 17. [Debug GitHub Actions locally with act](https://everyday.codes/tutorials/debug-github-actions-locally-with-act/) 510 | 511 | #### Tools 512 | 18. [Lastversion tool](https://github.com/dvershinin/lastversion) -------------------------------------------------------------------------------- /README_SELFHOSTED_RUNNERS.md: -------------------------------------------------------------------------------- 1 | # Self-hosted runners 2 | 3 | A runner is a server that runs your workflows when they're triggered. Each runner can run a single job at a time. GitHub provides Ubuntu Linux, Microsoft Windows, and macOS runners to run your workflows; each workflow run executes in a fresh, newly-provisioned virtual machine. If you need a different operating system or require a specific hardware configuration, you can host your [own runners](https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/about-self-hosted-runners). 4 | A self-hosted runner is a system that you deploy and manage to execute jobs from GitHub Actions on GitHub.com. 5 | 6 | ## Prerequisites: 7 | 8 | ### 1. Create VMs to use as self-hosted runners 9 | 10 | - To create VMs in `Proxmox` use [scripts](https://github.com/Alliedium/awesome-proxmox/tree/main/vm-cloud-init-shell#vm-provisioning-scripts-based-on-cloud-init-images) 11 | 12 | - To create VMs in `Hyper-V` use [steps](https://github.com/Alliedium/awesome-devops/tree/main/03_virtualization_on_windows_and_zfs_11-aug-2022#create-vms-in-hyper-v) 13 | 14 | ### 2. Install `docker` if you want to run workflow jobs in containers 15 | 16 | - [`Manjaro`](https://github.com/Alliedium/awesome-linux-config/blob/master/manjaro/basic/install_docker.sh) 17 | 18 | - [Ubuntu](https://docs.docker.com/engine/install/ubuntu/) 19 | 20 | 21 | ### 3. Install [tmate](https://tmate.io/) for debugging 22 | 23 | 24 | ## Repository-level runners 25 | 26 | ### 1. Create a fork from the [main repository](https://github.com/Alliedium/awesome-github-actions) 27 | 28 | ![fork](./images/fork.png) 29 | 30 | ### 2. Clone [project](https://github.com/Alliedium/awesome-github-actions) 31 | 32 | ``` 33 | git clone https://github.com/Alliedium/awesome-github-actions.git $HOME/awesome-github-actions 34 | ``` 35 | 36 | Replace the `https://github.com/Alliedium/awesome-github-actions.git` repository URL with the fork URL you created 37 | 38 | ### 3. Add a self-hosted Linux runner to the `GitHub` repository. 39 | 40 | ![add_runner](./images/add_runner.png) 41 | 42 | Run commands on the Linux VM `runner` 43 | 44 | - Create a `actions-runner` folder 45 | 46 | ``` 47 | mkdir actions-runner && cd actions-runner 48 | ``` 49 | 50 | - Download the latest runner package 51 | 52 | If you prefer to use the last version of `action runners`, run the command using tool [lastversion](https://github.com/dvershinin/lastversion): 53 | ```shell 54 | lastversion --assets https://github.com/actions/runner/releases/download --filter "actions-runner-linux-x64-(\d{0,3}\.\d{0,3}\.\d{0,3}).tar.gz" 55 | ``` 56 | The output of the command is the URL to the actions-runner-linux-x64 resource with the latest version of the downloading file. Use this URL in the following command and the version of the actions-runner from the output in the other commands below. In our case, all commands are provided with the version `2.305.0`. 57 | ```shell 58 | curl -o actions-runner-linux-x64-2.305.0.tar.gz -L https://github.com/actions/runner/releases/download/v2.305.0/actions-runner-linux-x64-2.305.0.tar.gz 59 | ``` 60 | 61 | - Extract the installer 62 | 63 | ```shell 64 | tar xzf ./actions-runner-linux-x64-2.305.0.tar.gz 65 | ``` 66 | 67 | - Create the runner and start the configuration experience: 68 | 69 | ```shell 70 | ./config.sh --url https://github.com/Alliedium/awesome-github-actions --token AL24AM7L6GS3RRSBBTGSSILESXOW6 71 | ``` 72 | Replace the `https://github.com/Alliedium/awesome-github-actions` repository URL with the fork URL you created 73 | 74 | - Run it! 75 | 76 | ``` 77 | ./run.sh 78 | ``` 79 | 80 | ### 3. Add a self-hosted Windows runner to the `GitHub` repository. 81 | 82 | - In `Windows` machine open `PowerShell` 83 | - Create a folder under the drive root 84 | 85 | ``` 86 | mkdir actions-runner; cd actions-runner 87 | ``` 88 | 89 | - Download the latest runner package 90 | 91 | ``` 92 | Invoke-WebRequest -Uri https://github.com/actions/runner/releases/download/v2.305.0/actions-runner-win-x64-2.305.0.zip -OutFile actions-runner-win-x64-2.305.0.zip 93 | 94 | ``` 95 | 96 | - Extract the installer 97 | 98 | ``` 99 | Add-Type -AssemblyName System.IO.Compression.FileSystem ; [System.IO.Compression.ZipFile]::ExtractToDirectory("$PWD/actions-runner-win-x64-2.305.0.zip", "$PWD") 100 | ``` 101 | 102 | - Create the runner and start the configuration experience 103 | 104 | ``` 105 | ./config.cmd --url https://github.com/Alliedium/awesome-github-actions --token AL24AM56SRAXQCYI7PF7KW3ES5ILY 106 | ``` 107 | 108 | Replace the `https://github.com/Alliedium/awesome-github-actions` repository URL with the fork URL you created 109 | 110 | - Run it! 111 | 112 | ``` 113 | ./run.cmd 114 | ``` 115 | 116 | - Use this YAML in your workflow file for each job 117 | 118 | ```yaml 119 | runs-on: self-hosted 120 | ``` 121 | 122 | ### 3. Add a self-hosted docker runner to the `GitHub` repository. 123 | 124 | - Navigate to `awesome-github-actions/07-job-matrix/` folder 125 | 126 | ``` 127 | cd $HOME/awesome-github-actions/07-job-matrix 128 | ``` 129 | 130 | - Build a `docker` image 131 | 132 | 133 | ``` 134 | docker build -t runner:0.1 \ 135 | --build-arg REPO_URL=https://github.com/Alliedium/awesome-github-actions \ 136 | --build-arg TOKEN='AL24AMZNNIJVECQ34ANMH23ESNYCW' \ 137 | --build-arg LABELS='ubuntu-18.04' \ 138 | --build-arg RUNNER_NAME='docker-runner' \ 139 | -f $HOME/awesome-github-actions/07-job-matrix/Dockerfile \ 140 | $HOME/awesome-github-actions/07-job-matrix 141 | ``` 142 | 143 | Replace the `https://github.com/Alliedium/awesome-github-actions` repository URL with the fork URL you created 144 | 145 | - Run `docker` image 146 | 147 | ``` 148 | docker run --name runner -d runner:0.1 149 | ``` 150 | 151 | ### 4. Run workflow jobs on self-hosted Linux runners 152 | 153 | We used the `$HOME/awesome-github-actions/.github/workflows/07-job-matrix.yml` file as a workflow example for self-hosted runners. 154 | 155 | Copy `$HOME/awesome-github-actions/07-job-matrix/workflows/self-hosted-wf.yml` file content to `$HOME/awesome-github-actions/.github/workflows/07-job-matrix.yml` file. 156 | 157 | Workflow will execute on any runner that matches all the specified runs-on values 158 | This `runs-on: [ self-hosted, Linux ]` matches all self-hosted Linux runners. 159 | 160 | As you can see, the job runs on any self-hosted Linux runner, regardless of the version of the Linux distribution specified in the job 161 | 162 | ### 5. Run workflow jobs on self-hosted Linux runners that match the distribution version, specified in the job. 163 | 164 | Copy `$HOME/awesome-github-actions/07-job-matrix/workflows/self-hosted-labels-wf.yml` file content to `$HOME/awesome-github-actions/.github/workflows/07-job-matrix.yml` file. 165 | 166 | The job runs on a runner that matches the version of the Linux distribution specified in the job 167 | 168 | ### 6. Run workflow jobs in containers on Linux runners on which the docker is installed 169 | 170 | Copy `$HOME/awesome-github-actions/07-job-matrix/workflows/self-hosted-containers-wf.yml` file content to `$HOME/awesome-github-actions/.github/workflows/07-job-matrix.yml` file. 171 | 172 | ### 7. Debugging running workflow 173 | 174 | [Tmate](https://chat.openai.com/) is a terminal sharing software that allows users to share their command-line interface (CLI) sessions with others over the internet. 175 | Copy `$HOME/awesome-github-actions/07-job-matrix/workflows/self-hosted-labels-tmate-wf.yml` file content to `$HOME/awesome-github-actions/.github/workflows/07-job-matrix.yml` file. 176 | 177 | ``` 178 | cp $HOME/awesome-github-actions/07-job-matrix/workflows/self-hosted-labels-tmate-wf.yml $HOME/awesome-github-actions/.github/workflows/07-job-matrix.yml 179 | ``` 180 | 181 | This workflow will fail because running `npm test` without `npm ci`. 182 | `Tmate` will pause the job and establish a terminal session with the runner. 183 | 184 | ![tmate](./images/tmate.png) 185 | 186 | Fix the issue in the terminal. 187 | To exit the terminal, create a file with `continue` name. 188 | 189 | ### 8. Deleting runner from the repo 190 | 191 | ![delete_runner](./images/delete_runner.png) 192 | 193 | Navigate to the `actions-runner` folder and in the Runner terminal run the command 194 | 195 | ``` 196 | ./config.sh remove --token AL24AM5N3UAUQDRAKNU5XJDETDEBC 197 | ``` -------------------------------------------------------------------------------- /images/add_runner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alliedium/awesome-github-actions/a9f197fdb5d66192d9f90d8b3b0d2f980f9f925e/images/add_runner.png -------------------------------------------------------------------------------- /images/delete_runner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alliedium/awesome-github-actions/a9f197fdb5d66192d9f90d8b3b0d2f980f9f925e/images/delete_runner.png -------------------------------------------------------------------------------- /images/fork.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alliedium/awesome-github-actions/a9f197fdb5d66192d9f90d8b3b0d2f980f9f925e/images/fork.png -------------------------------------------------------------------------------- /images/tmate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alliedium/awesome-github-actions/a9f197fdb5d66192d9f90d8b3b0d2f980f9f925e/images/tmate.png --------------------------------------------------------------------------------