Skip to content

Commit

Permalink
Incorporate release.rss generation into our build process (#257)
Browse files Browse the repository at this point in the history
* Remove legacy build tooling, we have long since migrated

* Update and move the releas.rss.groovy generation into the site build process

This doesn't make sense to execute as a separate process, we can just put it
inline with our existing site generation infrastructure

Fixes INFRA-663

* Ensure the fetchReleaseHistory task will execute if build/ does not yet exist

With a clean clone, this was breaking
  • Loading branch information
R. Tyler Croy committed May 23, 2016
1 parent 447c4fd commit 48f44ff
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 48 deletions.
70 changes: 22 additions & 48 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import com.github.jrubygradle.JRubyExec

ext.gitRef = Grgit.open('.')?.head()?.abbreviatedId
ext.siteOutputDir = "${buildDir}/_site"
ext.legacyOutputDir = "${buildDir}/_legacy"

description = 'Build for generating jenkins.io'
version = "2.0.${System.env.BUILD_NUMBER ?: '0'}+${ext.gitRef}"
Expand Down Expand Up @@ -68,6 +67,8 @@ dependencies {
/* needed for clean HTTP accesses */
externalFetcher 'rubygems:faraday:[0.9.2,1.0)'
externalFetcher 'rubygems:faraday_middleware:[0.9.2,1.0)'
/* used for running release.rss.groovy */
externalFetcher localGroovy()
}

/* for fetching javascript assets that we need for building the legacy and new
Expand Down Expand Up @@ -102,6 +103,18 @@ bower {
}
}

task fetchReleaseHistory(type: JavaExec) {
group 'Site'
classpath = configurations.externalFetcher
main = 'groovy.ui.GroovyMain'
def groovyScript = "${projectDir}/scripts/release.rss.groovy"
args groovyScript, "http://updates.jenkins.io/release-history.json"

file(project.ext.siteOutputDir).mkdirs()

standardOutput file("${project.ext.siteOutputDir}/release.rss").newOutputStream()
inputs.source file(groovyScript)
}

task fetchExternalResources(type: JRubyExec) {
group 'Site'
Expand All @@ -111,28 +124,6 @@ task fetchExternalResources(type: JRubyExec) {
inputs.source file("${projectDir}/scripts/fetch-external-resources")
}

task compileLegacyContent(type: JRubyExec) {
group 'Site'
description 'Compile the site using the awestruct CLI'
dependsOn 'fetchExternalResources'
script 'awestruct'
environment 'LEGACY' : true
scriptArgs '--generate', '--verbose',
/* forcefully set the site.base_url since the config is not
* being respected
*/
'--url', 'https://jenkins-ci.org',
'--source-dir', "${projectDir}/${contentDir}",
'--output-dir', project.ext.legacyOutputDir
/* without the --force option, awestruct is not smart enough to regenerate
* files based on includes */
configuration 'asciidoctor'
inputs.source fileTree(projectDir)
.include("${contentDir}/**/*.adoc")
.include("${contentDir}/**/*.haml")
.include("${contentDir}/**/*.md")
}

task compileContent(type: JRubyExec) {
group 'Site'
description 'Compile the site using the awestruct CLI'
Expand Down Expand Up @@ -160,14 +151,12 @@ task prepareJavaScripts {
dependsOn bowerInstall

doLast {
[project.ext.siteOutputDir, project.ext.legacyOutputDir].each {
def assetsDir = file("${it}/assets")
assetsDir.mkdirs()

copy {
from "${projectDir}/src/assets"
into assetsDir
}
def assetsDir = file("${project.ext.siteOutputDir}/assets")
assetsDir.mkdirs()

copy {
from "${projectDir}/src/assets"
into assetsDir
}
}
}
Expand All @@ -176,8 +165,8 @@ task assemble {
group 'Site'
description 'Assemble the full site'
dependsOn fetchExternalResources,
fetchReleaseHistory,
compileContent,
compileLegacyContent,
prepareJavaScripts
}

Expand All @@ -195,24 +184,10 @@ task archiveBeta(type: Zip) {
destinationDir = targetDir
}

task archiveLegacy(type: Zip) {
def computedDirName = "jenkins.io-${project.version}"

group 'Site'
description 'Create a zip archive of the site for deployment'
dependsOn assemble
archiveName "${computedDirName}.zip"
into(computedDirName) { from project.ext.legacyOutputDir }

File targetDir = file("${buildDir}/archives")
targetDir.mkdirs()
destinationDir = targetDir
}

task archive {
group 'Site'
description 'Create a zip archive of the site for deployment'
dependsOn archiveLegacy, archiveBeta
dependsOn archiveBeta
}

task run(type:Exec) {
Expand All @@ -232,4 +207,3 @@ def defineDevTask(name, body) {
}

defineDevTask('dev') {}
defineDevTask('dev-legacy') { environment 'LEGACY', 'true' }
58 changes: 58 additions & 0 deletions scripts/release.rss.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env groovy
/*
generate the plugin/core release history RSS
Usage: release-rss.groovy <URL of release-hisotory.json>
*/

import groovy.json.JsonSlurper
import groovy.xml.MarkupBuilder
import java.text.*

def xsd(dt) {
s = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(dt);
return s[0..-3]+':'+s[-2..-1]
}
def df = new SimpleDateFormat("MMM dd, yyyy");

def json = new JsonSlurper().parse(new URL(args[0]));

def toGA(gav) {
return gav.substring(0,gav.lastIndexOf(':'))
}

def first = [:]; // GA -> GAV to indicate the first version of the release
json.releaseHistory.reverse().each { i ->
i.releases.each { r ->
gav = r.gav
if (gav) {
first[toGA(gav)] = gav
}
}
}

def xml = new MarkupBuilder(new OutputStreamWriter(System.out))
xml.feed(xmlns:"http://www.w3.org/2005/Atom") {
title("Jenkins plugin releases")
link(href:"http://jenkins-ci.org/")
link(href:"http://kohsuke.org/test.atom",rel:"self",type:"application/atom+xml")
updated(xsd(new Date()))
author { name("Jenkins History Bot") }
id("urn:63067410335c11e0bc8e0800200c9a66:feed")

json.releaseHistory.reverse().subList(0,30).each { i ->
i.releases.each { r ->
if (r.gav) {
entry {
s = (first[toGA(r.gav)] == r.gav) ? " (new)" : ""
title("${r.title} ${r.version}${s}")
link(href:r.wiki,rel:"alternate",type:"text/html")
id("urn:63067410335c11e0bc8e0800200c9a66:${r.gav}")
pubished(xsd(new Date(r.timestamp)))
updated(xsd(new Date(r.timestamp)))
summary("${r.title} ${r.version}")
}
}
}
}
}

0 comments on commit 48f44ff

Please sign in to comment.