|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | + |
| 4 | +GIT=$(which "git") |
| 5 | + |
| 6 | +if [ -x "$GIT" ]; then |
| 7 | + echo "Using git executable $GIT" |
| 8 | +else |
| 9 | + echo "Could not find git executable $GIT" >&2 |
| 10 | + exit 1 |
| 11 | +fi |
| 12 | + |
| 13 | +GITHUB_CLI=$(which "gh") |
| 14 | + |
| 15 | +if [ -x "$GITHUB_CLI" ]; then |
| 16 | + echo "Using Microsoft GitHub CLI executable $GITHUB_CLI" |
| 17 | +fi |
| 18 | + |
| 19 | +APP_ID=$1 |
| 20 | +if [ "$APP_ID" ]; then |
| 21 | + echo "Preparing app $APP_ID" |
| 22 | +else |
| 23 | + echo "Missing app id" >&2 |
| 24 | + exit 1 |
| 25 | +fi |
| 26 | + |
| 27 | +ORIGINAL_DIR=$(pwd) |
| 28 | +WORK_DIR=$(mktemp -d) |
| 29 | +cd "${WORK_DIR}" |
| 30 | + |
| 31 | +$GIT clone https://github.com/nextcloud-gmbh/$APP_ID.git |
| 32 | + |
| 33 | +cd $APP_ID |
| 34 | +$GIT remote set-url --push origin git@github.com:nextcloud-gmbh/$APP_ID.git |
| 35 | + |
| 36 | +$GIT checkout --orphan gmbh-main |
| 37 | + |
| 38 | +cat > README.md<<'EOF' |
| 39 | +# $APP_ID |
| 40 | +
|
| 41 | +This repository is a clone of https://github.com/nextcloud/$APP_ID |
| 42 | +This branch is empty and contains information related to this repo. |
| 43 | +
|
| 44 | +You can find the main and other stable branches here: |
| 45 | + - https://github.com/nextcloud-gmbh/$APP_ID/tree/main |
| 46 | + - https://github.com/nextcloud-gmbh/$APP_ID/branches |
| 47 | +
|
| 48 | +EOF |
| 49 | +$GIT add README.md |
| 50 | +$GIT commit -m "Init readme" |
| 51 | +$GIT push origin gmbh-main |
| 52 | + |
| 53 | +$GIT checkout -b activate-actions |
| 54 | +mkdir -p .github/workflows/ |
| 55 | +cat > .github/workflows/blank.yml<<'EOF' |
| 56 | +# This is a basic workflow to help you get started with Actions |
| 57 | +
|
| 58 | +name: CI |
| 59 | +
|
| 60 | +# Controls when the workflow will run |
| 61 | +on: |
| 62 | + # Triggers the workflow on push or pull request events but only for the main2 branch |
| 63 | + push: |
| 64 | + branches: [ 'gmbh-main' ] |
| 65 | + pull_request: |
| 66 | + branches: [ 'gmbh-main' ] |
| 67 | +
|
| 68 | + # Allows you to run this workflow manually from the Actions tab |
| 69 | + workflow_dispatch: |
| 70 | +
|
| 71 | +# A workflow run is made up of one or more jobs that can run sequentially or in parallel |
| 72 | +jobs: |
| 73 | + # This workflow contains a single job called "build" |
| 74 | + build: |
| 75 | + # The type of runner that the job will run on |
| 76 | + runs-on: ubuntu-latest |
| 77 | +
|
| 78 | + # Steps represent a sequence of tasks that will be executed as part of the job |
| 79 | + steps: |
| 80 | + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it |
| 81 | + - uses: actions/checkout@v2 |
| 82 | +
|
| 83 | + # Runs a single command using the runners shell |
| 84 | + - name: Run a one-line script |
| 85 | + run: echo Hello, world! |
| 86 | +
|
| 87 | + # Runs a set of commands using the runners shell |
| 88 | + - name: Run a multi-line script |
| 89 | + run: | |
| 90 | + echo Add other actions to build, |
| 91 | + echo test, and deploy your project. |
| 92 | +EOF |
| 93 | + |
| 94 | +$GIT add .github/workflows/blank.yml |
| 95 | +$GIT commit -m "Activate github actions with a trick" |
| 96 | +$GIT push --set-upstream origin $($GIT symbolic-ref --short HEAD) |
| 97 | + |
| 98 | +if [ -x "$GITHUB_CLI" ]; then |
| 99 | + $GITHUB_CLI pr create --base gmbh-main --fill |
| 100 | + $GIT push --delete origin activate-actions |
| 101 | +else |
| 102 | + xdg-open "https://github.com/nextcloud-gmbh/${APP_ID}/pull/new/activate-actions" 2>/dev/null |
| 103 | +fi |
| 104 | + |
| 105 | +cd "${ORIGINAL_DIR}" |
| 106 | +rm -Rf "${WORK_DIR}" |
0 commit comments