Skip to content

Update carbon-aware SDK #207

Update carbon-aware SDK

Update carbon-aware SDK #207

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/checkout@v3.0.0
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 blogbot@github.com
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']
});