ClinicalObservations Back up simplifier project #15
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: ClinicalObservations 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 ClinicalObservations | ||
rm -rf backup | ||
mkdir -p backup | ||
cd backup | ||
wget --user ${{secrets.SIMPLIFIER_USER}} --password ${{secrets.SIMPLIFIER_PWD}} ${{ vars.CLINICALOBSERVATIONS_SIMPLIFIER_ADDRESS }} -O export.zip | ||
unzip export.zip -x settings.style | ||
rm -f export.zip | ||
cd .. | ||
- name: Sleep random #Used to stop error due to multiple actions wanting PRs to be merged at the same time | ||
run: sleep $((RANDOM % 59))s #sleeps for a random number of minutes and seconds | ||
- name: Check for changes #If no changes found then exit action, otherwise pass | ||
run: | | ||
if git diff --exit-code; then | ||
echo "No changes detected" | ||
exit 0 | ||
else | ||
"Changes detected" | ||
fi | ||
- 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 | ||
if: git diff --exit-code | ||
Check failure on line 58 in .github/workflows/ClinicalObservations.yml GitHub Actions / ClinicalObservations Back up simplifier projectInvalid workflow file
|
||
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"}); | ||
} | ||