|
| 1 | +name: Upgrade |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + schedule: |
| 6 | + - cron: '00 23 * * *' |
| 7 | + |
| 8 | +jobs: |
| 9 | + upgrade: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + contents: write |
| 13 | + pull-requests: write |
| 14 | + env: |
| 15 | + GH_TOKEN: ${{ github.token }} |
| 16 | + steps: |
| 17 | + - name: Checkout vim-syslog-ng source |
| 18 | + uses: actions/checkout@v3 |
| 19 | + |
| 20 | + - name: Prepare environment |
| 21 | + run: | |
| 22 | + git config --global user.name "github-actions" |
| 23 | + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 24 | + python3 -m venv ~/venv |
| 25 | +
|
| 26 | + - name: Install syslog-ng-cfg-helper |
| 27 | + id: syslog-ng-cfg-helper |
| 28 | + run: | |
| 29 | + source ~/venv/bin/activate |
| 30 | + pip install syslog-ng-cfg-helper |
| 31 | + echo "version=$(pip show syslog-ng-cfg-helper | grep Version | cut -d' ' -f2)" >> "$GITHUB_OUTPUT" |
| 32 | + echo "db-file-path=$(find ~/venv -name syslog-ng-cfg-helper.db)" >> "$GITHUB_OUTPUT" |
| 33 | +
|
| 34 | + - name: Generate vim syntax highlight |
| 35 | + run: | |
| 36 | + ./generate "${{ steps.syslog-ng-cfg-helper.outputs.db-file-path }}" |
| 37 | +
|
| 38 | + - name: Open Pull Request if needed |
| 39 | + run: | |
| 40 | + CHANGES=$(git diff | grep "^[-\+]" | grep -v "syntax/syslog-ng\.vim\|Last Change" | wc -l) |
| 41 | + if [ $CHANGES -ne 0 ] |
| 42 | + then |
| 43 | + VERSION="${{ steps.syslog-ng-cfg-helper.outputs.version }}" |
| 44 | + BRANCH="syslog-ng-cfg-helper-$VERSION" |
| 45 | + EXISTING_PR=$(gh pr list --state open --head "$BRANCH" --json number --jq ". | length") |
| 46 | + if [ $EXISTING_PR -eq 0 ] |
| 47 | + then |
| 48 | + TITLE="syslog-ng-cfg-helper: $VERSION" |
| 49 | + BODY="Generate from https://pypi.org/project/syslog-ng-cfg-helper/$VERSION" |
| 50 | + git switch -c "$BRANCH" |
| 51 | + git commit -a -s -m "$TITLE" |
| 52 | + git push --force origin "$BRANCH" |
| 53 | + gh pr create --title "$TITLE" --body "$BODY" |
| 54 | + else |
| 55 | + echo "Pull Request already exists" |
| 56 | + fi |
| 57 | + else |
| 58 | + echo "No functional change" |
| 59 | + fi |
0 commit comments