-
Notifications
You must be signed in to change notification settings - Fork 0
90 lines (79 loc) · 3.17 KB
/
GPConnectDirectCareAPIs-R4.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
89
name: GPConnectDirectCareAPIs-R4 Back up simplifier project
on:
workflow_dispatch:
schedule:
- cron: '0 18 1 * *'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set today
id: today
run: echo "TODAY=$(date)" >> $GITHUB_OUTPUT
- name: Set branch name
id: branch-name
run: echo "BRANCH=$(echo ${{ steps.today.outputs.TODAY }} | tr -d '[:space:]' | tr -d ':')" >> $GITHUB_OUTPUT
- name: Download and commit simplifier source code
run: |
cd GPConnectDirectCareAPIs-R4
rm -rf backup
mkdir -p backup
cd backup
wget --user ${{secrets.SIMPLIFIER_USER}} --password ${{secrets.SIMPLIFIER_PWD}} ${{ vars.GPCONNECTDIRECTCAREAPISR4_SIMPLIFIER_ADDRESS }} -O export.zip
unzip export.zip -x settings.style
mv export.zip ..
cd ..
export NUMLINES=$(wc -l < README.md) #Updates README file. Shows when last updated but also used to ensure changes made for the PR / merge steps below
export NUMLINES=$(($NUMLINES-2))
head -$NUMLINES README.md > README1.md
echo "" >> README1.md
echo "Updated at: $(date)" >> README1.md
mv README1.md README.md
- name: Create branch and commit
run: |
git config --global user.name "Workflows.Backup"
git config --global user.email "[email protected]"
git checkout -b ${{ steps.branch-name.outputs.BRANCH }}
git add -A
git commit -m "${{ steps.today.outputs.TODAY }}"
git push origin ${{ steps.branch-name.outputs.BRANCH }}
- name: Create Pull Request
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { repo, owner } = context.repo;
const result = await github.rest.pulls.create({
title: '${{ steps.today.outputs.TODAY }}',
owner,
repo,
head: '${{ steps.branch-name.outputs.BRANCH }}',
base: 'main',
body: [
'This PR is auto-generated by',
'[actions/github-script](https://github.com/actions/github-script).'
].join('\n')
});
github.rest.issues.addLabels({
owner,
repo,
issue_number: result.data.number,
labels: ['backup', 'automated pr']
});
- name: "Merge pull request"
uses: "actions/github-script@v7"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
retries: 5
script: |
const { repo, owner } = context.repo;
const head = '${{ steps.branch-name.outputs.BRANCH }}'
await new Promise(r => setTimeout(r, 2000));
const { data } = await github.rest.pulls.list({ owner, repo, head, per_page: 1 });
if (data.length) {
const pull_number = data[0].number;
await github.rest.pulls.merge({ owner, repo, pull_number, merge_method: "squash"});
}