trigger UBI images build:
  stage: postrelease
  extends:
  - .rules:release:all
  variables:
    BUILD_RELEASE: ${CI_COMMIT_REF_NAME}
  trigger: gitlab-org/ci-cd/gitlab-runner-ubi-images

trigger runner-incept tests:
  rules:
    # copy of .rules:merge_request_pipelines:no_docs:only_canonical, slightly modified for variables
    - if: '$CI_PROJECT_NAMESPACE !~ /^gitlab-org($|\/)/'
      when: never
    - if: $CI_PROJECT_PATH != "gitlab-org/gitlab-runner"
      when: never
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
      changes: !reference [.code-backstage-patterns]
      variables:
        UPSTREAM_CI_COMMIT_REF: "refs/merge-requests/${CI_MERGE_REQUEST_IID}/merge"
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
      changes: !reference [.code-backstage-patterns]
      variables:
        UPSTREAM_CI_COMMIT_REF: $CI_COMMIT_REF_NAME
    - if: $CI_COMMIT_REF_NAME =~ /\Av[0-9]+\.[0-9]+\.[0-9]+?\z/
      changes: !reference [.code-backstage-patterns]
      variables:
        UPSTREAM_CI_COMMIT_REF: $CI_COMMIT_REF_NAME
    - if: $CI_COMMIT_REF_NAME =~ /\Av[0-9]+\.[0-9]+\.[0-9]+(-rc[0-9]+)?\z/
      changes: !reference [.code-backstage-patterns]
      variables:
        UPSTREAM_CI_COMMIT_REF: $CI_COMMIT_REF_NAME
  needs:
    - binaries
    - "helper images"
  stage: postrelease
  variables:
    UPSTREAM_CI_COMMIT_REF: $CI_COMMIT_BRANCH
    UPSTREAM_CI_COMMIT_SHORT_SHA: $CI_COMMIT_SHORT_SHA
  trigger:
    project: gitlab-org/ci-cd/tests/runner-incept
    # strategy: depend

static QA:
  extends:
  - .rules:merge_request_pipelines:no_docs
  - .no_cache
  stage: postrelease
  image: alpine:3.14.2
  needs:
  - code_quality
  script: |
    if [ "$(cat gl-code-quality-report.json)" != "[]" ] ; then
      apk add -U --no-cache jq > /dev/null
      jq -C . gl-code-quality-report.json
      exit 1
    fi

.verify-resources:
  extends:
    - .rules:merge_request_pipelines:no_docs
    - .docker
  stage: postrelease
  script:
    - mage resources:verifyAll

verify development resources:
  extends:
  - .verify-resources
  - .rules:release:development:merge-requests
  needs:
  - job: "development docker images"
    artifacts: true

verify bleeding edge resources:
  extends:
  - .verify-resources
  - .rules:release:bleeding-edge
  needs:
  - job: "bleeding edge docker images"
    artifacts: true

verify stable resources:
  extends:
  - .verify-resources
  - .rules:release:stable:branch
  needs:
  - job: "stable docker images"
    artifacts: true

