2019-06-10 08:27:55 +00:00
|
|
|
stages:
|
|
|
|
- deploy_stage
|
|
|
|
- failed_stage
|
2019-06-12 10:13:28 +00:00
|
|
|
- pages_stage
|
2019-06-10 08:27:55 +00:00
|
|
|
|
2019-05-11 09:19:25 +00:00
|
|
|
image: alpine:latest # Use the latest version of Alpine Linux docker image
|
2018-10-09 06:18:46 +00:00
|
|
|
|
2019-06-10 08:27:55 +00:00
|
|
|
deploy_job:
|
|
|
|
stage: deploy_stage
|
|
|
|
|
|
|
|
before_script:
|
|
|
|
# Install dependencies
|
|
|
|
- 'which ssh-agent || ( apk update && apk add openssh-client git grep)'
|
2018-10-09 06:18:46 +00:00
|
|
|
|
2019-06-10 08:27:55 +00:00
|
|
|
# Run ssh-agent
|
|
|
|
- eval $(ssh-agent -s)
|
2018-10-09 06:18:46 +00:00
|
|
|
|
2019-06-10 08:27:55 +00:00
|
|
|
# Import private key with ed25519 workaround
|
|
|
|
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
|
2019-10-01 05:45:59 +00:00
|
|
|
- echo "$GH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
|
2018-10-09 06:18:46 +00:00
|
|
|
|
2019-06-10 08:27:55 +00:00
|
|
|
# Create the SSH directory and give it the right permissions
|
|
|
|
- mkdir -p ~/.ssh
|
|
|
|
- chmod 700 ~/.ssh
|
2018-10-09 06:18:46 +00:00
|
|
|
|
2019-06-10 08:27:55 +00:00
|
|
|
# Add gitlab.com as ssh known host
|
2019-10-01 05:45:59 +00:00
|
|
|
- echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
|
2019-06-10 08:27:55 +00:00
|
|
|
- chmod 644 ~/.ssh/known_hosts
|
2018-10-09 06:18:46 +00:00
|
|
|
|
2019-06-10 08:27:55 +00:00
|
|
|
# Set commit author
|
|
|
|
- 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
|
|
|
|
|
|
|
# SSH to gitlab.com
|
|
|
|
- ssh git@gitlab.com
|
|
|
|
|
|
|
|
# Shallow cloning for faster cloning
|
2018-10-10 04:44:59 +00:00
|
|
|
- git clone --depth 3 git@gitlab.com:curben/urlhaus-filter.git build
|
2018-10-10 06:57:16 +00:00
|
|
|
- cd build/
|
2018-10-09 06:18:46 +00:00
|
|
|
|
2019-10-01 11:57:48 +00:00
|
|
|
script:
|
2019-05-27 05:31:57 +00:00
|
|
|
# Run scripts
|
2019-05-29 05:15:08 +00:00
|
|
|
- sh script.sh
|
2018-10-09 06:18:46 +00:00
|
|
|
|
2019-05-28 00:21:49 +00:00
|
|
|
# Commit the changes
|
2019-05-28 00:31:09 +00:00
|
|
|
- sh utils/commit.sh
|
2019-05-28 00:21:49 +00:00
|
|
|
|
2019-10-01 11:57:48 +00:00
|
|
|
after_script:
|
|
|
|
- cd build/
|
|
|
|
|
|
|
|
# Re-add ssh key https://gitlab.com/gitlab-org/gitlab-runner/issues/1926
|
|
|
|
- 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 config --global user.name "curben-bot"
|
|
|
|
- git config --global user.email "curben-bot@users.noreply.gitlab.com"
|
|
|
|
- git diff-index --quiet HEAD || git commit -m "Success pipeline"
|
|
|
|
|
|
|
|
- ssh git@gitlab.com
|
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
|
2019-10-01 11:57:48 +00:00
|
|
|
# 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
|
2019-06-10 08:27:55 +00:00
|
|
|
|
|
|
|
failed_job:
|
|
|
|
stage: failed_stage
|
|
|
|
|
|
|
|
script:
|
2019-10-01 11:57:48 +00:00
|
|
|
- cd build/
|
|
|
|
- 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
|
|
|
|
- git config --global user.name "curben-bot"
|
|
|
|
- git config --global user.email "curben-bot@users.noreply.gitlab.com"
|
|
|
|
- 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-01 11:57:48 +00:00
|
|
|
- ssh git@gitlab.com
|
2019-10-01 12:08:37 +00:00
|
|
|
- git push origin master
|
2019-10-01 11:57:48 +00:00
|
|
|
- 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
|
2019-06-10 08:27:55 +00:00
|
|
|
|
|
|
|
# Run this job only when deploy_job failed
|
|
|
|
when: on_failure
|
|
|
|
|
|
|
|
only:
|
|
|
|
- schedules
|
|
|
|
- web
|