0

I have a github repository A which uses another github repository B as a submodule. Both of which has their own github action.

Repo B can be run independently with its actions, and whenever I run repo A's workflow it will automatically pull the latest version of repo B before proceeding with the rest of its workflow.

Basically what i want is a way to install repo A with clone etc - but to update the submodule to the lastest commit where it's own test were successful. Such that if repo B has 5 new commits all failing, then if i install repo A it will not be those commits.

The github repo B workflow uses some code on a test data set to create some test output files and as such I have made a makefile to make a test checking the md5sums

name: Repo B workflow on: push: branches: ["main"] pull_request: branches: ["main"] jobs: build: runs-on: ${{ matrix.os }} defaults: run: shell: bash -l {0} strategy: matrix: os: ["ubuntu-latest"] python-version: ["3.11"] steps: # step 1: checkout repository - name: Checkout repository uses: actions/checkout@v3 # step 2 use environment.yml dependencies to create conda environment - name: Set up miniconda uses: conda-incubator/setup-miniconda@v3 with: auto-update-conda: true environment-file: environment.yml activate-environment: repoB_pipeline python-version: ${{ matrix.python-version }} # step 3 - name: Run test script run: | conda activate repoB_pipeline make test # Step 4: Creating a webhook with repository dispatch ... 

Once the md5sum has been cleared in step 3, then I am also ('trying'), because repo B is a submodule to set up in step 4 a webhook in the form of a repository dispatch referring to repo A. Such that when I push to repo B it will automatically activate repo A's workflow.

So, after step 3, I would like to somehow create a new step that updates a text file and logs the latest git commit only if step 3 passes. That way, when I clone and install my repo A, I can use git checkout to get the latest successful version of my submodule repo B where I know the tests pass. However, I am not sure how to do this without creating an infinite loop.

To add files within an action I can see you can do as such

- name: Commit Changes run: | echo "Current commit: $(git rev-parse HEAD)" > commit_info.txt git config --local user.name "github-actions[bot]" git config --local user.email "github-actions[bot]@users.noreply.github.com" git add commit_info.txt git commit -m "Update commit info after successful tests" 

However, this would create an infinite loop as it would activate the rest of the repo B workflow again. I can see other suggestions for pushing to a new branch. But are there any ways to simply add this to a main branch or is other branches necessary to solve this particular issue?

If I add it to a different branch of repo B, then as far as I understand, when installing repo A and the submodules, i need to change the submodule repo B branch, get the commit, switch back to the main branch, and then checkout to get the latest commit where the test passed - all to ensure repo A has the latest submodule that worked?

I hope my question makes sense - and I would appreciate any suggestions on how I can avoid any infinite loops while storing the latest successful git commits.

Best regards

Additional code to accommodate the suggestions in the comments below with tags: would this work or create an infinite loop?

on: push: branches: ["main"] tags: - "!**" pull_request: branches: ["main"] . . . # Step 4: Create tag if test in step 3 passes - name: Create tag if: ${{ success() }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | TAG_NAME="RepoB.$('%Y%m%d').${GITHUB_SHA::7}" git tag $TAG_NAME git push origin $TAG_NAME echo "Creating tag: $TAG_NAME" 
3

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.