Instantly share code, notes, and snippets.
Last active
October 7, 2023 07:01
-
Star
(0)
0
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save samitha9125/9936cf3bcba711e4d2569843345ed6ab to your computer and use it in GitHub Desktop.
Passing Runners to Shared/Reusable Workflow (Ideal for Self Hosted)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# GitHub Actions Workflow: Reusing the Shared Workflow | |
# | |
# Summary: | |
# This workflow shows the reuse of a shared workflow to perform preliminary setup tasks. | |
# It is triggered manually via the GitHub UI or through the GitHub REST API, and executes the shared | |
# workflow defined in '.github/workflows/shared-workflow.yml'. This shared workflow is expected to handle | |
# the installation of Yarn and CocoaPod dependencies. | |
# | |
# Triggers: | |
# - Manually triggered by users via the GitHub UI or through the GitHub REST API using the `workflow_dispatch` event. | |
# | |
# Jobs: | |
# - preliminary-setup: | |
# 1. Executes the shared workflow located at '.github/workflows/shared-workflow.yml'. | |
# 2. Inherits all secrets from the parent repository to the shared workflow. | |
# 3. Specifies a self-hosted runner tagged as 'self-hosted-workflow-specific-runner' for executing the job. | |
# | |
# Environment: | |
# - Utilizes a self-hosted runner tagged as 'self-hosted-workflow-specific-runner' to execute the shared workflow. | |
# - Inherits and utilizes secrets from the parent repository for any required authentication or configuration within the shared workflow. | |
# | |
# Usage: | |
# To trigger this workflow, navigate to the 'Actions' tab in the GitHub repository, select this workflow from the list, | |
# and click on 'Run workflow'. Alternatively, trigger it via the GitHub REST API with the necessary payload for the `workflow_dispatch` event. | |
name: Reusing the Shared Workflow | |
on: | |
workflow_dispatch: # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch | |
jobs: | |
preliminary-setup: | |
name: Yarn and CocoaPod Installation | |
uses: ./.github/workflows/shared-workflow.yml | |
secrets: inherit # Expose secrets to the reusable workflow, which are available in the current workflow. | |
with: | |
runner: self-hosted-workflow-specific-runner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# GitHub Actions Workflow: Yarn and Pod Installation (Example of Reusing a Flow) | |
# | |
# Summary: | |
# This workflow prepares the environment for any main workflows by executing setup tasks: | |
# 1. Generates a .env.personal file with configurations for a private npm registry (https://github.com/samitha9125/private-npm-setup) | |
# 2. Sets up the private npm registry. | |
# 3. Installs all project dependencies using yarn. | |
# | |
# Triggers: | |
# - Invoked by other workflows via the `workflow_call` event. It requires a 'runner' input to specify the runner to be used. | |
# | |
# Jobs: | |
# - yarn-setup: Performs three main steps as outlined in the Summary section. | |
# - pod-install: A separate job to handle Pod installations. | |
# | |
# Environment: | |
# - Utilizes environment variables for npm registry setup, fetched securely from GitHub secrets. | |
# - Executes on a self-hosted runner as specified by the 'runner' input parameter. | |
# | |
# Notes: | |
# In this example, a Private NPM Registery has been used. In your case, you may not need to do that. | |
# | |
name: Yarn Setup and Execution | |
on: | |
workflow_call: # https://docs.github.com/en/actions/using-workflows/reusing-workflows#creating-a-reusable-workflow | |
inputs: | |
runner: | |
description: 'The name of the runner to use.' | |
required: true | |
type: string | |
jobs: | |
yarn-setup: | |
name: Yarn Setup | |
runs-on: ['self-hosted', '${{ inputs.runner }}'] | |
env: | |
USERNAME: ${{ secrets.USERNAME }} | |
PERSONAL_ACCESS_TOKEN: ${{ secrets.PASSWORD }} | |
PRIVATE_REGISTRY_URL: 'https://npm.example.com' # Real URL of the registry. | |
SCOPE: 'scope' # Scope of the package. here, "scope" has been used as an example. | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Generate .env.personal file | |
run: | | |
echo "USERNAME=${{ env.USERNAME }}" > .env.personal | |
echo "PERSONAL_ACCESS_TOKEN=${{ env.PERSONAL_ACCESS_TOKEN }}" >> .env.personal | |
echo "PRIVATE_REGISTRY_URL=${{ env.PRIVATE_REGISTRY_URL }}" >> .env.personal | |
echo "SCOPE=${{ env.SCOPE }}" >> .env.personal | |
- name: Setup private npm | |
run: npx private-npm-setup@latest | |
- name: Install dependencies | |
run: yarn install | |
pod-install: | |
name: Pod Installation | |
runs-on: ['self-hosted', '${{ inputs.runner }}'] | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Install Pods | |
run: npx pod-install |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment