Skip to content

Instantly share code, notes, and snippets.

@M1ke
Created February 14, 2022 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save M1ke/c8b3e3c4b0c2bc7aeb9e055aa83eb42f to your computer and use it in GitHub Desktop.
Save M1ke/c8b3e3c4b0c2bc7aeb9e055aa83eb42f to your computer and use it in GitHub Desktop.
Composer update pipeline in Bitbucket
pipelines:
# Manually triggered Pipelines
custom:
composer-update:
- step:
name: Composer Update
image: prooph/composer:<pick your version, e.g 7.4>
script:
- export COMPOSER_BRANCH="composer-update-auto-$(date +"%Y-%m-%d")"
- git checkout -b "$COMPOSER_BRANCH"
# This will depend on the version above, but probably can't hurt
# as sometimes the github auth fails, since GH changed their key format
- composer self-update
# The GITHUB_TOKEN here is just to avoid rate limits. Define it in your pipeline variables
- export COMPOSER_AUTH="{\"github-oauth\":{\"github.com\":\"$GITHUB_TOKEN\"}}"
- composer install
- composer update
- git add composer.lock
- git commit -m "Composer update from Bitbucket pipeline $(date +"%Y-%m-%d")"
- git push origin
# The pipeline variable PIPELINE_APP is an app password for the specific user, with PR open permission
- sh "./bitbucket-pr.sh" "$COMPOSER_BRANCH" "Auto composer update $(date +"%Y-%m-%d")" "$PIPELINE_USER" "$PIPELINE_APP"
#!/bin/sh
source=$1
title=$2
user=$3
pass=$4
repo="<you can hard code this or make variable>"
team="<as above...>"
# You could change "master" below to something else
data=$(cat <<EOF
{
"title": "$title",
"source": {
"branch": {
"name": "$source"
}
},
"destination": {
"branch": {
"name": "master"
}
},
"close_source_branch": true
}
EOF
)
echo "Opening PR for branch $source in repo $repo. Title will be $title"
response=$(curl --write-out "%{http_code}" --silent --output /dev/null "https://api.bitbucket.org/2.0/repositories/$team/$repo/pullrequests" \
-u "$user:$pass" \
--request POST \
--header "Content-Type: application/json" \
--data "$data")
if [ "$response" -ne "200" ] && [ "$response" -ne "201" ]; then
echo "ERROR opening PR: Status code was $response"
exit 1
fi
echo "PR opened successfully"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment