Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reusable gitlab workflows #42

Merged
merged 47 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
3b0a4de
add initial gitlab-ci.yml
velomatt Feb 15, 2024
f9f7af6
update sync rules
velomatt Feb 15, 2024
c5ccdf1
add shellcheck style template
velomatt Feb 15, 2024
ee650ed
sync to master
velomatt Feb 15, 2024
b711843
switch image to alpine
velomatt Feb 15, 2024
5d277c1
Update sync to be more generic
velomatt Feb 15, 2024
d12e027
Move sync job to separate file for downstream trigger
velomatt Feb 15, 2024
512efe9
fix local
velomatt Feb 15, 2024
3f43c2c
move rules from upstream to downstream
velomatt Feb 15, 2024
c5127cd
move rules from upstream to downstream
velomatt Feb 15, 2024
37c8381
revert rules from child to parent
velomatt Feb 15, 2024
b4e7e04
update defaults
velomatt Feb 15, 2024
f53ffcf
update defaults
velomatt Feb 15, 2024
673f66d
Move vars to downstream
velomatt Feb 15, 2024
6da9806
streamline rules
velomatt Feb 15, 2024
5a57362
add trigger defaults
velomatt Feb 16, 2024
84e1ae9
add trigger defaults
velomatt Feb 16, 2024
e3ee961
revert default trigger
velomatt Feb 16, 2024
d612dd6
re-enable manual sync
velomatt Feb 16, 2024
001b5ce
streamline vars
velomatt Feb 16, 2024
c5438a4
try to set default rules
velomatt Feb 16, 2024
07598d3
revert rules
velomatt Feb 16, 2024
dae1815
revert rules
velomatt Feb 16, 2024
8a2a6a1
remove stage
velomatt Feb 16, 2024
a589b39
remove manual trigger
velomatt Feb 16, 2024
9853f9a
streamline test
velomatt Feb 16, 2024
d1acc37
move variables
velomatt Feb 16, 2024
77f6118
Shellcheck doesn't need anything so it can run first
velomatt Feb 16, 2024
ab5aa3b
curl checkstyle template
velomatt Feb 16, 2024
7a82bc4
add curl
velomatt Feb 16, 2024
eac1cf7
add insecure curl
velomatt Feb 16, 2024
6eddfb4
debug checkstyle xslt
velomatt Feb 16, 2024
c814061
use wget instead of curl
velomatt Feb 16, 2024
8baa840
checkstyle template in yml
velomatt Feb 16, 2024
4d1c342
update method to dump file
velomatt Feb 16, 2024
feec32f
test
velomatt Feb 16, 2024
af02cec
fix filename
velomatt Feb 16, 2024
42c14b7
remove debug
velomatt Feb 16, 2024
9ccabc5
change test to lint stage
velomatt Feb 16, 2024
b04159b
remove checkstyle2junit.xslt
velomatt Feb 16, 2024
4ece360
Remove wget
velomatt Feb 16, 2024
72d7816
rename default rules
velomatt Mar 1, 2024
54bf70b
update rule names
velomatt Mar 1, 2024
c6d92a5
add push_only rule
velomatt Mar 2, 2024
9b29222
move files to .gitlab
velomatt Mar 2, 2024
058e59c
update paths
velomatt Mar 2, 2024
dde3f6e
remove unused vars
velomatt Mar 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
include:
- local: .gitlab/defaults.yml
- local: .gitlab/shellcheck.yml
- local: .gitlab/sync-github.yml

stages:
- lint
- sync

