diff --git a/.github/workflows/ci-devel.yml b/.github/workflows/ci-devel.yml
new file mode 100644
index 0000000000..34c88a2ec4
--- /dev/null
+++ b/.github/workflows/ci-devel.yml
@@ -0,0 +1,44 @@
+name: CI - Devel scripts
+
+on:
+ push:
+ paths:
+ # NOTE: GitHub Actions do not allow using YAML references, the same path
+ # list is used below for the pull request event. Keep both lists in sync!!
+
+ # this file as well
+ - .github/workflows/ci-devel.yml
+ # any change in the devel subfolder
+ - devel/**
+ # except the Markdown documentation
+ - "!devel/**.md"
+ pull_request:
+ paths:
+ # NOTE: GitHub Actions do not allow using YAML references, the same path
+ # list is used above for the push event. Keep both lists in sync!!
+
+ # this file as well
+ - .github/workflows/ci-devel.yml
+ # any change in the devel subfolder
+ - devel/**
+ # except the Markdown documentation
+ - "!devel/**.md"
+
+ # allow running manually
+ workflow_dispatch:
+
+jobs:
+ ci_devel:
+ runs-on: ubuntu-latest
+
+ steps:
+
+ - name: Git Checkout
+ uses: actions/checkout@v4
+ with:
+ # checkout only the "devel" subdirectory
+ sparse-checkout: |
+ devel
+
+ - name: Run the tests
+ run: find devel -type f -exec grep -l -E "^#! *(/usr/|)/bin/(ba|)sh" \{\} \; | xargs -I% bash -c "echo 'Checking %...' && shellcheck %"
diff --git a/.github/workflows/obs-release.yml b/.github/workflows/obs-release.yml
deleted file mode 100644
index 9928560fa6..0000000000
--- a/.github/workflows/obs-release.yml
+++ /dev/null
@@ -1,48 +0,0 @@
-# Publish a new version
-# - Submit the packages to the OBS project defined in OBS_PROJECT_RELEASE variable
-# at GitHub (in the original repository it is set to systemsmanagement:Agama:Release,
-# see https://github.com/agama-project/agama/settings/variables/actions,
-# you might change that in forks)
-# - Send submit requests
-
-name: Release
-
-on:
- # runs when creating a release tag
- push:
- tags:
- - v[0-9]*
-
-jobs:
- # Note: the Live ISO is currently not submitted
-
- update_rust:
- uses: ./.github/workflows/obs-staging-shared.yml
- # pass all secrets
- secrets: inherit
- with:
- install_packages: obs-service-cargo_audit obs-service-cargo_vendor
- package_name: agama
- service_file: rust/package/_service
-
- update_web:
- uses: ./.github/workflows/obs-staging-shared.yml
- # pass all secrets
- secrets: inherit
- with:
- install_packages: obs-service-node_modules
- package_name: agama-web-ui
- service_file: web/package/_service
-
- update_service:
- uses: ./.github/workflows/obs-service-shared.yml
- # pass all secrets
- secrets: inherit
-
- update_products:
- uses: ./.github/workflows/obs-staging-shared.yml
- # pass all secrets
- secrets: inherit
- with:
- package_name: agama-products
- service_file: products.d/_service
diff --git a/.github/workflows/obs-service-shared.yml b/.github/workflows/obs-service-shared.yml
index 4c4a33693f..5c0a3ccd1e 100644
--- a/.github/workflows/obs-service-shared.yml
+++ b/.github/workflows/obs-service-shared.yml
@@ -5,21 +5,24 @@ name: Update OBS Service Package
on:
workflow_call:
secrets:
- OBS_USER:
- required: true
OBS_PASSWORD:
required: true
jobs:
update_service:
- # do not run in forks which do not set the OBS_PROJECT variable
- if: vars.OBS_PROJECT != ''
+ # do not run in forks which do not set the OBS_PROJECTS and OBS_USER variables,
+ # or the mapping for the current branch is missing
+ if: vars.OBS_PROJECTS && fromJson(vars.OBS_PROJECTS)[github.ref_name] && vars.OBS_USER
runs-on: ubuntu-latest
container:
image: registry.opensuse.org/opensuse/tumbleweed:latest
+ env:
+ # to avoid Ruby UTF-8 errors (the default is "POSIX")
+ LC_ALL: en_US.UTF-8
+
steps:
- name: Configure and refresh repositories
# disable unused repositories to have a faster refresh
@@ -43,33 +46,27 @@ jobs:
# fetch all history, we need to find the latest tag and offset for the version number
fetch-depth: 0
- - name: Git Checkout (release tag only)
- if: ${{ github.ref_type == 'tag' }}
- uses: actions/checkout@v4
-
- name: Configure git
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
+ - name: Git Checkout
+ uses: actions/checkout@v4
+ with:
+ # fetch all history with tags, we need to find the latest version tag
+ fetch-depth: 0
+ fetch-tags: true
+
- name: Configure osc
run: .github/workflows/configure_osc.sh
env:
- OBS_USER: ${{ secrets.OBS_USER }}
+ OBS_USER: ${{ vars.OBS_USER }}
OBS_PASSWORD: ${{ secrets.OBS_PASSWORD }}
- - name: Commit the rubygem-agama-yast package to ${{ vars.OBS_PROJECT }}
+ - name: Commit the rubygem-agama-yast package to ${{ fromJson(vars.OBS_PROJECTS)[github.ref_name] }}
run: rake osc:commit
working-directory: ./service
env:
# do not build the package with "osc", it takes long time
# and does not provide much value
SKIP_OSC_BUILD: 1
- OBS_PROJECT: ${{ vars.OBS_PROJECT }}
-
- - name: Submit the rubygem-agama-yast package
- # only when a tag has been pushed
- if: ${{ github.ref_type == 'tag' }}
- # the package has been comitted in the previous step, just submit it
- run: rake osc:sr:force
- working-directory: ./service
- env:
- OBS_PROJECT: ${{ vars.OBS_PROJECT }}
+ OBS_PROJECT: ${{ fromJson(vars.OBS_PROJECTS)[github.ref_name] }}
diff --git a/.github/workflows/obs-staging-autoinstallation.yml b/.github/workflows/obs-staging-autoinstallation.yml
index 6888946a16..d9c8f15f3f 100644
--- a/.github/workflows/obs-staging-autoinstallation.yml
+++ b/.github/workflows/obs-staging-autoinstallation.yml
@@ -3,9 +3,6 @@ name: Submit agama-auto
on:
# runs on pushes targeting the default branch
push:
- branches:
- - master
- - release
paths:
# run only when an autoinstallation source is changed
- autoinstallation/**
diff --git a/.github/workflows/obs-staging-live.yml b/.github/workflows/obs-staging-live.yml
index 43d9feb8a8..e0eb7ed708 100644
--- a/.github/workflows/obs-staging-live.yml
+++ b/.github/workflows/obs-staging-live.yml
@@ -1,11 +1,7 @@
name: Submit agama-installer
on:
- # runs on pushes targeting the default branch
push:
- branches:
- - master
- - release
paths:
# run only when a live ISO source is changed
- live/**
@@ -14,9 +10,10 @@ on:
workflow_dispatch:
jobs:
- update_staging_package:
- # do not run in forks which do not set the OBS_PROJECT variable
- if: vars.OBS_PROJECT != ''
+ update_obs_package:
+ # do not run in forks which do not set the OBS_PROJECTS variable,
+ # or the mapping for the current branch is missing
+ if: vars.OBS_PROJECTS && fromJson(vars.OBS_PROJECTS)[github.ref_name] && vars.OBS_USER
runs-on: ubuntu-latest
@@ -41,11 +38,11 @@ jobs:
- name: Configure osc
run: .github/workflows/configure_osc.sh
env:
- OBS_USER: ${{ secrets.OBS_USER }}
+ OBS_USER: ${{ vars.OBS_USER }}
OBS_PASSWORD: ${{ secrets.OBS_PASSWORD }}
- - name: Checkout ${{ vars.OBS_PROJECT }} agama-installer
- run: osc co -o dist ${{ vars.OBS_PROJECT }} agama-installer
+ - name: Checkout ${{ fromJson(vars.OBS_PROJECTS)[github.ref_name] }} agama-installer
+ run: osc co -o dist ${{ fromJson(vars.OBS_PROJECTS)[github.ref_name] }} agama-installer
working-directory: ./live
- name: Build sources
@@ -60,6 +57,6 @@ jobs:
run: osc diff && osc status
working-directory: ./live/dist
- - name: Commit agama-installer to ${{ vars.OBS_PROJECT }}
+ - name: Commit agama-installer to ${{ fromJson(vars.OBS_PROJECTS)[github.ref_name] }}
run: osc commit -m "Updated to Agama $GITHUB_SHA"
working-directory: ./live/dist
diff --git a/.github/workflows/obs-staging-products.yml b/.github/workflows/obs-staging-products.yml
index ea54b77394..95743e56b9 100644
--- a/.github/workflows/obs-staging-products.yml
+++ b/.github/workflows/obs-staging-products.yml
@@ -1,13 +1,9 @@
name: Submit agama-products
on:
- # runs on pushes targeting the default branch
push:
- branches:
- - master
- - release
paths:
- # run only when a Rust source is changed
+ # run only when a product source is changed
- products.d/**
# allow running manually
diff --git a/.github/workflows/obs-staging-rust.yml b/.github/workflows/obs-staging-rust.yml
index d1c7a80f61..7f8fd25f2c 100644
--- a/.github/workflows/obs-staging-rust.yml
+++ b/.github/workflows/obs-staging-rust.yml
@@ -1,11 +1,7 @@
name: Submit agama
on:
- # runs on pushes targeting the default branch
push:
- branches:
- - master
- - release
paths:
# run only when a Rust source is changed
- rust/**
diff --git a/.github/workflows/obs-staging-service.yml b/.github/workflows/obs-staging-service.yml
index e17e560061..9679811807 100644
--- a/.github/workflows/obs-staging-service.yml
+++ b/.github/workflows/obs-staging-service.yml
@@ -1,11 +1,7 @@
name: Submit rubygem-agama-yast
on:
- # runs on pushes targeting the default branch
push:
- branches:
- - master
- - release
paths:
# run only when a service source is changed
- service/**
diff --git a/.github/workflows/obs-staging-shared.yml b/.github/workflows/obs-staging-shared.yml
index 2e4a968983..e3cfade8aa 100644
--- a/.github/workflows/obs-staging-shared.yml
+++ b/.github/workflows/obs-staging-shared.yml
@@ -5,8 +5,6 @@ name: Update OBS Packages
on:
workflow_call:
secrets:
- OBS_USER:
- required: true
OBS_PASSWORD:
required: true
@@ -27,10 +25,10 @@ on:
type: string
jobs:
- update_staging_package:
- # do not run in forks which do not set the OBS_PROJECT variable,
- # for the "release" branch or a git tag use the OBS_PROJECT_RELEASE variable
- if: vars.OBS_PROJECT != '' || ((github.ref_name == 'release' || github.ref_type == 'tag') && vars.OBS_PROJECT_RELEASE != '')
+ update_obs_package:
+ # do not run in forks which do not set the OBS_PROJECTS and OBS_USER variables,
+ # or the mapping for the current branch is missing
+ if: vars.OBS_PROJECTS && fromJson(vars.OBS_PROJECTS)[github.ref_name] && vars.OBS_USER
runs-on: ubuntu-latest
@@ -38,17 +36,6 @@ jobs:
image: registry.opensuse.org/opensuse/tumbleweed:latest
steps:
- - name: Select OBS project
- id: obs_project
- run: |-
- if [ "${{ github.ref_name }}" = "release" -o "${{ github.ref_type }}" = "tag" ]; then
- echo "OBS_PROJECT=${{ vars.OBS_PROJECT_RELEASE }}" >> "$GITHUB_OUTPUT"
- echo "OBS project: ${{ vars.OBS_PROJECT_RELEASE }}"
- else
- echo "OBS_PROJECT=${{ vars.OBS_PROJECT }}" >> "$GITHUB_OUTPUT"
- echo "OBS project: ${{ vars.OBS_PROJECT }}"
- fi
-
- name: Configure and refresh repositories
# disable unused repositories to have a faster refresh
run: zypper modifyrepo -d repo-non-oss repo-openh264 repo-update && zypper ref
@@ -73,22 +60,21 @@ jobs:
- name: Configure osc
run: .github/workflows/configure_osc.sh
env:
- OBS_USER: ${{ secrets.OBS_USER }}
+ OBS_USER: ${{ vars.OBS_USER }}
OBS_PASSWORD: ${{ secrets.OBS_PASSWORD }}
- - name: Checkout ${{ steps.obs_project.outputs.OBS_PROJECT }} ${{ inputs.package_name }}
- run: osc co ${{ steps.obs_project.outputs.OBS_PROJECT }} ${{ inputs.package_name }}
+ - name: Checkout ${{ inputs.package_name }} from ${{ fromJson(vars.OBS_PROJECTS)[github.ref_name] }}
+ run: osc co ${{ fromJson(vars.OBS_PROJECTS)[github.ref_name] }} ${{ inputs.package_name }}
- name: Configure git
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: Update service revision
# only when a tag has been pushed, or "release" branch updated
- if: github.ref_type == 'tag' || github.ref_name == 'release'
+ if: inputs.service_file != ''
run: |-
echo "Updating revision to \"${{ github.ref_name }}\""
- sed -i -e 's#.*#${{ github.ref_name }}#' _service
- working-directory: ./${{ steps.obs_project.outputs.OBS_PROJECT }}/${{ inputs.package_name }}
+ sed -i -e 's#.*#${{ github.ref_name }}#' ${{ inputs.service_file }}
- name: Copy optional service file
# patch the URL in the file so it works also from forks, forks also by
@@ -96,31 +82,23 @@ jobs:
# no tag is present
if: inputs.service_file != ''
run: |
- sed -e 's#.*#https://github.com/${{ github.repository }}.git#' ${{ inputs.service_file }} > ./${{ steps.obs_project.outputs.OBS_PROJECT }}/${{ inputs.package_name }}/_service
- if [ -z "$(git tag -l)" ]; then sed -i -e 's#.*##' ./${{ steps.obs_project.outputs.OBS_PROJECT }}/${{ inputs.package_name }}/_service; fi
+ sed -e 's#.*#https://github.com/${{ github.repository }}.git#' ${{ inputs.service_file }} > ./${{ fromJson(vars.OBS_PROJECTS)[github.ref_name] }}/${{ inputs.package_name }}/_service
+ if [ -z "$(git tag -l)" ]; then sed -i -e 's#.*##' ./${{ fromJson(vars.OBS_PROJECTS)[github.ref_name] }}/${{ inputs.package_name }}/_service; fi
- name: Run services
- run: osc service manualrun
- working-directory: ./${{ steps.obs_project.outputs.OBS_PROJECT }}/${{ inputs.package_name }}
-
- - name: Cleanup
- # sometimes the "osc service" run does not cleanup properly all
- # downloaded NPM package tarballs and they are accidentally added to the
- # OBS package, so delete any TGZ files present
- run: rm -vf *.tgz
- working-directory: ./${{ steps.obs_project.outputs.OBS_PROJECT }}/${{ inputs.package_name }}
+ run: |
+ osc service manualrun
+ # sometimes the "osc service" run does not cleanup properly all
+ # downloaded NPM package tarballs and they are accidentally added to the
+ # OBS package, so delete any TGZ files present
+ rm -vf *.tgz
+ working-directory: ./${{ fromJson(vars.OBS_PROJECTS)[github.ref_name] }}/${{ inputs.package_name }}
- name: Check status
run: osc addremove && osc diff && osc status
- working-directory: ./${{ steps.obs_project.outputs.OBS_PROJECT }}/${{ inputs.package_name }}
+ working-directory: ./${{ fromJson(vars.OBS_PROJECTS)[github.ref_name] }}/${{ inputs.package_name }}
- - name: Commit ${{ inputs.package_name }} to ${{ steps.obs_project.outputs.OBS_PROJECT }}
+ - name: Commit ${{ inputs.package_name }} to ${{ fromJson(vars.OBS_PROJECTS)[github.ref_name] }}
run: |-
osc commit -m "Updated to $(sed -e '/^version:/!d' -e 's/version: *\(.*\)/\1/' agama.obsinfo) ($(sed -e '/^commit:/!d' -e 's/commit: *\(.*\)/\1/' agama.obsinfo))"
- working-directory: ./${{ steps.obs_project.outputs.OBS_PROJECT }}/${{ inputs.package_name }}
-
- - name: Submit the package
- # only when a tag has been pushed
- if: github.ref_type == 'tag'
- run: osc sr --yes -m "Releasing version ${{ github.ref_name }}"
- working-directory: ./${{ steps.obs_project.outputs.OBS_PROJECT }}/${{ inputs.package_name }}
+ working-directory: ./${{ fromJson(vars.OBS_PROJECTS)[github.ref_name] }}/${{ inputs.package_name }}
diff --git a/.github/workflows/obs-staging-web.yml b/.github/workflows/obs-staging-web.yml
index 6480cfda4a..b457caca32 100644
--- a/.github/workflows/obs-staging-web.yml
+++ b/.github/workflows/obs-staging-web.yml
@@ -1,11 +1,7 @@
name: Submit agama-web-ui
on:
- # runs on pushes targeting the default branch
push:
- branches:
- - master
- - release
paths:
# run only when a web frontend source is changed
- web/**
diff --git a/devel/README.md b/devel/README.md
new file mode 100644
index 0000000000..f88e979cb5
--- /dev/null
+++ b/devel/README.md
@@ -0,0 +1,117 @@
+# Development script
+
+This directory contains scripts useful for Agama development.
+
+## Git autosubmission to OBS
+
+The [branch2obs.sh](./branch2obs.sh) script creates an OBS project and configures the GitHub Actions
+for automatic submission from the specified Git branch or the current branch. Each branch can be
+submitted to a different OBS project.
+
+There are several use cases for this script. You can use it for [building testing
+images](#testing-builds) with patched Agama so the testers can easily test your fixes. Another use
+case is using it for a long running feature or refactoring, especially when more people work on
+that.
+
+And last but not least, it can be used for preparing a new [version for release](#release-builds).
+The release branch can be configured to be submitted to a special OBS release project while the
+master continues in accepting new features for the future release and is submitted to the usual
+development project.
+
+### Used tools
+
+The script requires the `git`, `gh`, `jq` and `osc` command line tools to be installed. The `osc`
+and `gh` tools need to be configured/authenticated against OBS respective GitHub. Do not worry the
+script checks for that.
+
+### GitHub configuration
+
+If you run the script in your GitHub fork then you need to configure the OBS credentials. When
+running in the original repository it will use an already pre-configured OBS user, you do not need
+to change anything.
+
+You need to create the `OBS_USER` action variable containing your OBS login name. You can do that
+from command line running command
+
+ gh -R /agama variable set OBS_USER --body
+
+where `gh_user` is your GitHub login name and `obs_user` your OBS login name.
+
+Alternatively you can create the variable manually by visiting URL
+
+ https://github.com//agama/settings/variables/actions/new
+
+where `gh_user` is your GitHub login name. On that page create variable `OBS_USER` with your OBS
+login name.
+
+Similarly we need to enter the OBS password, but as this is sensitive private value we use GitHub
+secret for that. From command line run this command
+
+ gh -R /agama secret set OBS_PASSWORD
+
+where `gh_user` is your GitHub login name. The command will interactively ask for the password.
+
+Or you can create the secret in browser going to this page
+
+ https://github.com//agama/settings/secrets/actions/new`
+
+where `gh_user` is your GitHub login name. Create a new secret with name `OBS_PASSWORD` and
+enter your OBS password as the value.
+
+### Testing builds
+
+This works in both original repository and in a fork.
+
+- Create a new branch in git and push it to GitHub
+- Run the `branch2obs.sh` script
+- The Git branch name is by default used in the OBS project name
+ - `systemsmanagement:Agama:branches:` for the original repository
+ - `home::Agama:branches:` for forks
+
+### Release builds
+
+This works only in the original repository because is uses the
+[systemsmanagement:Agama:Release](https://build.opensuse.org/project/show/systemsmanagement:Agama:Release)
+project for submitting.
+
+- Create a new release branch in git and push it to GitHub
+ - `git checkout -b beta2`
+ - `git push origin beta2`
+- Configure submission, use the systemsmanagement:Agama:Release project as the target
+ - `branch2obs.sh -t systemsmanagement:Agama:Release`
+- Bump the version in master branch for the next release
+ - `git checkout master`
+ - Update the ISO version in `live/src/agama-installer.kiwi`, use the `pre` suffix to distinguish
+ between a development version and the final version. I.e. for Beta3 change the version from `12`
+ to `13pre`.
+ - Push the changes
+ - `git commit -a`
+ - `git push`
+ - Configure that the version tag is submitted to the Devel project as well:
+ - `branch2obs.sh -b v13.pre -p systemsmanagement:Agama:Devel`
+ - Important: The version tag needs to contain the dot separator between the version and "pre"
+ suffix! It is used in the Agama Ruby gem version and Ruby Gemspec is quite picky about the
+ version format.
+ - Create the version tag and push it to GitHub
+ - `git tag -s -m "Version v13.pre" v13.pre`
+ - `git push origin v13.pre`
+ - Important: The new version tag must not be reachable from the release branch otherwise it
+ would use this version as well. That special version bump commit created before ensures that.
+- Now the new features can be committed to the `master` branch without breaking the release code.
+- Do not forget to merge the fixes from the release branch also to `master`.
+- When the development for the next release is open in `master` remove the `pre` suffix from the
+ version (use the same process as described above without the `pre` suffix).
+- The "pre" tag can be removed from Git, it is not used anymore.
+- You might remove the mapping for the previous release branch from the
+ [OBS_PROJECTS](https://github.com/agama-project/agama/settings/variables/actions/OBS_PROJECTS)
+ GitHub variable. Just to avoid accidentally updating the packages with the old
+ code when a commit is added to the old branch.
+
+## Implementation details
+
+The mapping between the Git branch and the target OBS project is stored in the
+[OBS_PROJECTS](https://github.com/agama-project/agama/settings/variables/actions/OBS_PROJECTS)
+GitHub variable. It is in JSON format and maps the Git branch name to the OBS project name.
+
+The GitHub submission actions check the mapping value for the current branch/tag and if no mapping
+is found the submission is skipped.
diff --git a/devel/branch2obs.sh b/devel/branch2obs.sh
new file mode 100755
index 0000000000..450f7a36b8
--- /dev/null
+++ b/devel/branch2obs.sh
@@ -0,0 +1,191 @@
+#! /usr/bin/bash
+
+# This script configures autosubmission from a GitHub branch to an OBS project.
+# Works with the original project and with forks as well.
+
+usage () {
+ echo "Usage: $0 [options]"
+ echo
+ echo "Options:"
+ echo " -a - keep all original build archs (default: build only x86_64)"
+ echo " -b - source git branch or tag (default: current git branch)"
+ echo " -p - target OBS project (based on the git branch)"
+ echo " -t - keep all original build targets (default: disable Leap 16.0)"
+ echo " -h - print this help"
+}
+
+# process command line arguments
+while getopts ":ab:hp:t" opt; do
+ case ${opt} in
+ a)
+ ALL_ARCHS=true
+ ;;
+ b)
+ branch="${OPTARG}"
+ ;;
+ p)
+ PROJECT="${OPTARG}"
+ ;;
+ t)
+ ALL_TARGETS=true
+ ;;
+ h)
+ usage
+ exit 0
+ ;;
+ :)
+ echo "ERROR: Missing argument for option -${OPTARG}"
+ echo
+ usage
+ exit 1
+ ;;
+ ?)
+ echo "ERROR: Invalid option -${OPTARG}"
+ echo
+ usage
+ exit 1
+ ;;
+ esac
+done
+
+# check if all needed tools are installed
+tools=(git gh jq osc)
+for tool in "${tools[@]}"; do
+ if ! command -v "$tool" >/dev/null 2>&1; then
+ echo "Tool \"$tool\" is not installed, please run \"sudo zypper install $tool\""
+ exit 1
+ fi
+done
+
+# check if osc is authenticated
+osc_user=$(osc user | sed "s/^\([^:]*\):.*$/\\1/")
+if [ -z "$osc_user" ]; then
+ echo "ERROR: Cannot read the osc user, please configure osc"
+ exit 1
+fi
+
+# check if gh is authenticated
+if ! gh auth status --active > /dev/null 2>&1; then
+ echo "ERROR: Not logged into a GitHub account"
+ echo "Run \"gh auth login\" to log into your GitHub account"
+ exit 1
+fi
+
+# git branch from the command line or the current git branch
+BRANCH=${branch-$(git rev-parse --abbrev-ref HEAD)}
+echo "Git branch: $BRANCH"
+
+repo_slug=$(gh repo view --json nameWithOwner -q ".nameWithOwner")
+
+# is this repository a GitHub fork?
+if [ "$repo_slug" = "agama-project/agama" ]; then
+ if [ -z "$PROJECT" ]; then
+ if [ "$BRANCH" = "master" ]; then
+ PROJECT="systemsmanagement:Agama:Devel"
+ else
+ PROJECT="systemsmanagement:Agama:branches:${BRANCH}"
+ fi
+ fi
+else
+ echo "GitHub fork detected"
+
+ # check if OBS_USER and OBS_PASSWORD are defined in a fork
+ gh_obs_user=$(gh -R "$repo_slug" variable get OBS_USER 2> /dev/null)
+ if [ -z "$gh_obs_user" ]; then
+ echo "ERROR: OBS_USER variable is not defined in the GitHub configuration"
+ echo "Run this command to configure your OBS user name:"
+ echo " gh -R \"$repo_slug\" variable set OBS_USER --body \"$osc_user\""
+ exit 1
+ fi
+
+ if ! gh -R "$repo_slug" secret list 2> /dev/null | grep -q OBS_PASSWORD; then
+ echo "ERROR: OBS password is not defined in the GitHub configuration"
+ echo "Run this command to configure your OBS password:"
+ echo " gh -R \"$repo_slug\" secret set OBS_PASSWORD"
+ exit 1
+ fi
+
+ if [ -z "$PROJECT" ]; then
+ PROJECT="home:${osc_user}:Agama:branches:${BRANCH}"
+ fi
+fi
+
+echo "OBS project: $PROJECT"
+echo
+
+# check if the project already exists
+if osc ls "$PROJECT" > /dev/null 2>&1; then
+ echo "Project $PROJECT already exists, not branching"
+else
+ echo "Creating project $PROJECT..."
+ # packages to branch
+ packages=(agama agama-installer agama-auto agama-products agama-web-ui rubygem-agama-yast)
+ for pkg in "${packages[@]}"; do
+ echo "Branching package $pkg"
+ # branch the package
+ osc branch systemsmanagement:Agama:Devel "$pkg" "$PROJECT" > /dev/null
+ # detach branch so the package is not updated when the original package changes,
+ # this also avoids possible conflicts
+ osc detachbranch "$PROJECT" "$pkg"
+ done
+
+ # disable building on aarch64, ppc64le, i586 and s390x, usually not needed
+ if [ "$ALL_ARCHS" != true ]; then
+ echo "Disabling build on aarch64, i586, ppc64le and s390x"
+ osc meta prj "$PROJECT" | \
+ sed "/aarch64<\/arch>/d;/i586<\/arch>/d;/ppc64le<\/arch>/d;/s390x<\/arch>/d;" | \
+ osc meta prj -F - "$PROJECT"
+ fi
+
+ # disable Leap 16.0 target
+ if [ "$ALL_TARGETS" != true ]; then
+ echo "Disabling openSUSE Leap 16.0 build target"
+ osc meta prj "$PROJECT" | \
+ sed 's####' | \
+ osc meta prj -F - "$PROJECT"
+ fi
+
+ # enable publishing of the built packages and images (delete the disabled publish section)
+ echo "Enable publishing of the build results"
+ osc meta prj "$PROJECT" | sed "/^\s*\s*$/,/^\s*<\/publish>\s*$/d" | \
+ osc meta prj -F - "$PROJECT"
+
+ echo "Set project description"
+ url=$(gh repo view --json url --jq .url)
+ osc meta prj "$PROJECT" |
+ sed -e "s#.*#$url/tree/$BRANCH#" \
+ -e "s#.*#Agama from Git#" \
+ -e "s#.*#This project contains the latest packages built from repository $repo_slug, branch \"$BRANCH\".#" | \
+ osc meta prj -F - "$PROJECT"
+fi
+
+# configure OBS_PROJECTS GitHub variable
+projects=$(gh -R "$repo_slug" variable get OBS_PROJECTS 2> /dev/null)
+
+if [ -z "$projects" ]; then
+ # fallback to empty JSON if not defined yet
+ projects="{}"
+fi
+
+# insert the mapping for the new branch
+echo "$projects" | jq ". += { \"$BRANCH\" : \"$PROJECT\" } " | gh -R "$repo_slug" variable set OBS_PROJECTS
+
+# to really synchronize the GitHub content with OBS trigger the autosubmission jobs if the remote
+# brach already exists or print the instructions for later
+workflows=(obs-staging-autoinstallation.yml obs-staging-live.yml obs-staging-products.yml obs-staging-rust.yml obs-staging-service.yml obs-staging-web.yml)
+if git ls-remote --exit-code --heads origin "$BRANCH" > /dev/null; then
+ for workflow in "${workflows[@]}"; do
+ echo "Starting GitHub Action $workflow..."
+ gh workflow run "$workflow" --ref "$BRANCH"
+ done
+else
+ echo "After creating the remote branch trigger the submission actions on the web"
+ echo "or run these commands:"
+ echo
+ for workflow in "${workflows[@]}"; do
+ echo " gh workflow run \"$workflow\" --ref \"$BRANCH\""
+ done
+fi
+
+echo
+echo "Git branch \"$BRANCH\" is now automatically submitted to OBS project \"$PROJECT\""