|  | 
|  | 1 | +# Running Safe-settings with GitHub Actions (GHA) | 
|  | 2 | + | 
|  | 3 | +This guide describes how to schedule a full safe-settings sync using GitHub Actions. This assumes that an `admin` repository has been configured with your `safe-settings` configuration. Refer to the [How to Use](../README.md#how-to-use) docs for more details on that process. | 
|  | 4 | + | 
|  | 5 | + | 
|  | 6 | +## GitHub App Creation | 
|  | 7 | +Follow the [Create the GitHub App](deploy.md#create-the-github-app) guide to create an App in your GitHub account. This will allow `safe-settings` to access and modify your repos. | 
|  | 8 | + | 
|  | 9 | + | 
|  | 10 | +## Defining the GitHub Action Workflow | 
|  | 11 | +Running a full-sync with `safe-settings` can be done via `npm run full-sync`. This requires installing Node, such as with [actions/setup-node](https://github.com/actions/setup-node) (see example below). When doing so, the appropriate environment variables must be set (see the [Environment variables](#environment-variables) document for more details). | 
|  | 12 | + | 
|  | 13 | + | 
|  | 14 | +### Example GHA Workflow | 
|  | 15 | +The below example uses the GHA "cron" feature to run a full-sync every 4 hours. While not required, this example uses the `.github` repo as the `admin` repo (set via `ADMIN_REPO` env var) and the safe-settings configurations are stored in the `safe-settings/` directory (set via `CONFIG_PATH` and `DEPLOYMENT_CONFIG_FILE`). | 
|  | 16 | + | 
|  | 17 | +```yaml | 
|  | 18 | +name: Safe Settings Sync | 
|  | 19 | +on: | 
|  | 20 | +  schedule: | 
|  | 21 | +    - cron: "0 */4 * * *" | 
|  | 22 | +  workflow_dispatch: {} | 
|  | 23 | + | 
|  | 24 | +jobs: | 
|  | 25 | +  safeSettingsSync: | 
|  | 26 | +    runs-on: ubuntu-latest | 
|  | 27 | +    env: | 
|  | 28 | +      # Version/tag of github/safe-settings repo to use: | 
|  | 29 | +      SAFE_SETTINGS_VERSION: 2.1.13 | 
|  | 30 | + | 
|  | 31 | +      # Path on GHA runner box where safe-settings code downloaded to: | 
|  | 32 | +      SAFE_SETTINGS_CODE_DIR: ${{ github.workspace }}/.safe-settings-code | 
|  | 33 | +    steps: | 
|  | 34 | +      # Self-checkout of 'admin' repo for access to safe-settings config: | 
|  | 35 | +      - uses: actions/checkout@v4 | 
|  | 36 | + | 
|  | 37 | +      # Checkout of safe-settings repo for running full sync: | 
|  | 38 | +      - uses: actions/checkout@v4 | 
|  | 39 | +        with: | 
|  | 40 | +          repository: github/safe-settings | 
|  | 41 | +          ref: $SAFE_SETTINGS_VERSION | 
|  | 42 | +          path: $SAFE_SETTINGS_CODE_DIR | 
|  | 43 | +      - uses: actions/setup-node@v4 | 
|  | 44 | +      - run: npm install | 
|  | 45 | +        working-directory: $SAFE_SETTINGS_CODE_DIR | 
|  | 46 | +      - run: npm run full-sync | 
|  | 47 | +        working-directory: $SAFE_SETTINGS_CODE_DIR | 
|  | 48 | +        env: | 
|  | 49 | +          GH_ORG: ${{ vars.SAFE_SETTINGS_GH_ORG }} | 
|  | 50 | +          APP_ID: ${{ vars.SAFE_SETTINGS_APP_ID }} | 
|  | 51 | +          PRIVATE_KEY: ${{ secrets.SAFE_SETTINGS_PRIVATE_KEY }} | 
|  | 52 | +          GITHUB_CLIENT_ID: ${{ vars.SAFE_SETTINGS_GITHUB_CLIENT_ID }} | 
|  | 53 | +          GITHUB_CLIENT_SECRET: ${{ secrets.SAFE_SETTINGS_GITHUB_CLIENT_SECRET }} | 
|  | 54 | +          ADMIN_REPO: .github | 
|  | 55 | +          CONFIG_PATH: safe-settings | 
|  | 56 | +          DEPLOYMENT_CONFIG_FILE: ${{ github.workspace }}/safe-settings/deployment-settings.yml | 
|  | 57 | +``` | 
0 commit comments