A CI/CD pipeline in GitHub needs to first push code from the dev
branch to the test
branch, and then immediately run a workflow on the test
branch as soon as code has been pushed into the test
branch.
The dev-environ-workflow
below does successfully push code from the dev
branch into the test
branch when code is pushed into the dev
branch from a devbox outside of GitHub.
The problem is that the test-environ-workflow
fails to run when code is pushed into the test
branch from the dev-environ-workflow
.
Any GitHub account can reproduce this problem with only three files and the following structure:
.gihub/workflows/
dev-workflow.yaml
test-workflow.yaml
myapp.py
myapp.py
:
print('Hello from myapp!')
dev-workflow.yaml
:
name: dev-environ-workflow
on:
push:
branches:
- dev
jobs:
push-to-test-branch:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- shell: bash
name: Push changes to test branch
env:
GIT_PAT: ${{ secrets.GIT_PAT }}
run: |
repoWithToken="https://"$GIT_PAT"@github.com/myAccountName/trigger.git"
git config --global user.email "me@mydomain.com"
git config --global user.name "myAccountName"
git init
git remote set-url origin $repoWithToken
git branch -M test
git add --all
git push --force -u origin test
test-workflow.yaml
:
name: test-environ-workflow
on:
push:
branches:
- test
jobs:
push-to-test-branch:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- shell: bash
name: Do anything
run: echo "Successfully triggered test-environ-workflow"
The commands to trigger the dev-environ-workflow
from a remote devbox anywhere on the internet outside of GitHub are:
git init
git add --all
git commit -m "some changes"
git branch -M dev
git push -u origin dev
You also need to create an environment variable for the GitHub repository called GIT_PAT
which contains a personal access token that will be used to push code into the test
branch.
What specifically needs to change in the above in order for the test-environ-workflow
to be successfully triggered whenever the dev-environ-workflow
successfully pushes code into the test
branch?