diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 233a8ce..b487501 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,11 +1,13 @@ --- stages: - test +- build - publish variables: IMAGE_NAME: ${CI_REGISTRY}/${CI_PROJECT_PATH}/cv-builder IMAGE_TAG: ${CI_COMMIT_REF_SLUG}-${CI_COMMIT_SHORT_SHA} + RELEASE_CV_FILENAME: cv-DanAnglin-${CI_COMMIT_REF_NAME}.pdf include: - template: 'Workflows/MergeRequest-Pipelines.gitlab-ci.yml' diff --git a/.gitlab/ci/cv-gitlab-ci.yml b/.gitlab/ci/cv-gitlab-ci.yml index 1637487..8d49c0f 100644 --- a/.gitlab/ci/cv-gitlab-ci.yml +++ b/.gitlab/ci/cv-gitlab-ci.yml @@ -5,65 +5,127 @@ .use-cv-builder: image: ${IMAGE_NAME}:master-cb8a29c7 -.cv-test-rules: +.cv-default-job-rules: rules: - - changes: - - "docker/Dockerfile" - when: never - when: always -.cv-publish-rules: +.cv-publish-job-rules: rules: - - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PROJECT_PATH == "dananglin/cv"' + - if: '$CI_COMMIT_REF_NAME =~ /^[0-9]{4}(.[0-9]{2}){2}$/ && $CI_PROJECT_PATH == "dananglin/cv"' when: always - - changes: - - "docker/Dockerfile" - when: never + +.default-tags: + tags: + - dananglin-general + +.release-tags: + tags: + - dananglin-cv-release #------------------------------------# # Visible jobs for CV build pipeline # #------------------------------------# - test:spellcheck: before_script: - apt-get update - apt-get -y install aspell aspell-en extends: - - .cv-test-rules + - .cv-default-job-rules + - .default-tags - .use-cv-builder - stage: test script: - go run mage.go spellcheck + stage: test test:pdf: + extends: + - .cv-default-job-rules + - .default-tags + - .use-cv-builder + script: + - go run mage.go pdf + stage: test + +build:pdf: artifacts: - expire_in: 1 hour + expire_in: "30 minutes" paths: - __output/cv.pdf extends: + - .default-tags - .use-cv-builder - - .cv-test-rules - stage: test + needs: + - job: "test:spellcheck" + artifacts: false + - job: "test:pdf" + artifacts: false + rules: + - if: '$CI_MERGE_REQUEST_IID' + when: always script: - go run mage.go pdf + stage: build -publish:pdf: - extends: +build:pdf-for-publish: + artifacts: + expire_in: "1 year" + name: cv-DanAnglin-${CI_COMMIT_REF_NAME} + paths: + - ${RELEASE_CV_FILENAME} + - build_job_id + extends: + - .cv-publish-job-rules + - .default-tags - .use-cv-builder - - .cv-publish-rules - before_script: - - eval $(ssh-agent -s) - - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - - - mkdir -p ~/.ssh && chmod 700 ~/.ssh - - echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts - - chmod 0400 ~/.ssh/known_hosts - - git remote set-url origin git@gitlab.com:${CI_PROJECT_PATH}.git - - git config --global user.email "${GITLAB_USER_EMAIL}" - - git config --global user.name "${GITLAB_USER_NAME}" - stage: publish + needs: + - job: "test:spellcheck" + artifacts: false + - job: "test:pdf" + artifacts: false script: - go run mage.go pdf - - git checkout master - - git add __output/cv.pdf - - 'git commit -m "auto: [skip ci] update CV."' - - git push origin master + - mv __output/cv.pdf ${RELEASE_CV_FILENAME} + - echo "${CI_JOB_ID}" > build_job_id + stage: build + +publish:pdf:online: + before_script: + - export BUILD_JOB_ID=$( cat build_job_id ) + extends: + - .cv-publish-job-rules + - .release-tags + image: registry.gitlab.com/gitlab-org/release-cli:v0.3.0 + needs: + - job: "build:pdf-for-publish" + artifacts: true + script: + - 'echo "Publishing CV for release ${CI_COMMIT_REF_NAME}"' + - > + release-cli create --name "CV - ${CI_COMMIT_REF_NAME}" + --description "CV published with the release-cli tool for version ${CI_COMMIT_REF_NAME}" + --tag-name "${CI_COMMIT_REF_NAME}" + --ref "${CI_COMMIT_REF_NAME}" + --assets-links-name "${RELEASE_CV_FILENAME}" + --assets-links-url "https://gitlab.com/api/v4/projects/${CI_PROJECT_ID}/jobs/${BUILD_JOB_ID}/artifacts/${RELEASE_CV_FILENAME}" + stage: "publish" + variables: + GIT_STRATEGY: "none" + +# Private releases rebuilds the CV with the extra details. +publish:pdf:private: + extends: + - .cv-publish-job-rules + - .release-tags + - .use-cv-builder + needs: + - job: "test:spellcheck" + artifacts: false + - job: "test:pdf" + artifacts: false + script: + - go run mage.go pdf + - mv __output/cv.pdf ${CV_DEPLOY_DIR}/${RELEASE_CV_FILENAME} + stage: publish + variables: + CV_DEPLOY_DIR: "/CV" + CV_CONTACT_PHONE: $RELEASE_CV_CONTACT_PHONE diff --git a/.gitlab/ci/docker-gitlab-ci.yml b/.gitlab/ci/docker-gitlab-ci.yml index 620a53d..755d5f9 100644 --- a/.gitlab/ci/docker-gitlab-ci.yml +++ b/.gitlab/ci/docker-gitlab-ci.yml @@ -21,9 +21,12 @@ .docker-test-rules: rules: - - changes: + - if: '$CI_COMMIT_BRANCH' + changes: - "docker/Dockerfile" when: always + - if: '$CI_COMMIT_REF_NAME =~ /^[0-9]{4}(.[0-9]{2}){2}$/' + when: never .docker-publish-pre-post: stage: publish diff --git a/README.md b/README.md index 6d869c5..7a96e50 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Support for other formats such as HTML will be available soon. ### View/Download the CV -The latest build of the generated PDF document can be downloaded [here](__output/cv.pdf) +The latest build of the generated PDF document can be downloaded from the [release](https://gitlab.com/dananglin/cv/-/releases) page of the project in GitLab. ## Dependencies @@ -82,7 +82,7 @@ To use the image follow the steps below: The PDF document can be generated by running the following command: ```bash -$ make pdf +$ go run mage.go pdf ``` The PDF generation is completed in two steps: diff --git a/__output/cv.pdf b/__output/cv.pdf deleted file mode 100644 index d30736b..0000000 Binary files a/__output/cv.pdf and /dev/null differ