Skip to content

Commit

Permalink
feat(GHA): adding Windows packaging and pipelines
Browse files Browse the repository at this point in the history
  • Loading branch information
paologallinaharbur committed Oct 1, 2020
1 parent bfe5892 commit 74951af
Show file tree
Hide file tree
Showing 19 changed files with 777 additions and 14 deletions.
190 changes: 190 additions & 0 deletions .github/workflows/create_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
### ON MERGE TO MASTER
### build_push_linux_artifacts
### +-------------------------+
### | |
### | BUILD AND PUSH LINUX |
### +----------------- | PACKAGES TO GITHUB |
### | | |
### create_release | | |
### +-----------------------+ | +-------------------------+
### | | |
### | CREATE A NEW RELEASE | |
### | IN CASE ONE DEFINITION| |
### | HAS BEEN MODIFIED | -----------+
### | OR ADDED | | build_push_windows_artifacts
### | | | +---------------------------+
### +-----------------------+ | | | _
### | | BUILD AND PUSHES WINDOWS | |
### +----------------- | PACKAGES TO GITHUB | |
### | | |
### | Possibly executed twice | |
### +---------------------------+ |
### |___________________________|

on:
#pull_request
push:
branches:
- master

###
### RELEASE CREATION # Creates a release if needed and loads variables for next jobs
###
name: Create Release
jobs:
create_release:
name: Create Release
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v2
with:
go-version: '^1.13.1'
- name: Checkout code
uses: actions/checkout@v2
- name: Install dependencies
run: |
sudo wget -O /usr/local/bin/yq https://github.com/mikefarah/yq/releases/download/3.3.0/yq_linux_amd64
sudo chmod +x /usr/local/bin/yq
- name: Check exporters have been modified
id: check
run : |
git fetch -at origin --unshallow
source ./exporters/common_functions.sh
getExporterPath
loadVariables
setStepOutput
- name: Create Release
id: create_release
if: ${{ steps.check.outputs.CREATE_RELEASE }} == 'true'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.check.outputs.NAME }}-${{ steps.check.outputs.VERSION }}
release_name: Release ${{ steps.check.outputs.NAME }} ${{ steps.check.outputs.VERSION }}
body: |
Changes in ${{ steps.check.outputs.NAME }} ${{ steps.check.outputs.VERSION }}
- Exporter repository URL: ${{ steps.check.outputs.EXPORTER_REPO_URL }}
- Commit or Tag of the exporter built: ${{ steps.check.outputs.EXPORTER_HEAD }}
- CHANGELOG: ${{ steps.check.outputs.EXPORTER_CHANGELOG }}
draft: false
prerelease: false
outputs:
CREATE_RELEASE: ${{ steps.check.outputs.CREATE_RELEASE }}
EXPORTER_PATH: ${{ steps.check.outputs.EXPORTER_PATH }}
PACKAGE_LINUX: ${{ steps.check.outputs.PACKAGE_LINUX }}
PACKAGE_WINDOWS: ${{ steps.check.outputs.PACKAGE_WINDOWS }}
UPLOAD_URL: ${{ steps.create_release.outputs.upload_url }}

###
### LINUX PACKAGING # In case a new release has been created and linux packages are needed build and push DEB, RPM, TAR
###

build_push_linux_artifacts:
needs: [create_release]
name: Push Linux Artifacts
runs-on: ubuntu-latest
if: ${{ needs.create_release.outputs.CREATE_RELEASE == 'true' && needs.create_release.outputs.PACKAGE_LINUX == 'true'}}
steps:
- uses: actions/setup-go@v2
with:
go-version: '^1.13.1'
- name: Checkout code
uses: actions/checkout@v2
- name: Install dependencies
run: |
sudo apt-get install rpm ruby ruby-dev rubygems build-essential
sudo gem install --no-document fpm
sudo wget -O /usr/local/bin/yq https://github.com/mikefarah/yq/releases/download/3.3.0/yq_linux_amd64
sudo chmod +x /usr/local/bin/yq
- name: package linux
id: package
run : |
export GOPATH=$(go env GOPATH)
export EXPORTER_PATH=${{ needs.create_release.outputs.EXPORTER_PATH }}
source ././exporters/common_functions.sh
loadVariables
packageLinux
setStepOutput
- name: Upload Release Asset DEB
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.UPLOAD_URL }}
asset_path: ./exporters/${{ steps.package.outputs.NAME }}/target/packages/deb/${{ steps.package.outputs.NAME }}_${{ steps.package.outputs.VERSION }}-1_amd64.deb
asset_name: ${{ steps.package.outputs.NAME }}_${{ steps.package.outputs.VERSION }}-1_amd64.deb
asset_content_type: deb package
- name: Upload Release Asset TAR
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.UPLOAD_URL }}
asset_path: ./exporters/${{ steps.package.outputs.NAME }}/target/packages/tarball/${{ steps.package.outputs.NAME }}_linux_${{ steps.package.outputs.VERSION }}_amd64.tar.gz
asset_name: ${{ steps.package.outputs.NAME }}_linux_${{ steps.package.outputs.VERSION }}_amd64.tar.gz
asset_content_type: tarball
- name: Upload Release Asset RPM
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.UPLOAD_URL }}
asset_path: ./exporters/${{ steps.package.outputs.NAME }}/target/packages/rpm/${{ steps.package.outputs.NAME }}-${{ steps.package.outputs.VERSION }}-1.x86_64.rpm
asset_name: ${{ steps.package.outputs.NAME }}-${{ steps.package.outputs.VERSION }}-1.x86_64.rpm
asset_content_type: rpm package


