Skip to content
This repository has been archived by the owner on May 25, 2021. It is now read-only.

feat: automagic version & publish when go-ipfs released #35

Merged
merged 21 commits into from
Jul 9, 2019
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/main.workflow
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
workflow "New workflow" {
on = "schedule(0 */1 * * *)"
resolves = ["Version and publish"]
}

action "Check for go-ipfs release" {
uses = "./action-check-for-go-ipfs-release"
}

action "Build" {
needs = "Check for go-ipfs release"
uses = "actions/npm@master"
args = "install"
}

action "Test" {
needs = "Build"
uses = "actions/npm@master"
args = "test"
}

action "Version and publish" {
needs = "Test"
uses = "./action-publish"
secrets = ["GITHUB_TOKEN", "NPM_AUTH_TOKEN"]
}
9 changes: 9 additions & 0 deletions action-check-for-go-ipfs-release/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM node:10

LABEL "com.github.actions.name"="Update and publish"
LABEL "com.github.actions.description"="Publish new version when a new go-ipfs version is relased"
LABEL "com.github.actions.icon"="rss"
LABEL "com.github.actions.color"="green"

COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
16 changes: 16 additions & 0 deletions action-check-for-go-ipfs-release/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -eu

echo '💫 Checking for new releases...'

CURRENT=`node -e 'console.log(require("./package.json").version)'`
LATEST=`curl --silent https://dist.ipfs.io/go-ipfs/versions | tail -n 1 | cut -c 2-`

if [[ "$CURRENT" != "$LATEST" ]]; then
echo "🎉 New release exists $LATEST"
else
echo "💤 $CURRENT is the latest release. Going back to sleep"
# neutral github action exit... not good, not bad.
# https://developer.github.com/actions/creating-github-actions/accessing-the-runtime-environment/#exit-codes-and-statuses
exit 78
fi
9 changes: 9 additions & 0 deletions action-publish/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM node:10

LABEL "com.github.actions.name"="Version and publish"
LABEL "com.github.actions.description"="npm version and publish with new go-ipfs version"
LABEL "com.github.actions.icon"="box"
LABEL "com.github.actions.color"="green"

COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
48 changes: 48 additions & 0 deletions action-publish/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash
set -eu

echo '💫 Checking for new releases...'

CURRENT=`node -e 'console.log(require("./package.json").version)'`
LATEST=`curl --silent https://dist.ipfs.io/go-ipfs/versions | tail -n 1 | cut -c 2-`

if [ -n "$NPM_AUTH_TOKEN" ]; then
# Respect NPM_CONFIG_USERCONFIG if it is provided, default to $HOME/.npmrc
NPM_CONFIG_USERCONFIG="${NPM_CONFIG_USERCONFIG-"$HOME/.npmrc"}"
NPM_REGISTRY_URL="${NPM_REGISTRY_URL-registry.npmjs.org}"
NPM_STRICT_SSL="${NPM_STRICT_SSL-true}"
NPM_REGISTRY_SCHEME="https"
if ! $NPM_STRICT_SSL
then
NPM_REGISTRY_SCHEME="http"
fi

# Allow registry.npmjs.org to be overridden with an environment variable
printf "//%s/:_authToken=%s\\nregistry=%s\\nstrict-ssl=%s" "$NPM_REGISTRY_URL" "$NPM_AUTH_TOKEN" "${NPM_REGISTRY_SCHEME}://$NPM_REGISTRY_URL" "${NPM_STRICT_SSL}" > "$NPM_CONFIG_USERCONFIG"

chmod 0600 "$NPM_CONFIG_USERCONFIG"
fi

if [[ "$CURRENT" != "$LATEST" ]]; then
echo "🎉 New release exists $LATEST"

# The workspace starts as a detached commit for scheduled builds...
git checkout -b master
# Set sensible commit info
git config --global user.name "${GITHUB_ACTOR}"
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"

npm version $LATEST
npm publish --access public
echo "📦 published $LATEST to npm"

git push -u origin master
git push --tags
echo "👍 pushed changes back to master"

else
echo "💤 $CURRENT is the latest release. Going back to sleep"
# neutral github action exit... not good, not bad.
# https://developer.github.com/actions/creating-github-actions/accessing-the-runtime-environment/#exit-codes-and-statuses
exit 78
fi
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "go-ipfs-dep",
"version": "0.4.20",
"name": "@olizilla/go-ipfs-dep",
"version": "0.4.21",
"description": "Install the latest go-ipfs binary",
"main": "src/index.js",
"engines": {
Expand Down