Skip to content

Commit

Permalink
Geneate PHP part version from composer post install hook (#94)
Browse files Browse the repository at this point in the history
* Geneate PHP part version from composer post install hook

* Added missing version file to php deps
  • Loading branch information
intuibase authored Sep 13, 2024
1 parent a258331 commit 6f3c56d
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/build-php-deps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ jobs:
name: php-dependencies
path: |
prod/php/vendor_*
prod/php/ElasticOTel/PhpPartVersion.php
NOTICE
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#generated version file
prod/php/ElasticOTel/PhpPartVersion.php

# Mac
.DS_Store

Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
}
},
"scripts": {
"pre-autoload-dump": [
"./tools/build/generate_php_part_version.sh"
],
"parallel-lint": [
"parallel-lint ./prod/php/ ./tests/ --exclude ./tests/polyfills/"
],
Expand Down
28 changes: 28 additions & 0 deletions prod/php/ElasticOTel/PhpPartVersion.php.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/* this file is generated, do not edit it manually */

declare(strict_types=1);

namespace Elastic\OTel;

const ELASTIC_OTEL_PHP_VERSION = '__ELASTIC_OTEL_PHP_VERSION__';
4 changes: 3 additions & 1 deletion tools/build/build_php_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ do
docker run --rm \
-v ${PWD}:/sources \
-v ${PWD}/prod/php/vendor_${PHP_VERSION}:/sources/vendor \
-e GITHUB_SHA=${GITHUB_SHA} \
-w /sources \
php:${PHP_VERSION:0:1}.${PHP_VERSION:1:1}-cli sh -c "\
apt-get update && apt-get install -y unzip \
apt-get update && apt-get install -y unzip git \
&& git config --global --add safe.directory /sources \
&& curl -sS https://getcomposer.org/installer | php -- --filename=composer --install-dir=/usr/local/bin \
&& composer --ignore-platform-req=ext-opentelemetry --ignore-platform-req=ext-otel_instrumentation --no-dev install \
&& php /sources/packaging/notice_generator.php >>/sources/NOTICE \
Expand Down
39 changes: 39 additions & 0 deletions tools/build/generate_php_part_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

source ./tools/read_properties.sh

read_properties elastic-otel-php.properties ELASTIC_OTEL_PHP

get_git_hash() {
if [ -z "${GITHUB_SHA}" ]; then
IS_DIRTY=false

git diff-index --quiet HEAD --
GIT_RESULT=$?

if [ $GIT_RESULT -ne 0 ]; then
IS_DIRTY=true
fi

GIT_VERSION=$(git rev-parse --short HEAD 2>/dev/null)
GIT_RESULT=$?

if [ $GIT_RESULT -ne 0 ]; then
TMP_OUTPUT_HASH=""
else
if [ "$IS_DIRTY" = true ]; then
TMP_OUTPUT_HASH="~${GIT_VERSION}-dirty"
else
TMP_OUTPUT_HASH="~${GIT_VERSION}"
fi
fi

echo "$TMP_OUTPUT_HASH"
fi
}

ELASTIC_OTEL_PHP_VERSION="${ELASTIC_OTEL_PHP_VERSION}$(get_git_hash)"

sed "s/__ELASTIC_OTEL_PHP_VERSION__/$ELASTIC_OTEL_PHP_VERSION/g" prod/php/ElasticOTel/PhpPartVersion.php.template > prod/php/ElasticOTel/PhpPartVersion.php

echo "The file prod/php/ElasticOTel/PhpPartVersion.php has been generated with version ${ELASTIC_OTEL_PHP_VERSION}"

0 comments on commit 6f3c56d

Please sign in to comment.