###
### Windows Packaging # In case a new release has been created and Windows packages are needed build and push MSI
###

build_push_windows_artifacts:
name: Create MSI
runs-on: windows-2019
needs: [create_release]
if: ${{ needs.create_release.outputs.CREATE_RELEASE == 'true' && needs.create_release.outputs.PACKAGE_WINDOWS == 'true' }}
env:
GOPATH: ${{ github.workspace }}
defaults:
run:
working-directory: src/github.com/newrelic/newrelic-prometheus-exporters-packages
strategy:
matrix:
goarch: [amd64 ,386]
steps:
- name: Checkout
uses: actions/checkout@v2
with:
path: src/github.com/newrelic/newrelic-prometheus-exporters-packages
- uses: actions/setup-go@v2
with:
go-version: '^1.13.1'
#- name: Get PFX certificate from GH secrets
# shell: bash
# run: printf "%s" "$PFX_CERTIFICATE_BASE64" | base64 -d - > mycert.pfx
- name: Load Variables
id: load_variables
shell: bash
run: |
choco install yq
export EXPORTER_PATH=${{ needs.create_release.outputs.EXPORTER_PATH }}
source ././exporters/common_functions.sh
loadVariables
setStepOutput
- name : CreateMSI
shell: pwsh
run: |
.\exporters\${{ steps.load_variables.outputs.NAME }}\win_build.ps1 -arch ${{ matrix.goarch }} -exporterHead ${{ steps.load_variables.outputs.EXPORTER_HEAD }} -exporterName ${{ steps.load_variables.outputs.NAME }} -exporterURL ${{ steps.load_variables.outputs.EXPORTER_REPO_URL }}
.\exporters\win_msi_build.ps1 -arch ${{ matrix.goarch }} -exporterName ${{ steps.load_variables.outputs.NAME }} -version ${{ steps.load_variables.outputs.VERSION }}
# -pfx_certificate_base64 "$env:PFX_CERTIFICATE_BASE64" -pfx_passphrase "$env:PFX_PASSPHRASE"
- name: Upload Release Asset MSI
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.UPLOAD_URL }}
asset_path: ${{ github.workspace }}/src/github.com/newrelic/newrelic-prometheus-exporters-packages/exporters/${{ steps.load_variables.outputs.NAME }}/target/packages/msi/${{ steps.load_variables.outputs.NAME }}-${{ matrix.goarch }}.msi
asset_name: ${{ steps.load_variables.outputs.NAME }}-${{ matrix.goarch }}.msi
asset_content_type: msi package

9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,18 @@
.idea/
**/target/**
**/bin/**
**/obj/**

**/*-cloned/**
**/*-cloned/.*
**/*-cloned
# Dependency directories (remove the comment below to include it)
# vendor/

*.tmp
**/obj/Release/**
**/bin/Release/**

**/Product.wxs

**/versioninfo.json
70 changes: 70 additions & 0 deletions exporters/common_functions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env bash

loadVariables(){

export NAME=$(yq read $EXPORTER_PATH name)
export VERSION=$(yq read $EXPORTER_PATH version)
export EXPORTER_REPO_URL=$(yq read $EXPORTER_PATH exporter_repo_url)
export EXPORTER_TAG=$(yq read $EXPORTER_PATH exporter_tag)
export EXPORTER_COMMIT=$(yq read $EXPORTER_PATH exporter_commit)
export EXPORTER_CHANGELOG=$(yq read $EXPORTER_PATH exporter_changelog)
export PACKAGE_LINUX=$(yq read $EXPORTER_PATH package_linux)
export PACKAGE_WINDOWS=$(yq read $EXPORTER_PATH package_windows)

if [[ -z $EXPORTER_TAG ]]
then
export EXPORTER_HEAD=$EXPORTER_COMMIT
else
export EXPORTER_HEAD=$EXPORTER_TAG
fi
}

