Commit d8ecbe47 authored by Florian Schäfer's avatar Florian Schäfer

Use GitLab CI instead of Circle CI

This also now only publishes the master snapshot of wikipedia.jar, now that pt_assistant is being built on Travis CI, the master snapshot of that plugin can be published there.
parent af1f64c7
Pipeline #25134096 passed with stages
in 8 minutes and 52 seconds
version: 2
jobs:
test-java-9:
docker:
- image: circleci/openjdk:9-jdk-browsers
steps:
- restore_cache: &restore_gradleGit_cache
keys:
- gradleGit-v1-{{ .Branch }}-{{ .Revision }}
- gradleGit-v1-{{ .Branch }}-
- gradleGit-v1-
- run: sudo apt install -y gettext
# Temporary workaround for https://discuss.circleci.com/t/22437
- run: |
if [ -n "$CIRCLE_TAG" ]
then
mkdir -p ~/.ssh
echo 'github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==
' >> ~/.ssh/known_hosts
git fetch --force origin "refs/tags/${CIRCLE_TAG}:refs/tags/${CIRCLE_TAG}"
fi
- checkout
- run: ./gradlew assemble test
- store_test_results:
path: ./build/test-results/test
- save_cache: &save_gradleGit_cache
key: gradleGit-v1-{{ .Branch }}-{{ .Revision }}
paths:
- "~/.gradle/caches"
- "~/.gradle/wrapper"
- ".git"
- ".gradle"
test-java-8:
docker: &jdk8_image
- image: circleci/openjdk:8-jdk-browsers
steps:
- restore_cache: *restore_gradleGit_cache
- run: sudo apt install -y gettext
# Temporary workaround for https://discuss.circleci.com/t/22437
- run: |
if [ -n "$CIRCLE_TAG" ]
then
mkdir -p ~/.ssh
echo 'github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==
' >> ~/.ssh/known_hosts
git fetch --force origin "refs/tags/${CIRCLE_TAG}:refs/tags/${CIRCLE_TAG}"
fi
- checkout
# Main commands
- run: ./gradlew assemble test generatePot generateMasterPluginList
# Storing to cache/workspace
- persist_to_workspace: &persist_build_artifacts
root: .
paths:
- .tx
- build
- save_cache: *save_gradleGit_cache
- store_artifacts:
path: ./build/dist
destination: dist
- store_artifacts:
path: ./build/tmp/jar/MANIFEST.MF
destination: dist/MANIFEST.MF
- run: |
if [ "$CIRCLE_BRANCH" == "master" ]; then
git fetch origin gh-pages
git checkout gh-pages
cp ./build/pluginMasterSnapshots .
git stage pluginMasterSnapshots
git config user.name "CircleCI $CIRCLE_BUILD_NUM"
git config user.email "deploy@circleci"
git commit -m "[ci skip] Update plugin update site for JOSM with latest version from master branch"
git push -q https://${GITHUB_TOKEN}@github.com/JOSM/wikipedia.git gh-pages > /dev/null 2>&1
fi
min-josm:
docker: *jdk8_image
steps:
- restore_cache: *restore_gradleGit_cache
- checkout
# Attach build artifacts
- attach_workspace:
at: .
# Main commands
- run: ./gradlew compileJava_minJosm
check:
docker: *jdk8_image
steps:
- restore_cache: *restore_gradleGit_cache
- run: sudo apt install -y gettext
- checkout
# Attach build artifacts
- attach_workspace:
at: .
# Main commands
- run: ./gradlew check
# Storing to workspace
- persist_to_workspace: *persist_build_artifacts
transifex-upload:
docker:
- image: circleci/python:3.6-node-browsers
steps:
- attach_workspace:
at: .
- run: pip install --user git+https://github.com/transifex/transifex-client.git@699dd42e04074be92a07b5b87e8f1ea672a6571f#egg=transifex-client
- run: export PATH="$PATH:$HOME/.local/bin" && pip install --user codecov && codecov
- run: |
export PATH="$PATH:$HOME/.local/bin" && echo "$PATH"
if [ ! -z "$TRANSIFEX_TOKEN" ]; then
TX_TOKEN="$TRANSIFEX_TOKEN" tx push -s --no-interactive
fi
# Store artifacts
- store_test_results:
path: ./build/test-results/test
- store_artifacts:
path: ./build/reports/jacoco/test
destination: jacoco
- store_artifacts:
path: ./build/reports/pmd
destination: pmd
- store_artifacts:
path: ./build/reports/tests/test
destination: junit
publish-release:
docker:
- image: circleci/golang:1.10
steps:
- restore_cache: *restore_gradleGit_cache
- checkout
- attach_workspace:
at: .
- run: go get github.com/aktau/github-release
- run: |
export TAG_SUBJECT=`git tag -l --format="%(contents:subject)" $CIRCLE_TAG`
export TAG_BODY=`git tag -l --format="%(contents:body)" $CIRCLE_TAG`
export GITHUB_USER="$CIRCLE_PROJECT_USERNAME"
export GITHUB_REPO="$CIRCLE_PROJECT_REPONAME"
github-release release --tag "$CIRCLE_TAG" --name "$TAG_SUBJECT" --description "$TAG_BODY"
github-release upload --tag "$CIRCLE_TAG" --file "./build/dist/wikipedia.jar" --name "wikipedia.jar"
github-release upload --tag "$CIRCLE_TAG" --file "./build/tmp/jar/MANIFEST.MF" --name "MANIFEST.MF"
workflows:
version: 2
build-workflow:
jobs:
- test-java-8:
filters: &always_run
tags:
only: /.*/
- test-java-9:
filters: *always_run
- check: &depends_on_test_tasks
requires:
- test-java-8
- test-java-9
filters: *always_run
- min-josm: *depends_on_test_tasks
# Runs only on master branch
- transifex-upload:
requires:
- check
- min-josm
filters:
branches:
only: master
# Runs only on tags matching /v[0-9].*/
- publish-release:
requires:
- check
- min-josm
filters:
tags:
only: /v[0-9].*/
branches:
ignore: /.*/
image: registry.gitlab.com/josm/wikipedia/java8:latest
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
cache:
paths:
- .gradle/wrapper
- .gradle/caches
###############
# Build stage #
###############
assemble:
stage: build
script:
- ./gradlew assemble
artifacts:
paths:
- build
##############
# Test stage #
##############
build:
stage: test
script:
- ./gradlew build generatePot generateSnapshotUpdateSite
artifacts:
paths:
- build
compile against min JOSM:
stage: test
script:
- ./gradlew compileJava_minJosm
compile against latest JOSM:
stage: test
script:
- ./gradlew compileJava_latestJosm
################
# Deploy stage #
################
upload to transifex:
image: python:3.6-stretch
stage: deploy
environment:
name: transifex
url: https://www.transifex.com/josm/josm/josm-plugin_wikipedia/
before_script:
- apt-get update && apt-get install -yq gettext git
- pip install git+https://github.com/transifex/transifex-client.git
script:
- TX_TOKEN="$TRANSIFEX_TOKEN" tx push -s --no-interactive
dependencies:
- build
only:
- master@JOSM/wikipedia
release:
stage: deploy
environment:
name: pages branch
url: https://gitlab.com/JOSM/wikipedia/tree/pages
script:
- &clone_pages_branch |
echo "$SSH_PRIVATE_DEPLOY_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
git clone --depth 1 --branch pages git@gitlab.com:JOSM/wikipedia.git pages
- |
version=`git describe --always --dirty`
longVersion=`git describe --always --long --dirty`
commitMessage="Release version $longVersion"
- |
mkdir -pv "pages/dist/$version"
cp -v build/dist/* build/tmp/jar/MANIFEST.MF "pages/dist/$version"
rm -fv "pages/dist/latest"
ln -s "./$version" "pages/dist/latest"
- &push_pages_branch |
cd pages/
git config user.name "Deploy with GitLab CI"
git config user.email "JOSM/wikipedia@gitlab.com"
git stage .
git commit -a -m "$commitMessage"
git push origin pages
dependencies:
- build
only:
- tags@JOSM/wikipedia
publish master update site:
stage: deploy
environment:
name: master update site
url: https://josm.gitlab.io/wikipedia/snapshot/master/update-site
script:
- *clone_pages_branch
- |
commitHash=`git rev-parse HEAD`
commitMessage="Make latest commit available via JOSM update site (master@$commitHash)"
- |
rm -vrf pages/snapshot/master
mkdir -pv pages/snapshot/master
cp -v build/snapshot-update-site pages/snapshot/master/update-site
cp -v build/dist/* pages/snapshot/master
- *push_pages_branch
dependencies:
- build
only:
- master@JOSM/wikipedia
......@@ -2,9 +2,6 @@ import java.nio.file.Files
import java.nio.file.Paths
import java.time.Duration
import java.time.Instant
import java.util.jar.JarInputStream
import java.util.regex.Pattern
import java.util.stream.Collectors
import org.openstreetmap.josm.gradle.plugin.task.GeneratePluginList
import com.github.spotbugs.SpotBugsTask
......@@ -47,6 +44,8 @@ classes.dependsOn(copyToLib)
test {
useJUnitPlatform()
testLogging.showStandardStreams = true
testLogging.exceptionFormat = 'full'
}
sourceSets {
......@@ -129,28 +128,13 @@ tasks.withType(SpotBugsTask) {
}
}
task generateMasterPluginList(type: GeneratePluginList) {
task generateSnapshotUpdateSite(type: GeneratePluginList) {
dependsOn(tasks.processResources)
outputFile = new File(project.buildDir, "pluginMasterSnapshots")
def defaultVersionSuffix = versionSuffix
versionSuffix = {String s ->
if (s.startsWith(archivesBaseName)) {
return ""
}
return defaultVersionSuffix.invoke(s)
}
outputFile = new File(project.buildDir, "snapshot-update-site")
versionSuffix = {a -> ""}
doFirst {
def wikipediaURL = System.getenv("WIKIPEDIA_URL")
def ptAssistantURL = System.getenv("PT_ASSISTANT_URL")
if (wikipediaURL == null || ptAssistantURL == null) {
throw new TaskExecutionException(it, new IllegalStateException("This tasks requires the environment variables `WIKIPEDIA_URL` and `PT_ASSISTANT_URL` to be set!"))
}
def circleBuildNum = System.getenv("CIRCLE_BUILD_NUM")
if (wikipediaURL.count("%s") == 1 && circleBuildNum != null) {
wikipediaURL = String.format(wikipediaURL, circleBuildNum)
}
def pluginDownloadUrl = "https://josm.gitlab.io/$archivesBaseName/snapshot/master/${archivesBaseName}.jar"
it.iconBase64Provider = {
def file = new File(sourceSets.main.resources.srcDirs[0], it)
if (file.exists()) {
......@@ -158,65 +142,8 @@ task generateMasterPluginList(type: GeneratePluginList) {
return "data:image/" + contentType + ";base64," + Base64.getEncoder().encodeToString(Files.readAllBytes(Paths.get(file.toURI())));
}
}
it.addPlugin("$archivesBaseName-dev.jar", project.josm.manifest.createJosmPluginJarManifest(), new URL(wikipediaURL))
def manifestAttributes = new JarInputStream(new URL(ptAssistantURL).openConnection().inputStream).manifest.mainAttributes.entrySet().stream()
.collect(Collectors.toMap({ e -> e.key.toString()}, { e -> e.value.toString()}))
it.addPlugin("pt_assistant-dev.jar", manifestAttributes, new URL(ptAssistantURL))
}
}
/**
* @return the current version of the repo as determined by the first of these commands that returns a valid result:
* <ul>
* <li>`git log` Search for a line with a git-svn-id in the current commit (append "-dirty" if working tree differs)</li>
* <li>`git describe` Let git describe the current commit, should only fail, if this is not a git repo</li>
* <li>`svn info` take the revision number from the SVN info command</li>
* </ul>
*/
def getVersion() {
// First attempt: Check if the commit has a git-svn-id, return SVN revision
def result = getVersion("git-svn-id: .*@([1-9][0-9]*) .*", "git", "log", "-1", "--format=%b")
if (result == null) {
// Second attempt: Check if the commit can be git-described, return the description by git
result = getVersion("(.+)", "git", "describe", "--always", "--dirty")
if (result == null) {
// Third attempt: Check if we are in an SVN repo, return revision number
result = getVersion("Revision: ([1-9][0-9]*)", "svn", "info")
if (result == null) {
result = "UNKNOWN"
} else {
result = "r$result"
}
}
} else {
result = "r$result"
def dirtyProcess = new ProcessBuilder("git", "diff-index", "--quiet", "HEAD").start()
if (dirtyProcess.waitFor() != 0) {
result += "-dirty"
}
}
return result
}
/**
* Runs the specified command, matches the lines of the output with the given linePattern.
* @param linePattern the linePattern to match the lines against
* @param command the command to execute
* @return if a line matches, return the first RegEx group, else return null
*/
def getVersion(String linePattern, String... command) {
def process = new ProcessBuilder(command).directory(project.projectDir).start()
if (process.waitFor() != 0) {
return null
it.addPlugin("$archivesBaseName-dev.jar", project.josm.manifest.createJosmPluginJarManifest(), new URL(pluginDownloadUrl))
}
def pattern = Pattern.compile(linePattern)
return Arrays.stream(process.inputStream.text.split("\n"))
.map { pattern.matcher(it)}
.filter { it.matches() }
.map { it.group(1).trim() }
.findFirst()
.orElse(null)
}
// Show task duration and skipped tasks
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment