Skip to content
Permalink
Browse files

Nupkg distribution using GitHub Actions

[changelog skip]
  • Loading branch information...
dahlia committed May 10, 2019
1 parent 4b21f1d commit acd4862e9e6ef684c347f70bfb6ba5252009fffe
@@ -0,0 +1,78 @@
#!/bin/ash
# Extract a release note from the given changelog file.
# Note that this script is intended to be run by GitHub Actions.
# shellcheck disable=SC2169
set -e

project=Libplanet
configuration=Release

if [ "$GITHUB_REPOSITORY" = "" ] | [ "$GITHUB_REF" = "" ]; then
echo "This script is intended to be run by GitHub Actions." > /dev/stderr
exit 1
elif [ ! -f obj/package_version.txt ]; then
{
echo "obj/package_version.txt file is missing."
echo "dist:version action must be run first."
} > /dev/stderr
exit 1
elif [ "${GITHUB_REF:0:10}" != "refs/tags/" ]; then
echo "This script is run for only tag push; being skipped..." > /dev/stderr
exit 0 # If it exits with non-zero other actions become cancelled
fi

tag="${GITHUB_REF#refs/*/}"
if [ "$tag" != "$(cat obj/package_version.txt)" ]; then
{
echo -n "Git tag ($tag) does not match to obj/package_version.txt ("
cat obj/package_version.txt
echo ")."
} > /dev/stderr
exit 1
elif [ ! -f obj/release_note.txt ]; then
{
echo "obj/release_note.txt file is missing."
echo "dist:release-note action must be run first."
} > /dev/stderr
exit 1
fi

nupkg_path="./$project/bin/$configuration/$project.$tag.nupkg"
if [ ! -f "$nupkg_path" ]; then
{
echo "$nupkg_path is missing."
echo "dist:pack action must be run first."
} > /dev/stderr
exit 1
fi

wget -O /tmp/github-release.tar.bz2 \
https://github.com/aktau/github-release/releases/download/v0.7.2/linux-amd64-github-release.tar.bz2
tar xvfj /tmp/github-release.tar.bz2 -C /tmp
rm /tmp/github-release.tar.bz2 \

# Fill the description on GitHub releases with the release note
github_user="${GITHUB_REPOSITORY%/*}" \
github_repo="${GITHUB_REPOSITORY#*/}"

if [ "$GITHUB_REPOSITORY" = "planetarium/libplanet" ]; then
alias github-release=/tmp/bin/linux/amd64/github-release
else
alias github-release="echo DRY-RUN: github-release"
fi

github-release relase \
--user "$github_user" \
--repo "$github_repo" \
--tag "$tag" \
--name "$project $tag" \
--description - < obj/release_note.txt

github-release upload \
--user "$github_user" \
--repo "$github_repo" \
--tag "$tag" \
--name "$(basename "$nupkg_path")" \
--file "$nupkg_path"

rm /tmp/bin/linux/amd64/github-release
@@ -0,0 +1,30 @@
#!/bin/sh
# Submit .nupkg files to NuGet.
# Note that this script is intended to be run by GitHub Actions.
set -e

project=Libplanet
configuration=Release

if [ ! -f obj/package_version.txt ]; then
{
echo "obj/package_version.txt file is missing."
echo "dist:version action must be run first."
} > /dev/stderr
exit 1
fi

if [ "$NUGET_API_KEY" = "" ]; then
echo "This script requires NUGET_API_KEY envrionment variable." > /dev/stderr
exit 1
fi

if [ "$GITHUB_REPOSITORY" != "planetarium/libplanet" ]; then
alias dotnet="echo DRY-RUN: dotnet"
fi

package_version="$(cat obj/package_version.txt)"
dotnet nuget push \
"./$project/bin/$configuration/$project.$package_version.nupkg" \
--api-key "$NUGET_API_KEY" \
--source https://api.nuget.org/v3/index.json
@@ -0,0 +1,31 @@
#!/bin/sh
# Build a .nupkg file.
# Note that this script is intended to be run by GitHub Actions.
set -e

project=Libplanet
configuration=Release

if ! (env | grep '^GITHUB_'); then
echo "This script is intended to be run by GitHub Actions." > /dev/stderr
exit 1
fi

rm -rf "./$project/bin/$configuration/"

if [ -f obj/version_suffix.txt ]; then
dotnet_args="--version-suffix $(cat obj/version_suffix.txt)"
dotnet_args="$dotnet_args -p:NoPackageAnalysis=true"
fi
# shellcheck disable=SC2086
dotnet build -c "$configuration" $dotnet_args
# shellcheck disable=SC2086
dotnet pack "$project" -c "$configuration" $dotnet_args

version_prefix="$(cat obj/version_prefix.txt)"
package_version="$(cat obj/package_version.txt)"

ls -al "./$project/bin/$configuration/"
if [ "$package_version" != "$version_prefix" ]; then
rm -f "./$project/bin/$configuration/$project.$version_prefix.nupkg"
fi
@@ -0,0 +1,40 @@
#!/bin/ash
# Extract a release note from the given changelog file.
# Note that this script is intended to be run by GitHub Actions.
set -e

if [ "$1" = "" ]; then
echo "A changelog file path is missing." > /dev/stderr
exit 1
elif [ "$2" = "" ]; then
echo "An output path is missing." > /dev/stderr
exit 1
elif [ ! -f obj/package_version.txt ]; then
{
echo "obj/package_version.txt file is missing."
echo "dist:version action must be run first."
} > /dev/stderr
exit 1
fi

