-
Notifications
You must be signed in to change notification settings - Fork 0
Add GitHub Actions workflow for private composer releases #12
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
bf20257
Add GitHub Actions workflow for private composer releases
throttlehead-dev b8f7f1b
Removed test/dev code
throttlehead-dev 2fc2235
Moved file
throttlehead-dev bb375f7
Added ref input param
throttlehead-dev 2539fe7
Removed unneeded permissions
throttlehead-dev 23bec6c
Check if version tag already exists
throttlehead-dev ed0dd0c
Update workflows to only look for branch names that start with the in…
throttlehead-dev 04de412
Add commit_hash input
throttlehead-dev 72e0f31
Remove unneeded workflow steps
throttlehead-dev d5dc49b
Add check if release already exists
throttlehead-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
220 changes: 220 additions & 0 deletions
220
.github/workflows/_private_composer_gh_auto_release.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,220 @@ | ||
| name: private_composer_auto_release | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| php_version: | ||
| required: false | ||
| default: '8.3' | ||
| type: string | ||
| private_package_repo_workflow_id: | ||
| required: false | ||
| default: "235090394" | ||
| type: string | ||
| private_package_repo: | ||
| required: false | ||
| default: 'SparkHire/php-private-composer-registry' | ||
| type: string | ||
| private_package_ref: | ||
| required: false | ||
| default: "main" | ||
|
|
||
| jobs: | ||
| run: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Generate a token | ||
| id: generate-token | ||
| uses: actions/create-github-app-token@v1 | ||
| with: | ||
| app-id: ${{ secrets.GH_APP_ID }} | ||
| private-key: ${{ secrets.GH_APP_PRIVATE_KEY }} | ||
| owner: ${{ github.repository_owner }} | ||
|
|
||
| - name: Get info | ||
| id: get-commit-hash | ||
| run: | | ||
| COMMIT_INPUT="${{ inputs.commit_hash }}" | ||
throttlehead-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| GITHUB_SHA="${{ github.sha }}" | ||
|
|
||
| echo "Workspace dir: ${{ github.workspace }}" | ||
| echo "User: $(id -u -n) $(id -u):$(id -g)" | ||
|
|
||
| if [[ -z "$COMMIT_INPUT" ]]; then | ||
| HASH=$(echo "$GITHUB_SHA" | cut -c 1-7) | ||
| echo "Commit input is empty. Using current SHA: $HASH" | ||
| else | ||
| HASH=$(echo "$COMMIT_INPUT" | cut -c 1-7) | ||
| echo "Commit input provided. Using: $HASH" | ||
| fi | ||
|
|
||
| echo "commit_hash=$HASH" >> "$GITHUB_OUTPUT" | ||
|
|
||
throttlehead-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - name: Checkout repo | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| token: ${{ steps.generate-token.outputs.token }} | ||
|
|
||
| - name: Set Git user | ||
| run: | | ||
| git config user.name "SparkHireBot" | ||
| git config user.email "dev@sparkhire.com" | ||
|
|
||
| - name: Get latest release version | ||
| id: release-version | ||
| env: | ||
| GH_TOKEN: ${{ steps.generate-token.outputs.token }} | ||
| run: | | ||
| VERSION=$(gh release list --limit 1 --json tagName --jq '.[0].tagName') | ||
| # Remove 'v' prefix if it exists | ||
| VERSION=${VERSION#v} | ||
| echo "Latest release: $VERSION" | ||
| echo "package_version=$VERSION" >> $GITHUB_OUTPUT | ||
throttlehead-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| - name: Get branch name | ||
| id: get-branch-name | ||
| run: | | ||
| if [[ "${{ github.event_name }}" == "pull_request" ]]; then | ||
| echo "Getting branch name from pull request head ref" | ||
| branch_name="${{ github.event.pull_request.head.ref }}" | ||
| elif [[ "${{ github.event_name }}" == "push" ]]; then | ||
| echo "Getting branch name from merged commit message" | ||
| # Get only the first line (title) of the merge commit to avoid matching "from" in body text | ||
| merge_commit_title=$(git log --format=%s -n 1 "${GITHUB_SHA}") | ||
| echo "Merge commit title: $merge_commit_title" | ||
| # Match specifically the GitHub merge commit format: "Merge pull request #XX from owner/branch" | ||
| if [[ "$merge_commit_title" =~ ^Merge\ pull\ request\ \#[0-9]+\ from\ (.+)$ ]]; then | ||
| full_branch="${BASH_REMATCH[1]}" | ||
| # Remove owner prefix (e.g., "SparkHire/dependabot/..." -> "dependabot/...") | ||
| branch_name=$(echo "$full_branch" | cut -d/ -f2-) | ||
| else | ||
| echo "Warning: Commit is not a merge commit, skipping branch name extraction" | ||
| branch_name="" | ||
| fi | ||
| fi | ||
|
|
||
| echo "Branch name: ${branch_name}" | ||
| branch_name_sanitized="${branch_name//\//-}" | ||
| echo "branch_name=${branch_name}" >> $GITHUB_OUTPUT | ||
| echo "branch_name_sanitized=${branch_name_sanitized}" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Fail if branch_name not set | ||
| if: ${{ steps.get-branch-name.outputs.branch_name == '' }} | ||
| run: | | ||
| echo "Branch name was not set" >&2 | ||
| exit 1 | ||
|
|
||
| - name: Determine version bump | ||
| id: determine-version-bump | ||
| run: | | ||
| echo "Current version: ${{ steps.release-version.outputs.package_version }}" | ||
| echo "Branch name: ${{ steps.get-branch-name.outputs.branch_name }}" | ||
|
|
||
| BRANCH_NAME="${{ steps.get-branch-name.outputs.branch_name }}" | ||
| CURRENT_VERSION="${{ steps.release-version.outputs.package_version }}" | ||
|
|
||
| if [[ "$BRANCH_NAME" == "release/"* ]]; then | ||
| echo "This is a release branch. Setting version bump to 'major'." | ||
| VERSION_BUMP="major" | ||
| elif [[ "$BRANCH_NAME" == "major/"* ]]; then | ||
| echo "This is a major branch. Setting version bump to 'major'." | ||
| VERSION_BUMP="major" | ||
| elif [[ "$BRANCH_NAME" == "minor/"* ]]; then | ||
| echo "This is a minor branch. Setting version bump to 'minor'." | ||
| VERSION_BUMP="minor" | ||
| elif [[ "$BRANCH_NAME" == "patch/"* ]]; then | ||
| echo "This is a patch branch. Setting version bump to 'patch'." | ||
| VERSION_BUMP="patch" | ||
| elif [[ "$BRANCH_NAME" == "hotfix/"* ]]; then | ||
| echo "This is a hotfix branch. Setting version bump to 'patch'." | ||
| VERSION_BUMP="patch" | ||
| elif [[ "$BRANCH_NAME" == "feature/"* ]]; then | ||
| echo "This is a feature branch. Setting version bump to 'minor'." | ||
| VERSION_BUMP="minor" | ||
| elif [[ "$BRANCH_NAME" == "bugfix/"* ]]; then | ||
| echo "This is a bugfix branch. Setting version bump to 'patch'." | ||
| VERSION_BUMP="patch" | ||
| elif [[ "$BRANCH_NAME" == "chore/"* ]]; then | ||
| echo "This is a chore branch. Setting version bump to 'patch'." | ||
| VERSION_BUMP="patch" | ||
| elif [[ "$BRANCH_NAME" == "docs/"* ]]; then | ||
| echo "This is a docs branch. Setting version bump to 'patch'." | ||
| VERSION_BUMP="patch" | ||
| elif [[ "$BRANCH_NAME" == "test/"* ]]; then | ||
| echo "This is a test branch. Setting version bump to 'patch'." | ||
| VERSION_BUMP="patch" | ||
| elif [[ "$BRANCH_NAME" == "dependabot/"* ]]; then | ||
| echo "This is a dependabot branch. Setting version bump to 'patch'." | ||
| VERSION_BUMP="patch" | ||
| else | ||
| echo "Branch name does not match any known patterns!" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Determined version bump: $VERSION_BUMP" | ||
|
|
||
| echo "version_bump=$VERSION_BUMP" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Create release | ||
| env: | ||
| GH_TOKEN: ${{ steps.generate-token.outputs.token }} | ||
| run: | | ||
| VERSION_BUMP="${{ steps.determine-version-bump.outputs.version_bump }}" | ||
| CURRENT_VERSION="${{ steps.release-version.outputs.package_version }}" | ||
|
|
||
| if [[ -z "$CURRENT_VERSION" ]]; then | ||
| echo "No current version found. Defaulting to 0.0.0" | ||
| CURRENT_VERSION="0.0.0" | ||
| fi | ||
|
|
||
| IFS='.' read -r -a VERSION_PARTS <<< "$CURRENT_VERSION" | ||
|
|
||
| MAJOR="${VERSION_PARTS[0]}" | ||
| MINOR="${VERSION_PARTS[1]}" | ||
| PATCH="${VERSION_PARTS[2]}" | ||
|
|
||
| # Handle missing parts if version is like "1.0" | ||
throttlehead-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| MINOR=${MINOR:-0} | ||
| PATCH=${PATCH:-0} | ||
|
|
||
| if [[ "$VERSION_BUMP" == "major" ]]; then | ||
| MAJOR=$((MAJOR + 1)) | ||
| MINOR=0 | ||
| PATCH=0 | ||
| elif [[ "$VERSION_BUMP" == "minor" ]]; then | ||
| MINOR=$((MINOR + 1)) | ||
| PATCH=0 | ||
| elif [[ "$VERSION_BUMP" == "patch" ]]; then | ||
| PATCH=$((PATCH + 1)) | ||
| else | ||
| echo "Unknown version bump type: $VERSION_BUMP" | ||
| exit 1 | ||
| fi | ||
|
|
||
| NEW_VERSION="$MAJOR.$MINOR.$PATCH" | ||
| echo "Bumping version from $CURRENT_VERSION to $NEW_VERSION" | ||
|
|
||
| # Create tag and release | ||
| if git rev-parse "refs/tags/v$NEW_VERSION" >/dev/null 2>&1; then | ||
| echo "Tag v$NEW_VERSION already exists. Skipping tag creation and push." | ||
| else | ||
| git tag "v$NEW_VERSION" | ||
| git push origin "v$NEW_VERSION" | ||
| fi | ||
|
|
||
| if gh release view "v$NEW_VERSION" > /dev/null 2>&1; then | ||
| echo "Release v$NEW_VERSION already exists. Skipping creation." | ||
| else | ||
| gh release create "v$NEW_VERSION" --generate-notes | ||
| fi | ||
|
|
||
| - name: Update private package repository | ||
| env: | ||
| GH_TOKEN: ${{ steps.generate-token.outputs.token }} | ||
| WORKFLOW_ID: ${{ inputs.private_package_repo_workflow_id }} | ||
| REPO: ${{ inputs.private_package_repo }} | ||
| REF: ${{ inputs.private_package_ref }} | ||
| run: | | ||
| gh workflow run "$WORKFLOW_ID" --repo "$REPO" --ref $REF | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.