setStepOutput(){
echo "::set-output name=NAME::${NAME}"
echo "::set-output name=EXPORTER_HEAD::${EXPORTER_HEAD}"
echo "::set-output name=EXPORTER_REPO_URL::${EXPORTER_REPO_URL}"
echo "::set-output name=VERSION::${VERSION}"
echo "::set-output name=EXPORTER_CHANGELOG::${EXPORTER_CHANGELOG}"
echo "::set-output name=CREATE_RELEASE::${CREATE_RELEASE}"
echo "::set-output name=EXPORTER_PATH::${EXPORTER_PATH}"
echo "::set-output name=PACKAGE_LINUX::${PACKAGE_LINUX}"
echo "::set-output name=PACKAGE_WINDOWS::${PACKAGE_WINDOWS}"
}

packageLinux(){
IFS="/" read tmp exporter_name exporter_yaml <<< $EXPORTER_PATH

if [ $exporter_name != $NAME ]; then
echo "The exporter.yml is in a wrong folder. The name in the definition '$NAME' does not match with the foldername '$exporter_name'"
exit 1
fi

current_pwd=$(pwd)
cd ./exporters/"$exporter_name" && make all
cd $current_pwd
}

getExporterPath(){
old=$(git describe --tags --abbrev=0)
export EXPORTER_PATH=$(git --no-pager diff --name-only $old "exporters/**/exporter.yml")
CREATE_RELEASE=false

if [ -z "$EXPORTER_PATH" ]
then
echo "No definition has been modified"
exit 0
fi

if (( $(git --no-pager diff --name-only $old "exporters/**/exporter.yml"| wc -l) > 1 ))
then
echo "Only one definition should be modified at the same time"
git --no-pager diff --name-only $old "exporters/**/exporter.yml"
exit 1
fi
CREATE_RELEASE=true

}




8 changes: 4 additions & 4 deletions exporters/githubactions/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# Exporter yml variables
NAME ?= githubactions
VERSION ?= v1.2
VERSION ?= 1.2.0
EXPORTER_REPO_URL ?= https://github.com/Spendesk/github-actions-exporter
EXPORTER_TAG ?= v1.2
EXPORTER_COMMIT ?= 5ab74d5af9eb533e6564996bde43528175092591
EXPORTER_HEAD := $(if $(EXPORTER_TAG),$(EXPORTER_TAG),$(EXPORTER_COMMIT))
EXPORTER_HEAD ?= v1.2

IMPORT_PATH := $(subst https://,,$(EXPORTER_REPO_URL))
CLONED_REPO := $(GOPATH)/src/$(IMPORT_PATH)
Expand All @@ -23,6 +21,8 @@ clean:
echo "GOPATH is empty" ;\
exit 1 ;\
fi
@CLONED_REPO="$(echo -e "${CLONED_REPO}" | tr -d '[:space:]')"
@TARGET_DIR="$(echo -e "${TARGET_DIR}" | tr -d '[:space:]')"
rm -rf $(CLONED_REPO) $(TARGET_DIR)

clone-repo: clean
Expand Down
6 changes: 0 additions & 6 deletions exporters/githubactions/exporter.yaml

This file was deleted.

8 changes: 8 additions & 0 deletions exporters/githubactions/exporter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: githubactions
version: 1.2.0
exporter_repo_url: https://github.com/Spendesk/github-actions-exporter
exporter_tag: v1.2
exporter_commit: 3wfwef
exporter_changelog: "Changelog for the current version"
package_linux: true
package_windows: true
Binary file added exporters/githubactions/pkg/.DS_Store
Binary file not shown.
44 changes: 44 additions & 0 deletions exporters/githubactions/pkg/versioninfo.json.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"FixedFileInfo":
{
"FileVersion": {
"Major": {MajorVersion},
"Minor": {MinorVersion},
"Patch": {PatchVersion},
"Build": {BuildVersion}
},
"ProductVersion": {
"Major": {MajorVersion},
"Minor": {MinorVersion},
"Patch": {PatchVersion},
"Build": {BuildVersion}
},
"FileFlagsMask": "3f",
"FileFlags ": "00",
"FileOS": "040004",
"FileType": "01",
"FileSubType": "00"
},
"StringFileInfo":
{
"Comments": "(c) {Year} New Relic, Inc.",
"CompanyName": "New Relic, Inc.",
"FileDescription": "",
"FileVersion": "{MajorVersion}.{MinorVersion}.{PatchVersion}.{BuildVersion}",
"InternalName": "{Integration}",
"LegalCopyright": "(c) 2020 Spendesk",
"LegalTrademarks": "",
"OriginalFilename": "{IntegrationExe}",
"PrivateBuild": "",
"ProductName": "New Relic Infrastructure Integration, {Integration}",
"ProductVersion": "{MajorVersion}.{MinorVersion}.{PatchVersion}.{BuildVersion}",
"SpecialBuild": ""
},
"VarFileInfo":
{
"Translation": {
"LangID": "0409",
"CharsetID": "04B0"
}
}
}
Loading

0 comments on commit 74951af

Please sign in to comment.