Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Add composer/determine-root-version action #87

Merged
merged 1 commit into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## Unreleased

For a full diff see [`1.4.1...main`][1.4.1...main].
For a full diff see [`1.5.0...main`][1.5.0...main].

## [`1.5.0`][1.5.0]

For a full diff see [`1.4.1...1.5.0`][1.4.1...1.5.0].

### Added

- Added composite action `composer/determine-root-version` ([#87]), by [@localheinz]

### Fixed

Expand Down Expand Up @@ -95,6 +103,7 @@ For a full diff see [`1.0.0...main`][1.0.0...main].
[1.3.2]: https://github.com/ergebnis/.github/releases/tag/1.3.2
[1.4.0]: https://github.com/ergebnis/.github/releases/tag/1.4.0
[1.4.1]: https://github.com/ergebnis/.github/releases/tag/1.4.1
[1.5.0]: https://github.com/ergebnis/.github/releases/tag/1.5.0

[ca7f15d...1.0.0]: https://github.com/ergebnis/.github/compare/ca7f15d...1.0.0
[1.0.0...1.1.0]: https://github.com/ergebnis/.github/compare/1.0.0...1.1.0
Expand All @@ -105,7 +114,8 @@ For a full diff see [`1.0.0...main`][1.0.0...main].
[1.3.1...1.3.2]: https://github.com/ergebnis/.github/compare/1.3.1...1.3.2
[1.3.2...1.4.0]: https://github.com/ergebnis/.github/compare/1.3.2...1.4.0
[1.4.0...1.4.1]: https://github.com/ergebnis/.github/compare/1.4.0...1.4.1
[1.4.1...main]: https://github.com/ergebnis/.github/compare/1.4.1...main
[1.4.1...1.5.0]: https://github.com/ergebnis/.github/compare/1.4.1...1.5.0
[1.5.0...main]: https://github.com/ergebnis/.github/compare/1.5.0...main

[#47]: https://github.com/ergebnis/.github/pull/47
[#48]: https://github.com/ergebnis/.github/pull/48
Expand All @@ -121,5 +131,6 @@ For a full diff see [`1.0.0...main`][1.0.0...main].
[#79]: https://github.com/ergebnis/.github/pull/79
[#80]: https://github.com/ergebnis/.github/pull/80
[#82]: https://github.com/ergebnis/.github/pull/82
[#87]: https://github.com/ergebnis/.github/pull/87

[@localheinz]: https://github.com/localheinz
29 changes: 29 additions & 0 deletions actions/composer/determine-root-version/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# https://docs.github.com/en/actions/creating-actions/creating-a-composite-action
# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#inputs
# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-composite-run-steps-actions
# https://getcomposer.org/doc/03-cli.md#composer-root-version

name: "Determine composer root version"

description: "Determines the composer root version and exports it as COMPOSER_ROOT_VERSION environment variable"

inputs:
branch:
default: "main"
description: "Name of the branch, e.g. \"main\""
required: true
working-directory:
default: "."
description: "Which directory to use as working directory"
required: true

runs:
using: "composite"

steps:
- name: "Determine composer root version"
env:
COMPOSER_DETERMINE_ROOT_VERSION_BRANCH: "${{ inputs.branch }}"
COMPOSER_DETERMINE_ROOT_VERSION_WORKING_DIRECTORY: "${{ inputs.working-directory }}"
run: "${{ github.action_path }}/run.sh"
shell: "bash"
28 changes: 28 additions & 0 deletions actions/composer/determine-root-version/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

branch="${COMPOSER_DETERMINE_ROOT_VERSION_BRANCH}"
workingDirectory="${COMPOSER_DETERMINE_ROOT_VERSION_WORKING_DIRECTORY}"

if [[ ! -d ${workingDirectory} ]]; then
echo "::error::The value for the \"working-directory\" input needs to be an existing directory. The directory \"${workingDirectory}\" does not exist."

exit 1;
fi

pathToComposerJsonFile="${COMPOSER_DETERMINE_ROOT_VERSION_WORKING_DIRECTORY}/composer.json"

if [[ ! -f "${pathToComposerJsonFile}" ]]; then
echo "::error::A composer.json file could not be found in the directory \"${workingDirectory}\"."

exit 1
fi

COMPOSER_ROOT_VERSION=$(jq --arg key "dev-${branch}" --raw-output '.["extra"]["branch-alias"][$key]' "${pathToComposerJsonFile}")

if [[ null = "${COMPOSER_ROOT_VERSION}" ]]; then
echo "::error:A branch alias has not been defined in \"${pathToComposerJsonFile}\" for branch \"${branch}\"."

exit 0
fi

echo "COMPOSER_ROOT_VERSION=${COMPOSER_ROOT_VERSION}" >> "${GITHUB_ENV}"