Back up simplifier project #392
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: Back up simplifier project | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 12,16,19 * * *' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.REPO_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: Update README | |
run: | | |
export NUMLINES=$(wc -l < README.md) | |
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: Download and commit simplifier source code | |
run: | | |
mkdir -p backup | |
cd backup | |
git rm -rf * | |
wget --user ${{secrets.SIMPLIFIER_USER}} --password ${{secrets.SIMPLIFIER_PWD}} ${{ vars.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 '{{ vars.COMITTER_NAME }}' | |
git config --global user.email '${{ secrets.COMITTER }}' | |
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.REPO_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.REPO_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"}); | |
} | |