stable gitlab release:
  stage: postrelease
  extends:
  - .rules:release:stable-or-rc
  dependencies: []
  image: registry.gitlab.com/gitlab-org/release-cli:latest
  variables:
    CHANGELOG: https://gitlab.com/gitlab-org/gitlab-runner/blob/$CI_COMMIT_TAG/CHANGELOG.md
    S3: https://gitlab-runner-downloads.s3.amazonaws.com/$CI_COMMIT_TAG
    # Setting the CI_PROJECT_ID variable explicitly because we're running this job
    # also from the https://gitlab.com/gitlab-org/security/gitlab-runner fork. But it
    # should still create the release entry in the canonical one.
    CI_PROJECT_ID: 250833
  environment:
    name: stable/gitlab
    url: https://gitlab.com/gitlab-org/gitlab-runner/-/releases
  before_script: []
  script:
  - echo "Releasing to $S3"
  release:
    name: '$CI_COMMIT_TAG'
    description: |
      See [the changelog]($CHANGELOG) :rocket:

      GitLab Runner documentation can be found at https://docs.gitlab.com/runner/.
    tag_name: '$CI_COMMIT_TAG'
    ref: '$CI_COMMIT_TAG'
    assets:
      links:
      # binaries
      - name: 'binary: Linux amd64'
        url: '$S3/binaries/gitlab-runner-linux-amd64'
        filepath: '/binaries/gitlab-runner-linux-amd64'
      - name: 'binary: Linux amd64-fips'
        url: '$S3/binaries/gitlab-runner-linux-amd64-fips'
        filepath: '/binaries/gitlab-runner-linux-amd64-fips'
      - name: 'binary: Linux 386'
        url: '$S3/binaries/gitlab-runner-linux-386'
        filepath: '/binaries/gitlab-runner-linux-386'
      - name: 'binary: Linux arm'
        url: '$S3/binaries/gitlab-runner-linux-arm'
        filepath: '/binaries/gitlab-runner-linux-arm'
      - name: 'binary: Linux ppc64el'
        url: '$S3/binaries/gitlab-runner-linux-ppc64el'
        filepath: '/binaries/gitlab-runner-linux-ppc64el'
      - name: 'binary: Linux s390x'
        url: '$S3/binaries/gitlab-runner-linux-s390x'
        filepath: '/binaries/gitlab-runner-linux-s390x'

      - name: 'binary: macOS amd64'
        url: '$S3/binaries/gitlab-runner-darwin-amd64'
        filepath: '/binaries/gitlab-runner-darwin-amd64'
      - name: 'binary: macOS arm64'
        url: '$S3/binaries/gitlab-runner-darwin-arm64'
        filepath: '/binaries/gitlab-runner-darwin-arm64'

      - name: 'binary: FreeBSD amd64'
        url: '$S3/binaries/gitlab-runner-freebsd-amd64'
        filepath: '/binaries/gitlab-runner-freebsd-amd64'
      - name: 'binary: FreeBSD arm'
        url: '$S3/binaries/gitlab-runner-freebsd-arm'
        filepath: '/binaries/gitlab-runner-freebsd-arm'
      - name: 'binary: FreeBSD 386'
        url: '$S3/binaries/gitlab-runner-freebsd-386'
        filepath: '/binaries/gitlab-runner-freebsd-386'

      - name: 'binary: Windows amd64'
        url: '$S3/binaries/gitlab-runner-windows-amd64.zip'
        filepath: '/binaries/gitlab-runner-windows-amd64.zip'
      - name: 'binary: Windows i386'
        url: '$S3/binaries/gitlab-runner-windows-386.zip'
        filepath: '/binaries/gitlab-runner-windows-386.zip'

      # DEB packages
      - name: 'package: DEB amd64'
        url: '$S3/deb/gitlab-runner_amd64.deb'
        filepath: '/packages/deb/gitlab-runner_amd64.deb'
      - name: 'package: DEB i686'
        url: '$S3/deb/gitlab-runner_i686.deb'
        filepath: '/packages/deb/gitlab-runner_i686.deb'
      - name: 'package: DEB armel'
        url: '$S3/deb/gitlab-runner_armel.deb'
        filepath: '/packages/deb/gitlab-runner_armel.deb'
      - name: 'package: DEB armhf'
        url: '$S3/deb/gitlab-runner_armhf.deb'
        filepath: '/packages/deb/gitlab-runner_armhf.deb'
      - name: 'package: DEB aarch64'
        url: '$S3/deb/gitlab-runner_aarch64.deb'
        filepath: '/packages/deb/gitlab-runner_aarch64.deb'
      - name: 'package: DEB arm64'
        url: '$S3/deb/gitlab-runner_arm64.deb'
        filepath: '/packages/deb/gitlab-runner_arm64.deb'
      - name: 'package: DEB ppc64el'
        url: '$S3/deb/gitlab-runner_ppc64el.deb'
        filepath: '/packages/deb/gitlab-runner_ppc64el.deb'
      - name: 'package: DEB s390x'
        url: '$S3/deb/gitlab-runner_s390x.deb'
        filepath: '/packages/deb/gitlab-runner_s390x.deb'

      # RPM packages
      - name: 'package: RPM amd64'
        url: '$S3/rpm/gitlab-runner_amd64.rpm'
        filepath: '/packages/rpm/gitlab-runner_amd64.rpm'
      - name: 'package: RPM amd64-fips'
        url: '$S3/rpm/gitlab-runner_amd64-fips.rpm'
        filepath: '/packages/rpm/gitlab-runner_amd64-fips.rpm'
      - name: 'package: RPM i686'
        url: '$S3/rpm/gitlab-runner_i686.rpm'
        filepath: '/packages/rpm/gitlab-runner_i686.rpm'
      - name: 'package: RPM arm'
        url: '$S3/rpm/gitlab-runner_arm.rpm'
        filepath: '/packages/rpm/gitlab-runner_arm.rpm'
      - name: 'package: RPM armhf'
        url: '$S3/rpm/gitlab-runner_armhf.rpm'
        filepath: '/packages/rpm/gitlab-runner_armhf.rpm'
      - name: 'package: RPM arm64'
        url: '$S3/rpm/gitlab-runner_arm64.rpm'
        filepath: '/packages/rpm/gitlab-runner_arm64.rpm'
      - name: 'package: RPM aarch64'
        url: '$S3/rpm/gitlab-runner_aarch64.rpm'
        filepath: '/packages/rpm/gitlab-runner_aarch64.rpm'
      - name: 'package: RPM ppc64le'
        url: '$S3/rpm/gitlab-runner_ppc64le.rpm'
        filepath: '/packages/rpm/gitlab-runner_ppc64le.rpm'
      - name: 'package: RPM s390x'
        url: '$S3/rpm/gitlab-runner_s390x.rpm'
        filepath: '/packages/rpm/gitlab-runner_s390x.rpm'

      # Other files
      - name: 'checksums'
        url: '$S3/release.sha256'
        filepath: '/release.sha256'
      - name: 'checksums GPG signature'
        url: '$S3/release.sha256.asc'
        filepath: '/release.sha256.asc'
      - name: 'other release artifacts'
        url: '$S3/index.html'
        filepath: '/index.html'