|
| 1 | +name: Create template upgrade PR for bec_testing_plugin |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + |
| 5 | +permissions: |
| 6 | + pull-requests: write |
| 7 | + |
| 8 | +jobs: |
| 9 | + create_update_branch_and_pr: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + contents: write |
| 13 | + pull-requests: write |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Setup Python |
| 17 | + uses: actions/setup-python@v5 |
| 18 | + with: |
| 19 | + python-version: '3.12' |
| 20 | + |
| 21 | + - name: Checkout |
| 22 | + uses: actions/checkout@v4 |
| 23 | + |
| 24 | + - name: Create virtualenv |
| 25 | + run: | |
| 26 | + python -m virtualenv .venv |
| 27 | + |
| 28 | + - name: Install tools |
| 29 | + run: | |
| 30 | + source .venv/bin/activate |
| 31 | + pip install copier PySide6 bec_lib |
| 32 | + |
| 33 | + - name: Perform update |
| 34 | + run: | |
| 35 | + source .venv/bin/activate |
| 36 | + git config --global user.email "bec_ci_staging@psi.ch" |
| 37 | + git config --global user.name "BEC automated CI" |
| 38 | + |
| 39 | + branch="chore/update-template-$(python -m uuid)" |
| 40 | + echo "switching to branch $branch" |
| 41 | + git checkout -b $branch |
| 42 | + |
| 43 | + echo "Running copier update..." |
| 44 | + copier update --trust --defaults --conflict inline 2>&1 | tee copier.log |
| 45 | + status=${PIPESTATUS[0]} |
| 46 | + output="$(cat copier.log)" |
| 47 | + echo $output |
| 48 | + msg="$(printf '%s\n' "$output" | head -n 1)" |
| 49 | + |
| 50 | + if ! grep -q "make_commit: true" .copier-answers.yml ; then |
| 51 | + echo "Autocommit not made, committing..." |
| 52 | + git add -A |
| 53 | + git commit -a -m "$msg" |
| 54 | + fi |
| 55 | + |
| 56 | + if diff-index --quiet HEAD ; then |
| 57 | + echo "No changes detected" |
| 58 | + exit 0 |
| 59 | + fi |
| 60 | + |
| 61 | + git push -u origin $branch |
| 62 | + curl -X POST "https://gitea.psi.ch/api/v1/repos/${{ gitea.repository }}/pulls" \ |
| 63 | + -H "Authorization: token ${{ secrets.CI_REPO_WRITE }}" \ |
| 64 | + -H "Content-Type: application/json" \ |
| 65 | + -d "{ |
| 66 | + \"title\": \"Template: $(echo $msg)\", |
| 67 | + \"body\": \"This PR was created by Gitea Actions\", |
| 68 | + \"head\": \"$(echo $branch)\", |
| 69 | + \"base\": \"main\" |
| 70 | + }" |
0 commit comments