-
Notifications
You must be signed in to change notification settings - Fork 1
90 lines (78 loc) · 2.99 KB
/
update-carbon-aware-sdk.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
90
name: Update carbon-aware SDK
on:
schedule:
- cron: '0 3 * * *' # run at 03 AM UTC
workflow_dispatch:
jobs:
update-carbon-aware-sdk:
runs-on: ubuntu-latest
steps:
- name: checkout-code
uses: actions/[email protected]
with:
submodules: true
- name: pull-carbon-aware-sdk
id: pull-carbon-aware-sdk
run: |
status=$(git submodule update --remote)
echo "Status returned by submodule: ${status}"
if [ "$status" == "" ]; then
echo "No carbon-aware SDK updates detected; Skipping run..."
echo "continue=false" >> $GITHUB_OUTPUT
exit 0
fi
echo "continue=true" >> $GITHUB_OUTPUT
echo "Changes to carbon-aware SDK detected; updating local branch..."
- name: build-service
if: steps.pull-carbon-aware-sdk.outputs.continue == 'true'
run: dotnet build ./src/Greenhopper.sln
# todo: run tests
- name: build-sample
if: steps.pull-carbon-aware-sdk.outputs.continue == true
run: dotnet build ./sample/timer-trigger/CarbonAware.AzureFunction.Sample.sln
- name: create-new-branch-with-changes
if: steps.pull-carbon-aware-sdk.outputs.continue == true
id: push_output
run: |
branchbasename=carbon-aware-sdk-$(date +"%Y.%m.%d-%H.%M.%S")-${{ github.run_number }}
branchname=feature/${branchbasename}
git config user.name blogbot
git config user.email [email protected]
git pull
git branch ${branchname}
git push --set-upstream origin ${branchname}
git checkout ${branchname}
git add .
git commit --allow-empty -m "New carbon-aware-version-merged"
git push
echo "::set-output name=branchname::${branchname}"
- name: pull-request
if: steps.pull-carbon-aware-sdk.outputs.continue == true
uses: actions/github-script@v6
with:
script: |
title = 'Better double check this PR, it shouldnt be here!'
if( '${{ github.event_name }}' == 'schedule' ) {
title = '[Nightly Build] carbon-aware-sdk updated by a schedule.'
}
if( '${{ github.event_name }}' == 'workflow_dispatch' ) {
title = '[Manual Trigger] User ${{ github.actor }} triggered a carbon-aware-sdk update.'
}
const { repo, owner } = context.repo;
const pr = await github.rest.pulls.create({
title: title,
owner,
repo,
head: '${{ steps.push_output.outputs.branchname }}',
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: pr.data.number,
labels: ['${{ github.event_name }}', 'automated-pr']
});