Support creating incremental Pages in Merge requests
Our normal merge-request process looks like this: the developer pushes the changes, then CI tests them, then somebody else does the review in the code. But since humans are not ideal, it is a good practice to download the code to your IDE and then run the application to check whether it does not fail/throw errors.
Since Gitlab released Pages, I had an idea in my mind: what if the last step would be automatized? What if I would use Pages to host versioned app (frontend) with branch-only changes during merge requests?
So, I have prepared the following .gitlab-ci.yml:
image: debian:jessie
stages:
- deploy
- cleanup
pages:
stage: deploy
only:
- merge_requests
script:
- >
mkdir -p public/${CI_COMMIT_REF_NAME};
cd public/${CI_COMMIT_REF_NAME};
echo "hello_world" > index.html;
echo "Created page: ${CI_PAGES_URL}/${CI_COMMIT_REF_NAME}/index.html";
artifacts:
paths:
- public/${CI_COMMIT_REF_NAME}
clean_after_merge_request:
stage: cleanup
only:
refs:
- master
variables:
- $CI_COMMIT_TITLE =~ /.*Merge branch '.+' into '.+'.*/
script:
- >
MR_ORIGINAL_BRANCH=$(echo "${CI_COMMIT_TITLE}" | sed -n "s@Merge branch '\([^']*\)'.*@\1@p");
echo "Removing Gitlab Pages: ${CI_PAGES_URL}/${MR_ORIGINAL_BRANCH}";
Simple stuff, the mechanism creates for every merge_request new directory with branch name in the public folder, and after the merge it removes it.
Problems that I have found:
- The CI pages mechanism does not allow to add the content incrementally. It rather just replaces the whole content instead of just create an additional folder.
- On the cleanup stage, I can, in fact, clean the application that was created during the deploy stage. But what if the merge request is closed without merging? I would want to have any mechanism that would be prone to this issue (maybe new
onlykeyword, for example,merge_request_closedwhich would be fired on merge or close/remove?) - It would be great to have a section like
Coverageon the MR page (with related link to Page) - otherwise, the user would have to look in the console logs. For example:
pages:
stage: deploy
page: ${CI_PAGES_URL}/${CI_COMMIT_REF_NAME}
only:
- merge_requests
script:
- >
mkdir -p public/${CI_COMMIT_REF_NAME};
cd public/${CI_COMMIT_REF_NAME};
echo "hello_world" > index.html;
echo "Created page: ${CI_PAGES_URL}/${CI_COMMIT_REF_NAME}/index.html";
artifacts:
paths:
- public/${CI_COMMIT_REF_NAME}