Skip to content

Commit

Permalink
feat: Dynamically build the my.cnf
Browse files Browse the repository at this point in the history
  • Loading branch information
mkraeml committed Oct 30, 2024
1 parent d299044 commit e308e3e
Showing 1 changed file with 34 additions and 13 deletions.
47 changes: 34 additions & 13 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,41 @@ runs:
composer run framework:schema:dump
composer run npm:admin run convert-entity-schema
- name: Configure MySQL Client
if: inputs.mysql-version != 'builtin'
- name: Setup Shopware Database URL
shell: bash
working-directory: ${{ inputs.path }}
run: |
echo "[client]" > $HOME/.my.cnf
echo "host=127.0.0.1" > $HOME/.my.cnf
echo "user=root" > $HOME/.my.cnf
echo "DATABASE_URL=mysql://[email protected]/shopware" >> "$GITHUB_ENV"
if: ${{ env.DATABASE_URL == '' }} # Don't override if already set

- name: Configure MySQL Client
if: inputs.mysql-version != 'builtin'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const os = require('os');
const uri = process.env.DATABASE_URL;
const regex = /^mysql:\/\/(?<user>[^:]+)(:(?<password>[^@]+))?@(?<host>[^:\/]+)(:(?<port>\d+))?(\/(?<database>[^\?]+))?/;
const match = uri.match(regex);
if (!match || !match.groups) {
console.error("DATABASE_URL is invalid!");
process.exit(1);
}
const { user, password, host, port, database } = match.groups;
const myFileContent = [
"[client]",
`host=${host}`,
`user=${user}`,
password ? `password=${password}` : null,
port ? `port=${port}` : null,
database ? `database=${database}` : null,
].filter(Boolean).join("\n");
fs.writeFileSync(`${os.homedir()}/.my.cnf`, myFileContent);
- name: Wait for MySQL
if: inputs.mysql-version != 'builtin' && inputs.mysql-version != 'skip'
Expand All @@ -208,13 +236,6 @@ runs:
echo "APP_SECRET=def00000bb5acb32b54ff8ee130270586eec0e878f7337dc7a837acc31d3ff00f93a56b595448b4b29664847dd51991b3314ff65aeeeb761a133b0ec0e070433bff08e48" >> "$GITHUB_ENV"
echo "APP_URL=http://localhost:8000" >> "$GITHUB_ENV"
- name: Setup Shopware Database URL
shell: bash
working-directory: ${{ inputs.path }}
run: |
echo "DATABASE_URL=mysql://[email protected]/shopware" >> "$GITHUB_ENV"
if: ${{ env.DATABASE_URL == '' }} # Don't override if already set

- name: Configure HMAC JWT
shell: bash
working-directory: ${{ inputs.path }}
Expand Down Expand Up @@ -248,7 +269,7 @@ runs:
if: inputs.install-storefront == 'true'
shell: bash
working-directory: ${{ inputs.path }}
run: |
run: |
if bin/console theme:change --help | grep -q '--sync'; then
bin/console theme:change --sync --all Storefront
else
Expand Down

0 comments on commit e308e3e

Please sign in to comment.