Skip to content

Commit 60eb047

Browse files
committed
Update github workflow
1 parent 663b608 commit 60eb047

File tree

1 file changed

+39
-22
lines changed

1 file changed

+39
-22
lines changed
Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,44 @@
1-
name: Push to remote repo on incoming push to this repo
2-
on: [ push, workflow_dispatch ]
1+
name: Push to ADO and create PR
2+
on:
3+
push:
4+
branches:
5+
- develop
6+
create: # trigger on tag creation
7+
workflow_dispatch: # trigger explicitly
38
jobs:
4-
push-to-remote:
9+
push-to-ado:
510
runs-on: ubuntu-latest
6-
if: github.ref == 'refs/heads/main' # run this job only for the main branch
11+
if: github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags/')
712
steps:
8-
- uses: actions/checkout@v3
13+
- uses: actions/checkout@v4
914
with:
10-
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of the personal access token.
11-
fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository.
12-
ref: main
13-
- name: Push checked out repo to remote
14-
env:
15-
URL: ${{ secrets.REMOTE_URL }}
16-
PAT: ${{ secrets.REMOTE_PAT }}
15+
ref: ${{ github.event_name == 'create' && 'main' || github.ref_name }}
16+
persist-credentials: false
17+
fetch-depth: 0
18+
- name: If triggered by tag, verify tag is on main branch
19+
if: startsWith(github.ref, 'refs/tags/')
1720
run: |
18-
echo -e "* On branch"
19-
echo -e "---"
20-
git branch --show-current
21-
echo -e "\n* List checked out contents of github repo"
22-
echo -e "---"
23-
ls -l
24-
echo -e "\n* Push main branch to remote repo"
25-
echo -e "---"
26-
# git -c http.extraheader="Authorization: Basic $PAT" push --force $URL main
27-
git -c http.extraheader="Authorization: Basic $PAT" push $URL main:temp
21+
TAG_COMMIT_SHA="${{ github.sha }}"
22+
if ! git log --first-parent --pretty=format:%H "refs/heads/main" | grep -q "^$TAG_COMMIT_SHA$"; then
23+
echo "Tag '${{ github.ref_name }}' is not on main, skipping push"
24+
exit 1
25+
fi
26+
- name: Push to ADO
27+
run: |
28+
SOURCE_BRANCH="${{ github.event_name == 'create' && 'main' || github.ref_name }}"
29+
TARGET_REMOTE_BRANCH="${SOURCE_BRANCH}"
30+
if [ "${SOURCE_BRANCH}" == "main" ]; then
31+
TARGET_REMOTE_BRANCH="release"
32+
fi
33+
echo "Pushing ${SOURCE_BRANCH} (github)) to ${TARGET_REMOTE_BRANCH} (${vars.REMOTE_REPO_URL})..."
34+
git -c http.extraheader="Authorization: Basic ${{ secrets.REMOTE_PAT }}" push --force "${{ vars.REMOTE_REPO_URL }}" "${SOURCE_BRANCH}:${TARGET_REMOTE_BRANCH}"
35+
create-ado-pr:
36+
runs-on: ubuntu-latest
37+
needs: push-to-ado
38+
if: startsWith(github.ref, 'refs/tags/')
39+
steps:
40+
- name: Create ADO pull request
41+
run: |
42+
echo "Creating Pull Request from 'release' to 'main' in Azure DevOps for tag '${{ github.ref_name }}'..."
43+
curl -X POST -H "Content-Type: application/json" -H "Authorization: Basic ${{ secrets.REMOTE_PAT }}" "${{ vars.REMOTE_PR_URL }}" \
44+
-d "{ \"sourceRefName\": \"refs/heads/release\", \"targetRefName\": \"refs/heads/main\", \"title\": \"Automated PR: ${{ github.ref_name }}\" }"

0 commit comments

Comments
 (0)