Andrea Maldonado commited on
Commit
2ea6510
·
1 Parent(s): 25b3700

Keeps sync_back.yml

Browse files
.github/workflows/{release_to_public.yml → sync_back.yml} RENAMED
@@ -1,19 +1,21 @@
1
  name: Merge and Push to Other Repository
2
 
3
  on:
4
- push:
5
  branches:
6
- - main # Trigger the workflow when changes are pushed to the main branch
 
 
7
 
8
  permissions:
9
  contents: write
10
  actions: read
11
-
12
  jobs:
13
  export_pr:
 
14
  runs-on: ubuntu-latest
15
  steps:
16
-
17
  # Step 1: Checkout the current repository
18
  - name: Checkout current repository
19
  uses: actions/checkout@v3
@@ -24,77 +26,53 @@ jobs:
24
  run: |
25
  REPO_NAME=${GITHUB_REPOSITORY#*/}
26
 
27
- # Step 2: Check for specific labels in commit messages
28
- - name: Check for specific labels
29
- id: label_check
30
- run: |
31
- # Fetch the last commit message
32
- COMMIT_MESSAGE=$(git log -1 --pretty=%B)
33
-
34
- # Define labels you want to check for
35
- LABELS=("release-candidate")
36
-
37
- # Initialize a flag
38
- MATCHING_LABEL=false
39
-
40
- # Check if any label is in the commit message
41
- for LABEL in "${LABELS[@]}"; do
42
- if [[ "$COMMIT_MESSAGE" == *"$LABEL"* ]]; then
43
- MATCHING_LABEL=true
44
- break
45
- fi
46
- done
47
-
48
- # Set the output based on the label check
49
- echo "matching_label=${MATCHING_LABEL}" >> $GITHUB_ENV
50
-
51
-
52
- # Step 3: Clone the target repository
53
  - name: Remove existing directory
54
- if: env.matching_label == 'true'
55
  run: |
56
- rm -rf ${{ vars.TARGET_DIR }} # Ensure the directory is clean before cloning
57
  - name: Clone target repository
58
  run: |
59
  git clone https://$GITHUB_ACTOR:${{ secrets.TARGET_REPO_PAT }}@github.com/${{ vars.TARGET_REPO }}.git
60
  cd ${{ vars.TARGET_DIR }}
61
  git checkout main # Ensure we are on the main branch
62
 
63
- # Step 4: Set Git user info
64
  - name: Set Git user info
65
  run: |
66
  cd ${{ vars.TARGET_DIR }}
67
  git config user.name "GitHub Actions" # Set a name for the user
68
  git config user.email "[email protected]" # Set an email for the user
69
 
70
- # Step 5: Fetch changes from the current repository
71
  - name: Fetch current repository changes
72
  run: |
73
  cd ${{ vars.TARGET_DIR }}
74
-
75
  git remote add current-repo ../ # Give it a descriptive name
76
  git fetch current-repo # Fetch from the current repo
 
77
  # Get the current branch name
78
  CURRENT_BRANCH=$(echo $GITHUB_REF | awk -F'/' '{print $3}') # Get the current branch name
 
79
  # Checkout the current branch from the current repository
80
  git checkout -b temp-branch current-repo/$CURRENT_BRANCH # Create a new branch based on the current repo's branch
81
 
82
- # Step 6: Merge the target repository's main into the temporary branch
83
  - name: Merge target repository's main into temp branch
84
  run: |
85
  cd ${{ vars.TARGET_DIR }}
86
  git merge -s ours origin/main --allow-unrelated-histories # Allow unrelated histories if necessary
87
 
88
- # Step 7: Push the merged changes to the target repository
89
  - name: Push merged changes to target repository
90
  run: |
91
  cd ${{ vars.TARGET_DIR }}
92
- git push origin temp-branch --force # Push the temporary branch to the target repo
93
 
94
- # Step 8: Create a PR from the temporary branch to the target repo's main
95
  - name: Create PR from temporary branch to target repo's main
96
  run: |
97
  curl -X POST -H "Authorization: token ${{ secrets.TARGET_REPO_PAT }}" \
98
  -H "Accept: application/vnd.github.v3+json" \
99
  https://api.github.com/repos/${{ vars.TARGET_REPO }}/pulls \
100
- -d "{\"title\":\"Merges $REPO_NAME (private) into main\",\"head\":\"temp-branch\",\"base\":\"main\",\"body\":\"Automated PR from GitHub Actions\"}"
 
1
  name: Merge and Push to Other Repository
2
 
3
  on:
4
+ pull_request:
5
  branches:
6
+ - main
7
+ types:
8
+ - closed
9
 
10
  permissions:
11
  contents: write
12
  actions: read
13
+
14
  jobs:
15
  export_pr:
16
+ if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main' && github.event.pull_request.head.ref == 'temp_branch'
17
  runs-on: ubuntu-latest
18
  steps:
 
19
  # Step 1: Checkout the current repository
20
  - name: Checkout current repository
21
  uses: actions/checkout@v3
 
26
  run: |
27
  REPO_NAME=${GITHUB_REPOSITORY#*/}
28
 
29
+ # Step 2: Clone the target repository
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  - name: Remove existing directory
 
31
  run: |
32
+ rm -rf ${{ env.TARGET_DIR }} # Ensure the directory is clean before cloning
33
  - name: Clone target repository
34
  run: |
35
  git clone https://$GITHUB_ACTOR:${{ secrets.TARGET_REPO_PAT }}@github.com/${{ vars.TARGET_REPO }}.git
36
  cd ${{ vars.TARGET_DIR }}
37
  git checkout main # Ensure we are on the main branch
38
 
39
+ # Step 3: Set Git user info
40
  - name: Set Git user info
41
  run: |
42
  cd ${{ vars.TARGET_DIR }}
43
  git config user.name "GitHub Actions" # Set a name for the user
44
  git config user.email "[email protected]" # Set an email for the user
45
 
46
+ # Step 4: Fetch changes from the current repository
47
  - name: Fetch current repository changes
48
  run: |
49
  cd ${{ vars.TARGET_DIR }}
50
+ # Add current repo as a remote
51
  git remote add current-repo ../ # Give it a descriptive name
52
  git fetch current-repo # Fetch from the current repo
53
+
54
  # Get the current branch name
55
  CURRENT_BRANCH=$(echo $GITHUB_REF | awk -F'/' '{print $3}') # Get the current branch name
56
+
57
  # Checkout the current branch from the current repository
58
  git checkout -b temp-branch current-repo/$CURRENT_BRANCH # Create a new branch based on the current repo's branch
59
 
60
+ # Step 5: Merge the target repository's main into the temporary branch
61
  - name: Merge target repository's main into temp branch
62
  run: |
63
  cd ${{ vars.TARGET_DIR }}
64
  git merge -s ours origin/main --allow-unrelated-histories # Allow unrelated histories if necessary
65
 
66
+ # Step 6: Push the merged changes to the target repository
67
  - name: Push merged changes to target repository
68
  run: |
69
  cd ${{ vars.TARGET_DIR }}
70
+ git push origin temp-branch # Push the temporary branch to the target repo
71
 
72
+ # Step 7: Create a PR from the temporary branch to the target repo's main
73
  - name: Create PR from temporary branch to target repo's main
74
  run: |
75
  curl -X POST -H "Authorization: token ${{ secrets.TARGET_REPO_PAT }}" \
76
  -H "Accept: application/vnd.github.v3+json" \
77
  https://api.github.com/repos/${{ vars.TARGET_REPO }}/pulls \
78
+ -d "{\"title\":\"Sync $REPO_NAME (public) into main\",\"head\":\"temp-branch\",\"base\":\"main\",\"body\":\"Automated PR from GitHub Actions\"}"