stages:
  - verify
  - trigger

variables:
  GIT_STRATEGY: clone
  GIT_DEPTH: "500"

lint:
  stage: verify
  image: alpinelinux/apkbuild-lint-tools:latest
  interruptible: true
  script:
    - lint
  allow_failure: true
  only:
    - merge_requests
  tags:
    - docker-alpine
    - x86_64

.build:
  stage: verify
  image: alpinelinux/alpine-gitlab-ci:latest
  interruptible: true
  script:
    - build.sh
  artifacts:
    paths:
      - packages/
      - keys/
      - logs/
    expire_in: 1 day
    when: always
  only:
    - merge_requests

build-x86_64:
  extends: .build
  artifacts:
    name: MR${CI_MERGE_REQUEST_ID}_x86_64
  tags:
    - docker-alpine
    - ci-build
    - x86_64

build-x86:
  extends: .build
  image:
    name: alpinelinux/alpine-gitlab-ci:latest-x86
    entrypoint: ["linux32", "sh", "-c"]
  artifacts:
    name: MR${CI_MERGE_REQUEST_ID}_x86
  tags:
    - docker-alpine
    - ci-build
    - x86

build-s390x:
  extends: .build
  artifacts:
    name: MR${CI_MERGE_REQUEST_ID}_s390x
  tags:
    - docker-alpine
    - ci-build
    - s390x

build-ppc64le:
  extends: .build
  artifacts:
    name: MR${CI_MERGE_REQUEST_ID}_ppc64le
  tags:
    - docker-alpine
    - ci-build
    - ppc64le

build-aarch64:
  extends: .build
  artifacts:
    name: MR${CI_MERGE_REQUEST_ID}_aarch64
  tags:
    - docker-alpine
    - ci-build
    - aarch64

build-armv7:
  extends: .build
  image:
    name: alpinelinux/alpine-gitlab-ci:latest-armv7
    entrypoint: ["linux32", "sh", "-c"]
  artifacts:
    name: MR${CI_MERGE_REQUEST_ID}_armv7
  tags:
    - docker-alpine
    - ci-build
    - armv7

build-armhf:
  extends: .build
  image:
    name: alpinelinux/alpine-gitlab-ci:latest-armhf
    entrypoint: ["linux32", "sh", "-c"]
  artifacts:
    name: MR${CI_MERGE_REQUEST_ID}_armhf
  tags:
    - docker-alpine
    - ci-build
    - armhf

build-riscv64-emulated:
  extends: .build
  when: manual
  artifacts:
    name: MR${CI_MERGE_REQUEST_ID}_riscv64
  tags:
    - docker-alpine
    - ci-build
    - riscv64

trigger_build_image:
  stage: trigger
  only:
    - tags
  variables:
    APORTS_TAG: $CI_COMMIT_TAG
  trigger:
    project: clandmeter/alpine-disk-image
    branch: master
