Skip to content

Commit

Permalink
Append build number (based on "git describe") to the site version
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyfok committed Jul 12, 2022
1 parent 2174bda commit f380694
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/export-static-site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions bin/init-db-and-generate-static-site.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 '(<a href="https://github.com/OpenDRR/riskprofiler-cms/tree/' . $git_describe . '" class="text-gray-400">' . $build_number . '</a>)';\
\
echo '<span class="mx-1">•</span>';\
}\
EOF
}

simply_static_site_export() {
set -x
wp cron event schedule 'simply_static_site_export_cron'
Expand Down Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f380694

Please sign in to comment.