Skip to content

Commit

Permalink
Merge pull request #38 from ipfs/ipdx/june
Browse files Browse the repository at this point in the history
Implement improvements requested by the IP Shipyard team
  • Loading branch information
galargh authored Jul 1, 2024
2 parents 29d82e6 + aea5416 commit da2c157
Show file tree
Hide file tree
Showing 10 changed files with 292 additions and 121 deletions.
104 changes: 0 additions & 104 deletions .env.sh

This file was deleted.

1 change: 1 addition & 0 deletions .env.sh
13 changes: 0 additions & 13 deletions .env.template

This file was deleted.

1 change: 1 addition & 0 deletions .env.template
106 changes: 106 additions & 0 deletions actions/embed/.env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/usr/bin/env bash

github_token="$GITHUB_TOKEN"
if [[ -z "$github_token" ]]; then
echo "Please provide a GitHub token. You can create one at:"
echo " https://github.com/settings/tokens/new?scopes=repo,read:user,user:email,write:packages"
echo "If you don't want the value to be stored in a file, leave it empty and you will be prompted for it later."
echo "GitHub token: "
read -s github_token
fi

github_user_name="$GITHUB_USER_NAME"
if [[ -z "$github_user_name" ]]; then
github_user_name="$(git config --global user.name)"
fi
if [[ -z "$github_user_name" ]]; then
echo "Please provide a GitHub user name. You can also configure it with:"
echo " git config --global user.name \"Your Name\""
echo "If you don't want the value to be stored in a file, leave it empty and you will be prompted for it later."
echo "GitHub user name: "
read github_user_name
fi

github_user_email="$GITHUB_USER_EMAIL"
if [[ -z "$github_user_email" ]]; then
github_user_email="$(git config --global user.email)"
fi
if [[ -z "$github_user_email" ]]; then
echo "Please provide a GitHub user email. You can also configure it with:"
echo " git config --global user.email \"Your Email\""
echo "If you don't want the value to be stored in a file, leave it empty and you will be prompted for it later."
echo "GitHub user email: "
read github_user_email
fi

if [[ -z "$NO_GPG" ]]; then
gpg_id="$GPG_ID"
if [[ -z "$gpg_id" ]]; then
gpg_id="$(git config --global user.signingkey)"
fi
if [[ -z "$gpg_id" ]]; then
echo "Please provide a GPG ID. You can also configure it by following:"
echo " https://docs.github.com/en/authentication/managing-commit-signature-verification/telling-git-about-your-signing-key"
echo "If you don't want the value to be stored in a file, leave it empty and you will be prompted for it later."
echo "GPG ID: "
read gpg_id
fi
if [[ -n "$gpg_id" ]]; then
gpg_passphrase="$GPG_PASSPHRASE"
if [[ -z "$gpg_passphrase" ]]; then
echo "Please provide a GPG passphrase for the key $gpg_id."
echo "If you don't want the value to be stored in a file, leave it empty and you will be prompted for it later."
echo "GPG passphrase: "
read -s gpg_passphrase
fi
if [[ -n "$gpg_passphrase" ]]; then
gpg_key="$GPG_KEY"
if [[ -z "$gpg_key" ]]; then
gpg_key="$(gpg --armor --pinentry-mode=loopback --passphrase "$gpg_passphrase" --export-secret-key "$gpg_id" -w0 | base64 -w0)"
fi
fi
fi
fi

if [[ -z "$NO_MATRIX" ]]; then
matrix_url="$MATRIX_URL"
if [[ -z "$matrix_url" ]]; then
echo "Please provide a Matrix URL. For example: https://matrix-client.matrix.org/"
echo "If you don't want the value to be stored in a file, leave it empty and you will be prompted for it later."
echo "Matrix URL: "
read matrix_url
fi
matrix_user="$MATRIX_USER"
if [[ -z "$matrix_user" ]]; then
echo "Please provide a Matrix username."
echo "If you don't want the value to be stored in a file, leave it empty and you will be prompted for it later."
echo "Matrix username: "
read matrix_user
fi

