├── Dockerfile ├── LICENSE ├── action.yml ├── app-password-permissions.png ├── docker-compose.yml ├── fillbucket.sh ├── index.de.md ├── index.en.md └── readme.md /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine 2 | 3 | LABEL org.opencontainers.image.source https://github.com/heussd/mirror-to-bitbucket-github-action 4 | 5 | RUN apk add --no-cache --update bash git git-lfs less openssh curl 6 | 7 | WORKDIR / 8 | 9 | COPY fillbucket.sh / 10 | 11 | ENTRYPOINT [ "/fillbucket.sh" ] 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Timm Heuss 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: 'Mirror to BitBucket GitHub Action' 2 | description: 'Mirrors a GitHub Git repository to BitBucket' 3 | branding: 4 | icon: upload-cloud 5 | color: blue 6 | inputs: 7 | username: 8 | required: true 9 | default: ${{ github.actor }} 10 | password: 11 | required: true 12 | repository: 13 | required: true 14 | default: ${{ github.event.repository.name }} 15 | spacename: 16 | required: true 17 | default: ${{ github.actor }} 18 | 19 | runs: 20 | using: "composite" 21 | steps: 22 | - run: ${{ github.action_path }}/fillbucket.sh "${{ inputs.username }}" "${{ inputs.password }}" "${{ inputs.repository }}" "${{ inputs.spacename }}" 23 | shell: bash 24 | -------------------------------------------------------------------------------- /app-password-permissions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heussd/mirror-to-bitbucket-github-action/71cc58f09bb43670e69117cb344028534f587c1d/app-password-permissions.png -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | 3 | services: 4 | service: 5 | image: mirror-to-bitbucket-github-action 6 | build: . 7 | -------------------------------------------------------------------------------- /fillbucket.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -o errexit 4 | set -o pipefail 5 | set -o nounset 6 | 7 | trap "echo 'Missing parameter'; exit 1" INT TERM EXIT 8 | username="$1" 9 | password="$2" 10 | reponame="$3" 11 | trap - INT TERM EXIT 12 | 13 | spacename="$username" 14 | if [ $# -ge 4 ]; then 15 | spacename="$4" 16 | fi 17 | 18 | 19 | CURL_OPTS=(-u "$username:$password" --silent) 20 | 21 | 22 | echo "Validating BitBucket credentials..." 23 | curl --fail "${CURL_OPTS[@]}" "https://api.bitbucket.org/2.0/user" > /dev/null || ( 24 | echo "... failed. Most likely, the provided credentials are invalid. Terminating..." 25 | exit 1 26 | ) 27 | 28 | 29 | reponame=$(echo $reponame | tr '[:upper:]' '[:lower:]') 30 | 31 | echo "Checking if BitBucket repository \"$spacename/$reponame\" exists..." 32 | curl "${CURL_OPTS[@]}" "https://api.bitbucket.org/2.0/repositories/$spacename/$reponame" | grep "error" > /dev/null && ( 33 | echo "BitBucket repository \"$spacename/$reponame\" does NOT exist, creating it..." 34 | curl -X POST --fail "${CURL_OPTS[@]}" "https://api.bitbucket.org/2.0/repositories/$spacename/$reponame" -H "Content-Type: application/json" -d '{"scm": "git", "is_private": "true"}' > /dev/null 35 | ) 36 | 37 | echo "Pushing to remote..." 38 | git push https://"$username:$password"@bitbucket.org/$spacename/$reponame.git --all --force 39 | -------------------------------------------------------------------------------- /index.de.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mirror to BitBucket GitHub Action 3 | summary: GitHub Action zum automatischen spiegeln nach BitBucket. 4 | --- 5 | 6 | 7 | *Inhalte sind nur in englischer Sprache verfügbar.* -------------------------------------------------------------------------------- /index.en.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mirror to Bitbucket GitHub Action 3 | summary: GitHub Action to automatically mirror to Bitbucket. 4 | --- 5 | 6 | 7 | Mirrors a GitHub Git repository to Bitbucket. If no corresponding Bitbucket repository exists, it is created using the [Bitbucket API 2.0](https://developer.atlassian.com/bitbucket/api/2/reference/). 8 | 9 | **Please note**: make sure that you checkout the entire repository before using this. By default, `actions/checkout@v2` only creates a shallow clone. See section [example usage](#example-usage) on how to do a complete clone. 10 | 11 | ## Required Inputs 12 | 13 | ### `password` 14 | Password to use on Bitbucket for authentication and for pushing. **Create a new [App Password](https://bitbucket.org/account/settings/app-passwords/) with the following permissions:** 15 | 16 | ![Required App Password Permissions: Account - read, Repositories - read, write, admin](app-password-permissions.png) 17 | 18 | 19 | ## Optional Inputs 20 | ### `username` 21 | Username to use on Bitbucket for 1) authentication and as 2) workspace name. Default: GitHub user name. 22 | 23 | ### `repository` 24 | Name of the repository on Bitbucket. If it does not exist, it is created automatically. Default: GitHub repository name. 25 | 26 | ### `spacename` 27 | Name of the space in which the repository should be contained on Bitbucket. Default: GitHub user name. 28 | 29 | ## Outputs 30 | None 31 | 32 | 33 | ## Example usage 34 | 35 | - name: Checkout 36 | uses: actions/checkout@v2 37 | with: 38 | fetch-depth: 0 # <-- clone with complete history 39 | - name: Push 40 | uses: heussd/mirror-to-bitbucket-github-action@v2 41 | with: 42 | password: ${{ secrets.BITBUCKET_PASSWORD }} 43 | 44 | ## Example with all parameters 45 | 46 | - name: Checkout 47 | uses: actions/checkout@v2 48 | with: 49 | fetch-depth: 0 # <-- clone with complete history 50 | - name: Push 51 | uses: heussd/mirror-to-bitbucket-github-action@v2 52 | with: 53 | username: mycrazybbusername 54 | spacename: teamspace 55 | repository: bestrepo 56 | password: ${{ secrets.BITBUCKET_PASSWORD }} 57 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | index.en.md --------------------------------------------------------------------------------