Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
3933cb6b
Commit
3933cb6b
authored
May 11, 2018
by
Leonard Gram
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
build: publisher updated to support more architectures and OSs.
parent
803694f4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
155 additions
and
21 deletions
+155
-21
scripts/build/publish.go
+51
-21
scripts/build/publish_test.go
+104
-0
No files found.
scripts/build/publish.go
View file @
3933cb6b
...
...
@@ -18,8 +18,15 @@ import (
var
apiUrl
=
flag
.
String
(
"apiUrl"
,
"https://grafana.com/api"
,
"api url"
)
var
apiKey
=
flag
.
String
(
"apiKey"
,
""
,
"api key"
)
var
version
=
""
var
versionRe
=
regexp
.
MustCompile
(
`grafana-(.*)\.(linux|windows)`
)
var
versionRe
=
regexp
.
MustCompile
(
`grafana-(.*)(\.|_)(arm64|armv7|darwin|linux|windows|x86_64)`
)
var
debVersionRe
=
regexp
.
MustCompile
(
`grafana_(.*)_(arm64|armv7|amd64)\.deb`
)
var
builds
=
[]
build
{}
var
architectureMapping
=
map
[
string
]
string
{
"amd64"
:
"amd64"
,
"armv7"
:
"armv7"
,
"arm64"
:
"arm64"
,
"x86_64"
:
"amd64"
,
}
func
main
()
{
flag
.
Parse
()
...
...
@@ -60,45 +67,68 @@ func main() {
}
}
func
packageWalker
(
path
string
,
f
os
.
FileInfo
,
err
error
)
error
{
if
f
.
Name
()
==
"dist"
||
strings
.
Contains
(
f
.
Name
(),
"sha256"
)
||
strings
.
Contains
(
f
.
Name
(),
"latest"
)
{
return
nil
}
log
.
Printf
(
"Finding package file %s"
,
f
.
Name
())
result
:=
versionRe
.
FindSubmatch
([]
byte
(
f
.
Name
()))
func
mapPackage
(
path
string
,
name
string
,
shaBytes
[]
byte
)
(
build
,
error
)
{
log
.
Printf
(
"Finding package file %s"
,
name
)
result
:=
versionRe
.
FindSubmatch
([]
byte
(
name
))
debResult
:=
debVersionRe
.
FindSubmatch
([]
byte
(
name
))
if
len
(
result
)
>
0
{
version
=
string
(
result
[
1
])
log
.
Printf
(
"Version detected: %v"
,
version
)
}
shaBytes
,
err
:=
ioutil
.
ReadFile
(
path
+
".sha256"
)
if
err
!=
nil
{
log
.
Fatalf
(
"Failed to read sha256 file %v"
,
err
)
}
else
if
(
len
(
debResult
)
>
0
)
{
version
=
string
(
debResult
[
1
])
}
os
:=
""
if
strings
.
Contains
(
f
.
Name
(),
"linux-x64.tar.gz
"
)
{
if
strings
.
Contains
(
name
,
"linux
"
)
{
os
=
"linux"
}
if
strings
.
HasSuffix
(
f
.
Name
(),
"windows-x
64.zip"
)
{
if
strings
.
HasSuffix
(
name
,
"windows-amd
64.zip"
)
{
os
=
"win"
}
if
strings
.
HasSuffix
(
f
.
Name
(),
".rpm"
)
{
if
strings
.
HasSuffix
(
name
,
"darwin-amd64.tar.gz"
)
{
os
=
"darwin"
}
if
strings
.
HasSuffix
(
name
,
".rpm"
)
{
os
=
"rhel"
}
if
strings
.
HasSuffix
(
f
.
Name
()
,
".deb"
)
{
if
strings
.
HasSuffix
(
name
,
".deb"
)
{
os
=
"deb"
}
builds
=
append
(
builds
,
build
{
arch
:=
""
for
archListed
,
archReal
:=
range
architectureMapping
{
if
strings
.
Contains
(
name
,
archListed
)
{
arch
=
archReal
break
}
}
return
build
{
Os
:
os
,
Arch
:
"amd64"
,
Url
:
"https://s3-us-west-2.amazonaws.com/grafana-releases/master/"
+
f
.
Name
()
,
Arch
:
arch
,
Url
:
"https://s3-us-west-2.amazonaws.com/grafana-releases/master/"
+
name
,
Sha256
:
string
(
shaBytes
),
})
},
nil
}
func
packageWalker
(
path
string
,
f
os
.
FileInfo
,
err
error
)
error
{
if
f
.
Name
()
==
"dist"
||
strings
.
Contains
(
f
.
Name
(),
"sha256"
)
||
strings
.
Contains
(
f
.
Name
(),
"latest"
)
{
return
nil
}
shaBytes
,
err
:=
ioutil
.
ReadFile
(
path
+
".sha256"
)
if
err
!=
nil
{
log
.
Fatalf
(
"Failed to read sha256 file %v"
,
err
)
}
build
,
err
:=
mapPackage
(
path
,
f
.
Name
(),
shaBytes
)
if
err
!=
nil
{
return
err
}
builds
=
append
(
builds
,
build
)
return
nil
}
...
...
scripts/build/publish_test.go
0 → 100644
View file @
3933cb6b
package
main
import
(
"testing"
)
type
testPackage
struct
{
path
string
version
string
os
string
arch
string
}
var
testData
=
[]
testPackage
{
{
path
:
"grafana-5.2.0-474pre1.arm64.rpm"
,
version
:
"5.2.0-474pre1"
,
os
:
"rhel"
,
arch
:
"arm64"
,
},
{
path
:
"grafana-5.2.0-474pre1.armv7.rpm"
,
version
:
"5.2.0-474pre1"
,
os
:
"rhel"
,
arch
:
"armv7"
,
},
{
path
:
"grafana-5.2.0-474pre1.darwin-amd64.tar.gz"
,
version
:
"5.2.0-474pre1"
,
os
:
"darwin"
,
arch
:
"amd64"
,
},
{
path
:
"grafana-5.2.0-474pre1.linux-amd64.tar.gz"
,
version
:
"5.2.0-474pre1"
,
os
:
"linux"
,
arch
:
"amd64"
,
},
{
path
:
"grafana-5.2.0-474pre1.linux-arm64.tar.gz"
,
version
:
"5.2.0-474pre1"
,
os
:
"linux"
,
arch
:
"arm64"
,
},
{
path
:
"grafana-5.2.0-474pre1.linux-armv7.tar.gz"
,
version
:
"5.2.0-474pre1"
,
os
:
"linux"
,
arch
:
"armv7"
,
},
{
path
:
"grafana-5.2.0-474pre1.windows-amd64.zip"
,
version
:
"5.2.0-474pre1"
,
os
:
"win"
,
arch
:
"amd64"
,
},
{
path
:
"grafana-5.2.0-474pre1.x86_64.rpm"
,
version
:
"5.2.0-474pre1"
,
os
:
"rhel"
,
arch
:
"amd64"
,
},
{
path
:
"grafana_5.2.0-474pre1_amd64.deb"
,
version
:
"5.2.0-474pre1"
,
os
:
"deb"
,
arch
:
"amd64"
,
},
{
path
:
"grafana_5.2.0-474pre1_arm64.deb"
,
version
:
"5.2.0-474pre1"
,
os
:
"deb"
,
arch
:
"arm64"
,
},
{
path
:
"grafana_5.2.0-474pre1_armv7.deb"
,
version
:
"5.2.0-474pre1"
,
os
:
"deb"
,
arch
:
"armv7"
,
},
}
func
TestFileWalker
(
t
*
testing
.
T
)
{
for
_
,
packageInfo
:=
range
testData
{
version
=
""
actualPackageInfo
,
err
:=
mapPackage
(
packageInfo
.
path
,
packageInfo
.
path
,
[]
byte
{})
if
err
!=
nil
{
t
.
Error
(
err
)
continue
}
if
version
!=
packageInfo
.
version
{
t
.
Errorf
(
"Testing (%v), expected %v to be %v."
,
packageInfo
.
path
,
version
,
packageInfo
.
version
)
}
if
actualPackageInfo
.
Os
!=
packageInfo
.
os
{
t
.
Errorf
(
"Testing (%v), expected %v to be %v."
,
packageInfo
.
path
,
actualPackageInfo
.
Os
,
packageInfo
.
os
)
}
if
actualPackageInfo
.
Arch
!=
packageInfo
.
arch
{
t
.
Errorf
(
"Testing (%v), expected %v to be %v."
,
packageInfo
.
path
,
actualPackageInfo
.
Arch
,
packageInfo
.
arch
)
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment