diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..7255735 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,75 @@ +name: "Release" + +on: + push: + tags: + - "*" + +env: + COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --no-suggest --prefer-dist" + +jobs: + build: + name: Upload Release Asset + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + extensions: "intl" + ini-values: "memory_limit=-1" + php-version: "7.4" + + - name: "Install dependencies from composer.lock using composer binary provided by system" + run: "composer install ${{ env.COMPOSER_FLAGS }}" + + - name: "Run install again using composer binary from source" + run: "bin/composer install ${{ env.COMPOSER_FLAGS }}" + + - name: "Validate composer.json" + run: "bin/composer validate" + + - name: Build phar file + run: "php -d phar.readonly=0 bin/compile" + + - name: Create release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: ${{ github.ref }} + draft: true + body: TODO + + - name: Upload phar + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./composer.phar + asset_name: composer.phar + asset_content_type: application/octet-stream + + # This step requires a secret token with `pull` access to composer/docker. The default + # secrets.GITHUB_TOKEN is scoped to this repository only which is not sufficient. + - name: "Open issue @ Docker repository" + uses: actions/github-script@v2 + with: + github-token: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }} + script: | + // github.ref value looks like 'refs/tags/TAG', cleanup + const tag = "${{ github.ref }}".replace(/refs\/tags\//, ''); + // create new issue on Docker repository + github.issues.create({ + owner: "${{ github.repository_owner }}", + repo: "docker", + title: `New Composer tag: ${ tag }`, + body: `https://github.com/${{ github.repository }}/releases/tag/${ tag }`, + }); diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..432b940 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,42 @@ +name: Tests + +on: + push: + pull_request: + +jobs: + tests: + name: PHP ${{ matrix.php }} + runs-on: ubuntu-20.04 + + strategy: + matrix: + php: + - "5.3" + - "5.4" + - "5.5" + - "5.6" + - "7.0" + - "7.1" + - "7.2" + - "7.3" + - "7.4" + + steps: + - name: Checkout Code + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: none + coverage: none + + - name: Install box + run: make box.phar + + - name: Make PHAR + run: make phar + +# vim:ft=yaml:et:ts=2:sw=2 diff --git a/README.md b/README.md index c1318c0..2f13565 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ REV="$2" ## Git + * Setup in your git repo `hooks/post-receive`: ```sh diff --git a/eventum-cvs-hook.php b/eventum-cvs-hook.php index 6dccada..fa4f8f9 100755 --- a/eventum-cvs-hook.php +++ b/eventum-cvs-hook.php @@ -46,7 +46,7 @@ function main($context) $commit_msg = cvs_commit_msg($context['stdin']); // parse the commit message and get all issue numbers we can find - $issues = match_issues($commit_msg); + $issues = match_issues($commit_msg, $context['eventum_url']); if (!$issues) { return; } diff --git a/helpers.php b/helpers.php index 50a0d45..09d6ec3 100644 --- a/helpers.php +++ b/helpers.php @@ -91,14 +91,27 @@ function fileparts($abspath) * parse the commit message and get all issue numbers we can find * * @param string $commit_msg + * @param string|null $eventum_url * @return array */ -function match_issues($commit_msg) +function match_issues($commit_msg, $eventum_url = null) { - preg_match_all('/(?:issue|bug) ?:? ?#?(\d+)/i', $commit_msg, $matches); - - if (count($matches[1]) > 0) { - return $matches[1]; + $url_quoted = $eventum_url ? preg_quote($eventum_url, '/') : ''; + + preg_match_all("/ + (?: + # match issue xxx and bug xxx + (?i:issue|bug)\s*:?\s*#? + | + # match url + {$url_quoted}/view\.php\?id= + ) + + (?P\d+) + /x", $commit_msg, $matches); + + if (count($matches['issue_id']) > 0) { + return $matches['issue_id']; } return null;