Skip to content

Commit

Permalink
UHF-11137: Reusable workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
tuutti committed Dec 20, 2024
1 parent 6ad92ac commit 012c6ff
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 210 deletions.
35 changes: 1 addition & 34 deletions .github/workflows/artifact.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,4 @@ on:
name: Build artifacts
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install and start Stonehenge
run: |
git clone -b 5.x https://github.com/druidfi/stonehenge.git ~/stonehenge
cd ~/stonehenge && make up
# This must be done after we start Stonehenge.
- name: Setup Docker compose environment variables
run: |
echo "COMPOSE_FILE=compose.yaml:compose.ci.yaml" >> $GITHUB_ENV
- name: Start project
run: make up

- name: Build project
run: docker compose exec app bash -c "composer install --no-interaction"

- name: Setup drupal and save database dump
run: |
docker compose exec app bash -c "drush si -y && drush cr"
docker compose exec app bash -c "drush si --existing-config -y"
docker compose exec app bash -c "drush cr"
docker compose exec app bash -c "drush cim -y"
docker compose exec app bash -c "drush sql-dump --result-file=/app/latest.sql"
- name: Upload latest database dump
uses: actions/upload-artifact@v4
with:
name: latest.sql
path: latest.sql
retention-days: 10
uses: city-of-helsinki/drupal-gh-actions/.github/workflows/build-artifact.yml@main
76 changes: 1 addition & 75 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,78 +5,4 @@ on:
name: CI
jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Make sure configuration was exported in correct language (en or und)
run: |
OUTPUT=$(grep -oP '^langcode: \b(?!(?:en|und)\b)\w+' conf -R || true)
if [ ! -z "$OUTPUT" ]; then
echo "Found configuration that does not match the pattern 'langcode: (en|und)':" >> $GITHUB_STEP_SUMMARY
echo "$OUTPUT" >> $GITHUB_STEP_SUMMARY
exit 1
fi
- name: Install and start Stonehenge
run: |
git clone -b 5.x https://github.com/druidfi/stonehenge.git ~/stonehenge
cd ~/stonehenge && make up
# This must be done after we start Stonehenge.
- name: Setup Docker compose environment variables
run: |
echo "COMPOSE_FILE=compose.yaml:compose.ci.yaml" >> $GITHUB_ENV
echo "COMPOSE_PROFILES=" >> $GITHUB_ENV
- name: Start project
run: make up

- name: Build project
run: docker compose exec app bash -c "composer install --no-interaction"

- name: Scan security updates
run: docker compose exec app bash -c "composer audit"

- name: Check that subtheme is not built with dev mode
run: docker compose exec app bash -c "if grep -q 'sourceMappingURL=' -R public/themes/custom/hdbt_subtheme/dist/css; then exit 1; fi"

- name: Run PHPCS
run: |
docker compose exec app bash -c "vendor/bin/phpcs public/modules/custom/"
docker compose exec app bash -c "vendor/bin/phpcs public/themes/custom/"
- name: Run phpstan
run: docker compose exec app bash -c "vendor/bin/phpstan analyze"

- name: Download latest dump
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh run download -n latest.sql

- name: Install Drupal
run: |
docker compose exec app bash -c "mysql --user=drupal --password=drupal --database=drupal --host=db --port=3306 -A < latest.sql"
docker compose exec app bash -c "drush deploy"
- name: Run PHPUnit tests
run: |
docker compose exec app bash -c "mkdir -p /app/results"
if [ -d "tests/" ]; then
docker compose exec app bash -c "composer test-php tests/"
fi
docker compose exec app bash -c "composer test-php public/modules/custom"
- name: Export logs
if: always()
run: docker compose logs app > results/service.log

- name: Create an artifact from test report
uses: actions/upload-artifact@v4
if: always()
with:
name: results
path: results/
retention-days: 1
uses: city-of-helsinki/drupal-gh-actions/.github/workflows/project-tests.yml@main
104 changes: 3 additions & 101 deletions .github/workflows/update-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,106 +3,8 @@ on:
repository_dispatch:
types: [config_change]
name: Update config
env:
GH_TOKEN: ${{ github.token }}
jobs:
update-config:
runs-on: ubuntu-latest
container:
image: ghcr.io/city-of-helsinki/drupal-web:8.3
options: --hostname app --user 1001
services:
db:
image: mysql:8
env:
MYSQL_USER: drupal
MYSQL_PASSWORD: drupal
MYSQL_DATABASE: drupal
MYSQL_ROOT_PASSWORD: drupal
ports:
- 3306:3306

steps:
- uses: actions/checkout@v4

- name: Check if required secrets are set
env:
AUTOMATIC_UPDATE_TOKEN: ${{ secrets.AUTOMATIC_UPDATE_TOKEN }}
if: env.AUTOMATIC_UPDATE_TOKEN == ''
run: exit 1

- name: Download latest dump
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh run download -n latest.sql
- name: Prepare setup
run: |
# We install Drupal from existing dump, so locale_install() hook
# is never fired. Make sure the translations folder exists.
mkdir -p public/sites/default/files/translations -p
- name: Build project
run: |
composer install --no-interaction
$(drush sql:connect) < latest.sql
drush cim -y && drush updb -y && drush cr
composer update drupal/helfi_* drupal/hdbt* -W --no-interaction
drush cr
# Update translations from localize.drupal.org and helfi-modules
# before running update hooks to reduce clutter in configuration files.
drush locale:check && drush locale:update
drush updb -y
# Update translations from helfi_platform_config. These translations
# consists of overrides for non customised translations and will
# override current translation with a non customised translation.
drush helfi:locale-import helfi_platform_config
drush cex -y
# Update platform
drush helfi:tools:update-platform
- name: Check module versions
id: module-status
run: |
MODE="delete"
drush helfi:tools:check-composer-versions $GITHUB_WORKSPACE/composer.lock --format=markdown_table >> $GITHUB_STEP_SUMMARY && EXIT_CODE=$? || EXIT_CODE=$?
if [ "$EXIT_CODE" -eq 3 ]; then
MODE="upsert"
echo " " >> $GITHUB_STEP_SUMMARY
echo ":warning: Failed to install the latest version of the packages listed above" >> $GITHUB_STEP_SUMMARY
echo " " >> $GITHUB_STEP_SUMMARY
echo "Please run \`composer why-not drupal/package_name package_version\` to see why." >> $GITHUB_STEP_SUMMARY
fi
echo "MODE=$MODE" >> $GITHUB_OUTPUT
cat $GITHUB_STEP_SUMMARY > /tmp/pr-message.txt
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
commit-message: Update configuration
token: ${{ secrets.AUTOMATIC_UPDATE_TOKEN }}
title: Automatic update
labels: auto-update
body: |
- Updated active configuration.
- Updated platform
branch: update-configuration

- name: Attempt to find PR
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
id: find-pr
run: echo "number=$(gh pr list --base ${BRANCH_NAME} --head update-configuration --json number --jq '.[].number')" >> $GITHUB_OUTPUT

- name: Comment PR
uses: thollander/actions-comment-pull-request@v2
if: ${{ steps.find-pr.outputs.number != '' }}
with:
comment_tag: status
mode: ${{ steps.module-status.outputs.MODE }}
filePath: /tmp/pr-message.txt
pr_number: ${{ steps.find-pr.outputs.number }}
uses: city-of-helsinki/drupal-gh-actions/.github/workflows/update-config.yml@main
secrets:
automatic_update_token: ${{ secrets.AUTOMATIC_UPDATE_TOKEN }}

0 comments on commit 012c6ff

Please sign in to comment.