urlhaus-filter/.gitlab-ci.yml

86 lines
2.5 KiB
YAML
Raw Normal View History

stages:
- deploy_stage
- failed_stage
image: alpine:latest # Use the latest version of Alpine Linux docker image
2018-10-09 06:18:46 +00:00
deploy_job:
stage: deploy_stage
before_script:
2019-10-02 00:46:28 +00:00
- 'which ssh-agent || (apk update && apk add openssh-client git grep)'
2018-10-09 06:18:46 +00:00
2019-10-02 00:46:28 +00:00
script:
- sh script.sh
2018-10-09 06:18:46 +00:00
- git config --global user.name "curben-bot"
- git config --global user.email "curben-bot@users.noreply.gitlab.com"
2018-10-09 06:18:46 +00:00
# Commit the changes
2019-05-28 00:31:09 +00:00
- sh utils/commit.sh
after_script:
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- echo "$GH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
# Generate successful status badge
- mkdir -p .gitlab/
- wget https://img.shields.io/badge/pipeline-passed-success.svg -O .gitlab/status.svg
- git add .gitlab/status.svg
# Only commit when diff exists https://stackoverflow.com/a/8123841
- git diff-index --quiet HEAD || git commit -m "Success pipeline"
2019-10-02 00:46:28 +00:00
- ssh -T git@gitlab.com
- git remote set-url origin git@gitlab.com:curben/urlhaus-filter.git
2019-10-01 12:08:37 +00:00
- git push origin master
2018-10-09 06:18:46 +00:00
2019-10-01 05:45:59 +00:00
# Push to mirror
# Force exit code 0
- ssh -T git@github.com || echo
2019-10-01 05:45:59 +00:00
- git remote add mirror git@github.com:curbengh/urlhaus-filter.git
2019-10-01 12:08:37 +00:00
- git push mirror master
2019-10-01 05:45:59 +00:00
2018-10-09 06:18:46 +00:00
only:
2018-10-11 00:42:35 +00:00
# Allow CI to be triggered by schedule
2018-10-09 06:18:46 +00:00
- schedules
2018-10-11 00:42:35 +00:00
# Allow CI to be triggered manually
- web
failed_job:
stage: failed_stage
2019-10-02 00:46:28 +00:00
before_script:
- 'which ssh-agent || (apk update && apk add openssh-client git grep)'
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- echo "$GH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
2019-10-02 00:46:28 +00:00
script:
- mkdir -p .gitlab/
- wget https://img.shields.io/badge/pipeline-failed-critical.svg -O .gitlab/status.svg
- git add .gitlab/status.svg
2019-10-01 12:00:34 +00:00
- git diff-index --quiet HEAD || git commit -m "Failed pipeline"
2019-10-02 00:46:28 +00:00
- ssh -T git@gitlab.com
- git remote set-url origin git@gitlab.com:curben/urlhaus-filter.git
2019-10-01 12:08:37 +00:00
- git push origin master
- ssh -T git@github.com || echo
- git remote add mirror git@github.com:curbengh/urlhaus-filter.git
2019-10-01 12:08:37 +00:00
- git push mirror master
# Run this job only when deploy_job failed
when: on_failure
only:
- schedules
- web