Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

GitHub action triggered by somebody else's repository

+6
−0

Consider the following situation:


To make sure that my package stays compatible with the development of the class, I'd like to regularly run a GitHub Action in my repository to test this. At the moment, I run it on a schedule once a week:

name: Check with current ltx-talk

on:
  schedule:
    - cron: '47 13 * * 3'

Is it somehow possible to trigger this action based on events in the ltx-talk repository? For example every time a new version gets released or for every commit? I've read about repository_dispatch, but it seems this would require changes in the triggering repository.

In case it helps, I also have a fork of the ltx-talk repository, which is automatically kept up-to-date using Probot Pull.

History

4 comment threads

Fork + repositorydispatch (4 comments)
What about git submodule? (5 comments)
Use a third service? (1 comment)
I also want this (4 comments)

2 answers

+4
−0

Facing a somewhat similar situation, I took mr Tsolder's suggestion of looking into submodules.

In my case, it was fine to keep the remote project as a folder in my local clone, but I think it still works if you don't want the copy in your worktree. Just git submodule deinit Joseph Wright's repo.

Then, I made a Dependabot instruction to make a PR if it detected that the remote project had updates:

version: 2
updates:
  - package-ecosystem: gitsubmodule
    schedule:
        interval: daily
    directory: /

That was the flow I wanted to make sure that my code could handle the dependency before pushing to master: running CI and adding my own commits to the PR if needed.

But if you're happy to push submodule changes directly, you can do that with a GitHub Action:

name: Update submodules
on:
  schedule:
    - cron:  '0 * * * *'

jobs:
  update_submodules:
    name: Update submodules
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
      with:
        submodules: recursive
    - name: Update submodules
      id: update
      run: git submodule update --remote --recursive 
    - name: Add and commit files
      run: |
        git add .
        git config --local user.email "[email protected]"
        git config --local user.name "GitHub Action"
        git commit -m "Update submodules at $(date "+DATE: %Y-%m-%d TIME: %H:%M:%S")"
      if: ${{ steps.status.outputs.status }}
    - name: Push changes
      uses: ad-m/github-push-action@master
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
        branch: main
      # if: ${{ steps.status.outputs.status && github.event_name == 'push' }}

The submodule approach doesn't eliminate a cron completely (see the schedule key in the two YAML snippets above), but it's no more delay than triggering actions from your Probot-synced fork.

History

1 comment thread

Thanks a lot for your answer! (1 comment)
+2
−0

None of the below is tested, but logically should work.

  1. In your fork, configure probot pull to use the merge strategy instead of its default hardreset. A git merge will mix your changes with the upstream changes, whereas hardreset will 'reset' your fork to look like the upstream. That would be bad since we're adding new files. This involves adding a new file .github/pull.yml to the default branch of your fork (in this case main). Docs

    version: "1"
    rules:
      - base: main
        # Not fully sure if this is correct but its either this
        # or 'josephwright/ltx-talk:main'
        upstream: josephwright:main
        mergeMethod: merge
        # Reading the docs, I think this stops merges that have
        # conflicts. We wouldn't expect conflicts in this strategy,
        # but if they do occur we want to be notified through the
        # failure so we can address it. Flip to true if it's giving
        # you grief.
        mergeUnstable: false
    
  2. In your fork, add a new workflow in the .github/workflows/ folder that triggers off commits on the main branch. This workflow will use repository_dispatch to trigger the workflow in all other repositories. Docs

    name: trigger-remote-repo
    run-name: Triggering action in remote repository
    on:
      push:
        branches:
          - main
    jobs:
      trigger-remote:
        runs-on: ubuntu-latest
        steps:
          - name: Dispatch event to remote repository
            uses: peter-evans/repository-dispatch@v4
            with:
              token: ${{ secrets.PAT }}
              repository: samcarter/beamertheme-spectrum
              event-type: any-old-event-name
    
    • Note this requires you to set up a personal access token (technically you should use fine-grained-access tokens, but that's something I'd go back and fix after getting everything working first.). Then store that token in secrets with the name PAT. I would use the organizational secrets which should make that secret available to all your repositories. But if that doesn't work store it directly in the forked repo's secrets.
  3. In your personal repository, create/update your workflow to respond to that event. Example

    name: update-from-upstream
    run-name: An event occurred in the upstream repository
    
    # This is the relevant bit. Make sure the event type matches
    # the name you used in the fork.
    on:
      repository_dispatch:
        types: [any-old-event-name]
    
    # Do whatever you need to. I'd assume this'd be the same job
    # as in the cron workflow you already made.
    jobs:
      respond-to-event:
        runs-on: ubuntu-latest
        steps:
          - shell: bash
            run: |
              echo "Doing whatever I needed to do."
    
History

1 comment thread

Thanks a lot for your answer! (1 comment)

Sign up to answer this question »