Skip to content

Commit

Permalink
Add new "Check the label 'Needs autoupgrade PR'" workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
M0rgan01 committed May 6, 2024
1 parent fc70da9 commit 28af954
Showing 1 changed file with 108 additions and 0 deletions.
108 changes: 108 additions & 0 deletions .github/workflows/check_need_autoupgrade_pr_label.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# This workflow allows you to check potential changes to the structure of the database,
# and to apply the “Needs autoupgrade PR” label if this is the case
name: Check the label 'Needs autoupgrade PR'

on: pull_request_target

jobs:
install_prestashop_and_dump_base:
name: Install Prestashop and create database dump for base branch
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Docker build
run: docker compose build prestashop-git

- name: Build dependency
run: docker compose run --rm prestashop-git composer install --ansi --prefer-dist --no-interaction --no-progress

- name: Create base database
run: docker compose run --rm mysql mysql -hmysql -uroot -pprestashop -e "CREATE DATABASE presta_base;"

- name: Install shop
run: docker compose run --rm prestashop-git php install-dev/index_cli.php \
--step=database --db_server=mysql:3306 --db_name=presta_base --db_user=root --db_password=prestashop --prefix=ps_ --db_clear=1 \
--domain=localhost:8001 --firstname="Marc" --lastname="Beier" \
--password=Toto123! [email protected] --language=fr --country=fr \
--newsletter=0 --send_email=0 --ssl=0

- name: Export dump
run: docker compose run --rm mysql sh -c "exec mysqldump -hmysql -uroot --no-data --compact -pprestashop presta_base" > dump_base.sql

- name: Upload dump
uses: actions/upload-artifact@v4
with:
name: dump_base
path: |
dump_base.sql
install_prestashop_and_dump_head:
name: Install Prestashop and create database dump for head branch
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}

- name: Docker build
run: docker compose build prestashop-git

- name: Build dependency
run: docker compose run --rm prestashop-git composer install --no-interaction

- name: Create head database
run: docker compose run --rm mysql mysql -hmysql -uroot -pprestashop -e "CREATE DATABASE presta_head;"

- name: Install shop
run: docker compose run --rm prestashop-git php install-dev/index_cli.php \
--step=database --db_server=mysql:3306 --db_name=presta_head --db_user=root --db_password=prestashop --prefix=ps_ --db_clear=1 \
--domain=localhost:8001 --firstname="Marc" --lastname="Beier" \
--password=Toto123! [email protected] --language=fr --country=fr \
--newsletter=0 --send_email=0 --ssl=0

- name: Export dump
run: docker compose run --rm mysql sh -c "exec mysqldump -hmysql -uroot --no-data --compact -pprestashop presta_head" > dump_head.sql

- name: Upload dump
uses: actions/upload-artifact@v4
with:
name: dump_head
path: |
dump_head.sql
create_diff:
name: Create database dumps diff
needs: [install_prestashop_and_dump_base, install_prestashop_and_dump_head]

Check failure on line 76 in .github/workflows/check_need_autoupgrade_pr_label.yml

View workflow job for this annotation

GitHub Actions / YAML Lint (YamlLint Check)

76:13 [brackets] too few spaces inside brackets

Check failure on line 76 in .github/workflows/check_need_autoupgrade_pr_label.yml

View workflow job for this annotation

GitHub Actions / YAML Lint (YamlLint Check)

76:79 [brackets] too few spaces inside brackets
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4

- name: Create diff
run: git diff ./dump_head/dump_head.sql ./dump_base/dump_base.sql > sql-diff.txt | true

- name: Upload diff
uses: actions/upload-artifact@v4
with:
name: sql_diff
path: |
sql-diff.txt
update_label:
name: Update Needs autoupgrade PR label
needs: [create_diff]

Check failure on line 93 in .github/workflows/check_need_autoupgrade_pr_label.yml

View workflow job for this annotation

GitHub Actions / YAML Lint (YamlLint Check)

93:13 [brackets] too few spaces inside brackets

Check failure on line 93 in .github/workflows/check_need_autoupgrade_pr_label.yml

View workflow job for this annotation

GitHub Actions / YAML Lint (YamlLint Check)

93:24 [brackets] too few spaces inside brackets
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4

- run: |
if [ -s sql_diff/sql-diff.txt ]; then
gh pr edit "$NUMBER" --add-label "$LABELS"
else
gh pr edit "$NUMBER" --remove-label "$LABELS"
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
NUMBER: ${{ github.event.number }}
LABELS: Needs autoupgrade PR

0 comments on commit 28af954

Please sign in to comment.