diff --git a/.github/workflows/export-static-site.yml b/.github/workflows/export-static-site.yml index 5d6fcd2d..e04aa4ca 100644 --- a/.github/workflows/export-static-site.yml +++ b/.github/workflows/export-static-site.yml @@ -11,21 +11,24 @@ concurrency: export-static-site jobs: export-static-site: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')" env: DOCKER_BUILDKIT: 1 TZ: America/Vancouver steps: - - name: Checkout OpenDRR/riskprofiler-cms + - name: Checkout uses: actions/checkout@v3 with: + fetch-depth: 0 submodules: recursive - name: Run "docker compose up" to export static site for RiskProfiler run: | + set -x export DOCKER_WP_UID_GID="$(id -u):$(id -g)" + export OPTIONS_GIT_DESCRIBE=$(git describe --long --tags) docker compose up --abort-on-container-exit --exit-code-from wpcli - name: Deploy to gh-pages branch as GitHub Pages diff --git a/bin/init-db-and-generate-static-site.sh b/bin/init-db-and-generate-static-site.sh index df7d383a..e44fb28e 100755 --- a/bin/init-db-and-generate-static-site.sh +++ b/bin/init-db-and-generate-static-site.sh @@ -141,6 +141,36 @@ configure_simply_static() { wp option get simply-static } +get_git_describe() { + wp option add options_git_describe "$OPTIONS_GIT_DESCRIBE" + # TODO: The following does not work with French pages + # wp option add options_fr_git_describe "$OPTIONS_GIT_DESCRIBE" +} + +patch_version_php() { + # Append build number to the site version + sed -i -f - site/assets/themes/fw-child/template/version.php <<'EOF' +/^?>/i\ + if ($git_describe = get_field ( 'git_describe', 'option' )) {\ + list($version, $api_version, $release_date, $commits_since, $commit_hash) = explode("-", $git_describe);\ +\ + if ($commits_since == 0) {\ + $git_describe = implode('-', [$version, $api_version, $release_date]);\ + }\ +\ + $build_number = sprintf("%04d", $release_date - 20220000);\ + if ($commits_since > 0) {\ + $build_number = implode('-', [$build_number, $commits_since, $commit_hash]);\ + }\ +\ + echo '(' . $build_number . ')';\ +\ + echo '';\ + }\ + +EOF +} + simply_static_site_export() { set -x wp cron event schedule 'simply_static_site_export_cron' @@ -253,6 +283,8 @@ main() { #update_wp_core_and_simply_static configure_simply_static + get_git_describe + patch_version_php simply_static_site_export fixup_static_site diff --git a/docker-compose.yml b/docker-compose.yml index 12663e44..bcde8350 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -42,7 +42,8 @@ services: WP_ADMIN_USER: # read from .env WP_ADMIN_EMAIL: # read from .env WP_ADMIN_PASSWORD: # read from .env - KEEP_WPCLI_RUNNING: # read from .env + KEEP_WPCLI_RUNNING: # read from .env or from environment + OPTIONS_GIT_DESCRIBE: # read from .env or from environment depends_on: - db - wordpress