Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to run safe-settings as GitHub Action? #378

Open
martinm82 opened this issue Jan 11, 2023 · 12 comments
Open

Possibility to run safe-settings as GitHub Action? #378

martinm82 opened this issue Jan 11, 2023 · 12 comments
Labels
enhancement New feature or request

Comments

@martinm82
Copy link
Contributor

Prerequisites:

  • Is the functionality available in the GitHub UI? If so, please provide a link to information about the feature.

New Feature

Based on the Probot docs there is an GitHub Action adapter which should allow running Probot apps as Actions. Would this be possible as well with safe-settings?

https://probot.github.io/docs/deployment/#github-actions

@martinm82 martinm82 added the enhancement New feature or request label Jan 11, 2023
@niraj8
Copy link
Contributor

niraj8 commented Feb 27, 2023

There are 2 ways I think we could run this in Github Actions

  • On a schedule that does a full reconciliation , i.e. check that all settings across all repositories in the org match the desired settings from the admin repo, similar to [Question] Safe-settings cron with lambda via serverless #313
  • Trigger a GH workflow that runs safe-settings app with the webhook payload event to a Github workflow with inputs in workflow_dispatch [example]

@dolan-a
Copy link
Contributor

dolan-a commented Feb 28, 2024

I have a prototype of this on my repo fork, which adds a new script for calling syncInstallation (if people like this approach, I can open a PR, but I'll have to separate it from my changes on #588 update: PR opened in #604):

diff --git a/full-sync.js b/full-sync.js
new file mode 100644
index 0000000..7881056
--- /dev/null
+++ b/full-sync.js
@@ -0,0 +1,6 @@
+const { createProbot } = require('probot')
+const appFn = require('./')
+
+const probot = createProbot()
+const app = appFn(probot, {})
+app.syncInstallation()
diff --git a/package.json b/package.json
index 6bfb4ce..624f429 100644
--- a/package.json
+++ b/package.json
@@ -7,6 +7,7 @@
   "scripts": {
     "dev": "nodemon --inspect",
     "start": "probot run ./index.js",
+    "full-sync": "node ./full-sync.js",
     "test": "npm-run-all --print-label --parallel lint:* --parallel test:*",
     "lint:es": "eslint .",
     "lint:js": "standard",

To use this as an action, I pull the safe-settings code, pass along the env secrets via GitHub secrets, and run in as the action:

name: Safe Settings Sync
on:
  schedule:
    # daily run:
    - cron:  '0 0 * * *'
  workflow_dispatch: {}

jobs:
  safeSettingsSync:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          repository: pydolan/safe-settings
          ref: gha-runner
      - uses: actions/setup-node@v4
      - run: npm install
      - run: npm run full-sync
        env:
          GH_ORG: my-org
          APP_ID: my-app-id
          PRIVATE_KEY: ${{ secrets.SAFE_SETTINGS_PRIVATE_KEY }}
          GITHUB_CLIENT_ID: ${{ secrets.SAFE_SETTINGS_GITHUB_CLIENT_ID }}
          GITHUB_CLIENT_SECRET: ${{ secrets.SAFE_SETTINGS_GITHUB_CLIENT_SECRET }}

Regarding Probot's GHA Adapter -- I initially used this in my separate script (similar to what handler.js does with the Serverless adapter), but this adapter uses the Action's GITHUB_TOKEN, which is limited to the current repo, so it offers no benefit that I can see.

Regarding my use of actions/checkout -- I would prefer to run safe-settings as an action using the Dockerfile, but GHA targets a different WORKDIR when doing so. There's an open issue about allowing workdir overrides with GHA.

@beatngu13
Copy link

There's now documentation on how to run GitHub Safe-Settings via GitHub Actions, at least for a full-sync:

https://github.com/github/safe-settings/blob/main-enterprise/docs/github-action.md

@paddyroddy
Copy link

If still unclear, I've got it working in practice https://github.com/UCL-MIRSG/.github/blob/main/.github/workflows/safe-settings.yaml.

@beatngu13
Copy link

@paddyroddy even with Renovate Custom Manager – thank you! 🙏

@paddyroddy
Copy link

@paddyroddy even with Renovate Custom Manager – thank you! 🙏

No problem, I will add docs to the README here soon 😅 spent a fair bit of time debugging beforehand

@riprasad
Copy link

riprasad commented Dec 28, 2024

@paddyroddy Thank you for sharing a working example — it was very helpful!

Couple of Questions:

  • What's the purpose of using renovate in conjunction with safe-settings?
  • Do you know if we can run the GHA workflow in NOP mode?

@beatngu13
Copy link

What's the purpose of using renovate in conjunction with safe-settings?

In our case, Renovate makes sure that the GHA workflow gets updated when a new GH Safe-Settings version is available.

@paddyroddy
Copy link

  • What's the purpose of using renovate in conjunction with safe-settings?

As @beatngu13 said, I want the SAFE_SETTINGS_VERSION: 2.1.14 version to keep up-to-date. If it was a traditional GHA then @renovatebot supports it natively with the @vx bit. I've set up a regex to maintain this environment variable.

  • Do you know if we can run the GHA workflow in NOP mode?

Sorry, I'm not sure what you mean by NOP here.

@riprasad
Copy link

riprasad commented Jan 7, 2025

@paddyroddy Thanks for explaining the use of renovate!

Sorry, I'm not sure what you mean by NOP here.

It's kind of a dry run which also produces a report. See here

In that set up, when changes happen to the settings files and there is a PR for merging the changes back to the default branch in the admin repo, safe-settings will run checks – which will run in nop mode and produce a report of the changes that would happen, including the API calls and the payload.

I saw that you’ve set your safe-settings workflow to trigger on the pull request event. I tried the same, assuming the workflow would be a dry run when triggered by a pull request. However, it turns out the changes are applied directly instead of just being a dry run.

@paddyroddy
Copy link

I saw that you’ve set your safe-settings workflow to trigger on the pull request event. I tried the same, assuming the workflow would be a dry run when triggered by a pull request. However, it turns out the changes are applied directly instead of just being a dry run.

I have found this too. I assume it might be a bug? In theory, I have them turned on https://github.com/UCL-MIRSG/.github/blob/4695e545829b91dcddc6e36358454bc4a879f751/.github/workflows/safe-settings.yaml#L59C11-L59C34

@riprasad
Copy link

riprasad commented Jan 7, 2025

Looks like a bug, Yeah!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants