-
Notifications
You must be signed in to change notification settings - Fork 0
88 lines (88 loc) · 3.78 KB
/
clone.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
name: Pull latest changes from quickstart repository
on:
workflow_dispatch:
schedule:
- cron: '0 13 * * 1'
jobs:
pull-request-source-repo:
name: Create pull request
runs-on: ubuntu-latest
env:
WORKING_BRANCH: auto
steps:
- name: Get GitHub App token
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ secrets.PORTAL_QUICKSTART_SYNCHRONIZER_APP_ID }}
private-key: ${{ secrets.PORTAL_QUICKSTART_SYNCHRONIZER_PRIVATE_KEY }}
- name: Checkout source repository
uses: actions/checkout@v4
with:
repository: azure-samples/cosmos-db-nosql-java-quickstart
ref: main
path: source
- name: Checkout target repository
uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
ref: ${{ github.head_ref }}
path: target
- name: Get GitHub App User ID
id: get-user-id
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
- name: Configure git
working-directory: target
run: |
git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]'
git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com>'
- name: Generate date variables
run: |
echo "CURRENT_DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
echo "WORKING_BRANCH=auto-$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV
- name: Create working branch
working-directory: target
run: git checkout -b $WORKING_BRANCH
- name: Clear existing project
working-directory: target
run: |
shopt -s extglob
rm -rf !(".devcontainer"|".github"|"LICENSE"|"readme.md")
- name: Copy source to target
run: cp -ra source/src/web/. target/
- name: Change text content
working-directory: target
run: |
content=$(cat .github/workflows/replace.java)
awk -v content="$content" '
BEGIN { in_block = 0 }
/^\s*\/\/ <create_client>/ { in_block = 1; print content; next }
/^\s*\/\/ <\/create_client>/ { in_block = 0; next }
!in_block { print }
' src/main/java/com/microsoft/learn/azure/cosmosdb/nosql/quickstart/CosmosConfiguration.java > src/main/java/com/microsoft/learn/azure/cosmosdb/nosql/quickstart/CosmosConfiguration.tmp.java && mv src/main/java/com/microsoft/learn/azure/cosmosdb/nosql/quickstart/CosmosConfiguration.tmp.java src/main/java/com/microsoft/learn/azure/cosmosdb/nosql/quickstart/CosmosConfiguration.java
- name: Add changes to git
working-directory: target
run: |
git add .
- name: Check if files are changed
id: check-files
working-directory: target
run: |
echo "status=$(git diff --shortstat --staged)" >> $GITHUB_OUTPUT
- name: Commit and push changes
if: ${{ steps.check-files.outputs.status != '' }}
working-directory: target
run: |
git commit -m "Automatically generated commit"
git push --set-upstream origin $WORKING_BRANCH
- name: Create auto-merge pull request
if: ${{ steps.check-files.outputs.status != '' }}
working-directory: target
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
url=$(gh pr create --title "[AUTO] $CURRENT_DATE | Merge latest from source repo" --body "${{ steps.check-files.outputs.status}}" --base main --head $WORKING_BRANCH)
gh pr merge --auto --merge $url
echo $url