version_prefix="$(cat obj/version_prefix.txt)"
package_version="$(cat obj/package_version.txt)"

wget -O /tmp/submark \
https://github.com/dahlia/submark/releases/download/0.2.0/submark-linux-x86_64
chmod +x /tmp/submark
/tmp/submark \
-o "$2" \
-iO \
--h2 "Version $version_prefix" \
"$1"
rm /tmp/submark

if ! grep -E '\S' "$2" > /dev/null; then
echo "There is no section for the version $version_prefix." > /dev/stderr
exit 1
elif [ "$version_prefix" = "$package_version" ] && \
! grep -i "to be released" "$2"; then
echo 'Release date should be shown on the release note.' > /dev/stderr
exit 1
fi
@@ -0,0 +1,52 @@
#!/usr/bin/env pwsh
# Append suffix to the package version if it's not a tag push:
# - "dev.TIMESTAMP" (e.g., 0.1.2-dev.20190423131415)
# - "nightly.DATE" (e.g., 0.1.2-nightly.20190423)
# Note that this script is intended to be run by GitHub Actions.
if ((Get-ChildItem env:GITHUB_*).Count -lt 1) {
Write-Error "This script is intended to be run by GitHub Actions."
exit 1
}

$VersionPrefix = (Select-Xml `
-Path Libplanet/Libplanet.csproj `
-XPath './Project/PropertyGroup/VersionPrefix/text()').Node.Value

New-Item -ItemType directory -Path obj -ErrorAction SilentlyContinue
[Console]::Error.Write("VersionPrefix: ")
Write-Output $VersionPrefix
Write-Output $VersionPrefix > obj/version_prefix.txt

if ($env:GITHUB_EVENT_NAME.StartsWith("schedule")) {
$date = (Get-Date).ToUniversalTime().ToString("yyyyMMdd")
$VersionSuffix = "nightly.$date"
$PackageVersion = "$VersionPrefix-$VersionSuffix"
} elseif ($env:GITHUB_REF.StartsWith("refs/tags/")) {
$tag = $env:GITHUB_REF.Substring(10)
if ("$tag" -ne "$VersionPrefix") {
Write-Error "Git tag ($tag) doesn't match to VersionPrefix ($VersionPrefix)"
exit 1
}
$PackageVersion = $tag
} else {
$event = Get-Content $env:GITHUB_EVENT_PATH | ConvertFrom-Json
$timestamp = $event.head_commit.timestamp
if ($timestamp -eq $null) {
$timestamp = Get-Date
}
$timestamp = $timestamp.ToUniversalTime()
$VersionSuffix = "dev." + $timestamp.ToString("yyyyMMddHHmmss")
$PackageVersion = "$VersionPrefix-$VersionSuffix"
}

if ($VersionSuffix -eq $null) {
Remove-Item obj/version_suffix.txt -ErrorAction SilentlyContinue
} else {
[Console]::Error.Write("VersionSuffix: ")
Write-Output $VersionSuffix
Write-Output $VersionSuffix > obj/version_suffix.txt
}
[Console]::Error.Write("PackageVersion: ")
Write-Output $PackageVersion
Write-Output $PackageVersion > obj/package_version.txt

@@ -1,10 +1,21 @@
workflow "on push" {
workflow "push" {
on = "push"
resolves = ["docs:publish"]
resolves = ["dist:nuget", "dist:github-release", "docs:publish"]
}

workflow "everyday" {
on = "schedule(59 14 * * *)"
resolves = ["dist:nuget"]
}

action "docs:build" {
uses = "dahlia/actions/docfx@master"

needs = "dist:pack"
# dotnet build & msbuild may occur error if both is running at a time,
# so in order to wait until one is finished add dist:pack action as
# a dependency of this action.

env = {
MSBUILD_PROJECT = "Libplanet"
}
@@ -24,3 +35,42 @@ action "docs:publish" {
]
runs = ["Docs/publish.sh"]
}

action "dist:version" {
uses = "docker://mcr.microsoft.com/powershell:latest"
args = [".github/bin/dist-version.ps1"]
}

action "dist:pack" {
uses = "docker://mcr.microsoft.com/dotnet/core/sdk:2.2"
needs = "dist:version"
runs = [".github/bin/dist-pack.sh"]
}

action "dist:release-note" {
uses = "docker://alpine:3.9"
needs = "dist:version"
runs = [
".github/bin/dist-release-note.sh",
"CHANGES.md",
"obj/release_note.txt"
]
}

action "dist:nuget" {
uses = "docker://mcr.microsoft.com/dotnet/core/sdk:2.2"
needs = ["dist:pack", "dist:release-note"]
runs = [".github/bin/dist-nuget.sh"]
secrets = [
"NUGET_API_KEY"
]
}

action "dist:github-release" {
uses = "docker://alpine:3.9"
needs = ["dist:pack", "dist:release-note"]
runs = [".github/bin/dist-github-release.sh"]
secrets = [
"GITHUB_TOKEN"
]
}
@@ -25,6 +25,7 @@
.vs/
[Bb]in/
[Oo]bj/
!.github/bin/
_UpgradeReport_Files/
[Pp]ackages/
mono_crash.*.json
Oops, something went wrong.

0 comments on commit acd4862

Please sign in to comment.
You can’t perform that action at this time.