matrix_password="$MATRIX_PASSWORD"
if [[ -z "$matrix_password" ]]; then
echo "Please provide a Matrix password."
echo "If you don't want the value to be stored in a file, leave it empty and you will be prompted for it later."
echo "Matrix password: "
read -s matrix_password
fi
fi

export GITHUB_TOKEN="$github_token"
export GITHUB_USER_NAME="$github_user_name"
export GITHUB_USER_EMAIL="$github_user_email"

export NO_GPG="$NO_GPG"
export GPG_ID="$gpg_id"
export GPG_PASSPHRASE="$gpg_passphrase"
export GPG_KEY="$gpg_key"

export NO_MATRIX="$NO_MATRIX"
export MATRIX_URL="$matrix_url"
export MATRIX_USER="$matrix_user"
export MATRIX_PASSWORD="$matrix_password"


# cat $ENV_TEMPLATE or fall back to .env.template
cat "${ENV_TEMPLATE:-.env.template}" | envsubst > .env
13 changes: 13 additions & 0 deletions actions/embed/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
GITHUB_TOKEN=$GITHUB_TOKEN
GITHUB_USER_NAME=$GITHUB_USER_NAME
GITHUB_USER_EMAIL=$GITHUB_USER_EMAIL

NO_GPG=$NO_GPG
GPG_ID=$GPG_ID
GPG_KEY=$GPG_KEY
GPG_PASSPHRASE=$GPG_PASSPHRASE

NO_MATRIX=$NO_MATRIX
MATRIX_URL=$MATRIX_URL
MATRIX_USER=$MATRIX_USER
MATRIX_PASSWORD=$MATRIX_PASSWORD
59 changes: 59 additions & 0 deletions actions/env.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package actions

import (
_ "embed"
"fmt"
"os"

"github.com/ipfs/kuboreleaser/util"
)

type Env struct{}

//go:embed embed/.env.sh
var envScript string

//go:embed embed/.env.template
var envTemplate string

func (ctx Env) Check() error {
if _, err := os.Stat(".env"); os.IsNotExist(err) {
return fmt.Errorf("file .env does not exist yet in the current directory (%w)", ErrIncomplete)
}
return nil
}

func (ctx Env) Run() error {
envScriptFile, err := os.CreateTemp("", ".env.*.sh")
if err != nil {
return err
}
_, err = envScriptFile.WriteString(envScript)
if err != nil {
return err
}
err = os.Chmod(envScriptFile.Name(), 0755)
if err != nil {
return err
}
envTemplateFile, err := os.CreateTemp("", ".env.*.sh")
if err != nil {
return err
}
_, err = envTemplateFile.WriteString(envTemplate)
if err != nil {
return err
}

cmd := util.Command{
Name: envScriptFile.Name(),
Stdin: os.Stdin,
Env: append(os.Environ(), fmt.Sprintf("ENV_TEMPLATE=%s", envTemplateFile.Name())),
}
err = cmd.Run()
if err != nil {
return err
}

return nil
}
12 changes: 11 additions & 1 deletion actions/publish_to_github.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,17 @@ func (ctx PublishToGitHub) Run() error {
}
}

_, err := ctx.GitHub.GetOrCreateRelease(repos.Kubo.Owner, repos.Kubo.Repo, ctx.Version.String(), ctx.Version.String(), body, ctx.Version.IsPrerelease())
latestRelease, err := ctx.GitHub.GetLatestRelease(repos.Kubo.Owner, repos.Kubo.Repo)
if err != nil {
return err
}

latestVersion, err := util.NewVersion(latestRelease.GetTagName())
if err != nil {
return err
}

_, err = ctx.GitHub.GetOrCreateRelease(repos.Kubo.Owner, repos.Kubo.Repo, ctx.Version.String(), ctx.Version.String(), body, ctx.Version.IsPrerelease(), ctx.Version.Compare(latestVersion) >= 0)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit da2c157

Please sign in to comment.