sync-github:
variables:
GITHUB_REPO: DSS
32 changes: 32 additions & 0 deletions .gitlab/defaults.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.default_rules:
merge_only:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
variables:
BRANCH_NAME: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
SONAR_BRANCH: ''
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
- if: $CI_PIPELINE_SOURCE == "web"
merge_and_push:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
variables:
BRANCH_NAME: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
SONAR_BRANCH: ''
- if: $CI_COMMIT_BRANCH == "master" && $CI_PIPELINE_SOURCE == "push"
- if: $CI_COMMIT_BRANCH =~ /^stable\/.*/ && $CI_PIPELINE_SOURCE == "push"
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
- if: $CI_PIPELINE_SOURCE == "web"
push_only:
- if: $CI_COMMIT_BRANCH == "master" && $CI_PIPELINE_SOURCE == "push"
- if: $CI_COMMIT_BRANCH =~ /^stable\/.*/ && $CI_PIPELINE_SOURCE == "push"
scheduled_sync:
- if: $CI_PIPELINE_SOURCE == "schedule" && $SCHEDULE_TYPE == "sync"

variables:
BRANCH_NAME: $CI_COMMIT_BRANCH
SONAR_BRANCH: -Dsonar.branch.name=$CI_COMMIT_BRANCH

default:
image:
name: dss-build_$BRANCH_NAME
68 changes: 68 additions & 0 deletions .gitlab/shellcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
shellcheck:
stage: lint
image: koalaman/shellcheck-alpine:$SHELLCHECK_VER
before_script:
- apk update
- apk add git xmlstarlet
- shellcheck --version
- |
cat > checkstyle2junit.xslt <<EOL
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="UTF-8" method="xml"></xsl:output>

<xsl:template match="/">
<testsuite>
<xsl:attribute name="tests">
<xsl:value-of select="count(.//file)" />
</xsl:attribute>
<xsl:attribute name="failures">
<xsl:value-of select="count(.//error)" />
</xsl:attribute>
<xsl:for-each select="//checkstyle">
<xsl:apply-templates />
</xsl:for-each>
</testsuite>
</xsl:template>

<xsl:template match="file">
<testcase>
<xsl:attribute name="classname">
<xsl:value-of select="@name" />
</xsl:attribute>
<xsl:attribute name="name">
<xsl:value-of select="@name" />
</xsl:attribute>
<xsl:apply-templates select="node()" />
</testcase>
</xsl:template>

<xsl:template match="error">
<failure>
<xsl:attribute name="type">
<xsl:value-of select="@source" />
</xsl:attribute>
<xsl:text>Line </xsl:text>
<xsl:value-of select="@line" />
<xsl:text>: </xsl:text>
<xsl:value-of select="@message" />
<xsl:text> See https://www.shellcheck.net/wiki/</xsl:text>
<xsl:value-of select="substring(@source, '12')" />
</failure>
</xsl:template>
</xsl:stylesheet>
EOL
script:
- git ls-files --exclude='*.sh' --ignored -c -z |
xargs -t --no-run-if-empty -0 shellcheck --format=checkstyle |
xmlstarlet tr checkstyle2junit.xslt >
shellcheck.xml
artifacts:
when: always
reports:
junit: shellcheck.xml
variables:
SHELLCHECK_VER: v0.9.0
needs: []
rules:
- !reference [.default_rules, merge_and_push]
21 changes: 21 additions & 0 deletions .gitlab/sync-github.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
sync-github:
stage: sync
image:
name: alpine:3.19.1
before_script:
- apk add git
- git config --global http.sslVerify false
script:
- mkdir $GITHUB_REPO && cd $GITHUB_REPO
- git clone --branch $GITHUB_BRANCH https://github.com/$GITHUB_PROJECT/$GITHUB_REPO .
- git remote rename origin old-origin
- git remote add origin https://$CI_USERNAME:$CI_TOKEN@$CI_SERVER_HOST/$CI_PROJECT_PATH.git
- git push origin $GITHUB_BRANCH:$GITLAB_BRANCH
- git push -u origin --tags
variables:
GIT_STRATEGY: none
GITHUB_PROJECT: OpenMPDK
GITHUB_BRANCH: master
GITLAB_BRANCH: master
rules:
- !reference [.default_rules, scheduled_sync]
Loading