CurrentFHIRIG Template Back up simplifier project #3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CurrentFHIRIG Template Back up simplifier project | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 16 * */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 CurrentFHIRIGTemplate | |
rm -rf backup | |
mkdir -p backup | |
cd backup | |
wget --user ${{secrets.SIMPLIFIER_USER}} --password ${{secrets.SIMPLIFIER_PWD}} ${{ vars.CURRENTFHIRIGTEMPLATE_SIMPLIFIER_ADDRESS }} -O export.zip | |
unzip export.zip -x settings.style | |
mv export.zip .. | |
cd .. | |
- 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@v6 | |
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@v6" | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
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"}); | |
} | |