Skip to content
This repository was archived by the owner on Jan 31, 2025. It is now read-only.

Commit da2c157

Browse files
authored
Merge pull request #38 from ipfs/ipdx/june
Implement improvements requested by the IP Shipyard team
2 parents 29d82e6 + aea5416 commit da2c157

File tree

10 files changed

+292
-121
lines changed

10 files changed

+292
-121
lines changed

.env.sh

Lines changed: 0 additions & 104 deletions
This file was deleted.

.env.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
actions/embed/.env.sh

.env.template

Lines changed: 0 additions & 13 deletions
This file was deleted.

.env.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
actions/embed/.env.template

actions/embed/.env.sh

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/usr/bin/env bash
2+
3+
github_token="$GITHUB_TOKEN"
4+
if [[ -z "$github_token" ]]; then
5+
echo "Please provide a GitHub token. You can create one at:"
6+
echo " https://github.com/settings/tokens/new?scopes=repo,read:user,user:email,write:packages"
7+
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."
8+
echo "GitHub token: "
9+
read -s github_token
10+
fi
11+
12+
github_user_name="$GITHUB_USER_NAME"
13+
if [[ -z "$github_user_name" ]]; then
14+
github_user_name="$(git config --global user.name)"
15+
fi
16+
if [[ -z "$github_user_name" ]]; then
17+
echo "Please provide a GitHub user name. You can also configure it with:"
18+
echo " git config --global user.name \"Your Name\""
19+
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."
20+
echo "GitHub user name: "
21+
read github_user_name
22+
fi
23+
24+
github_user_email="$GITHUB_USER_EMAIL"
25+
if [[ -z "$github_user_email" ]]; then
26+
github_user_email="$(git config --global user.email)"
27+
fi
28+
if [[ -z "$github_user_email" ]]; then
29+
echo "Please provide a GitHub user email. You can also configure it with:"
30+
echo " git config --global user.email \"Your Email\""
31+
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."
32+
echo "GitHub user email: "
33+
read github_user_email
34+
fi
35+
36+
if [[ -z "$NO_GPG" ]]; then
37+
gpg_id="$GPG_ID"
38+
if [[ -z "$gpg_id" ]]; then
39+
gpg_id="$(git config --global user.signingkey)"
40+
fi
41+
if [[ -z "$gpg_id" ]]; then
42+
echo "Please provide a GPG ID. You can also configure it by following:"
43+
echo " https://docs.github.com/en/authentication/managing-commit-signature-verification/telling-git-about-your-signing-key"
44+
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."
45+
echo "GPG ID: "
46+
read gpg_id
47+
fi
48+
if [[ -n "$gpg_id" ]]; then
49+
gpg_passphrase="$GPG_PASSPHRASE"
50+
if [[ -z "$gpg_passphrase" ]]; then
51+
echo "Please provide a GPG passphrase for the key $gpg_id."
52+
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."
53+
echo "GPG passphrase: "
54+
read -s gpg_passphrase
55+
fi
56+
if [[ -n "$gpg_passphrase" ]]; then
57+
gpg_key="$GPG_KEY"
58+
if [[ -z "$gpg_key" ]]; then
59+
gpg_key="$(gpg --armor --pinentry-mode=loopback --passphrase "$gpg_passphrase" --export-secret-key "$gpg_id" -w0 | base64 -w0)"
60+
fi
61+
fi
62+
fi
63+
fi
64+
65+
if [[ -z "$NO_MATRIX" ]]; then
66+
matrix_url="$MATRIX_URL"
67+
if [[ -z "$matrix_url" ]]; then
68+
echo "Please provide a Matrix URL. For example: https://matrix-client.matrix.org/"
69+
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."
70+
echo "Matrix URL: "
71+
read matrix_url
72+
fi
73+
matrix_user="$MATRIX_USER"
74+
if [[ -z "$matrix_user" ]]; then
75+
echo "Please provide a Matrix username."
76+
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."
77+
echo "Matrix username: "
78+
read matrix_user
79+
fi
80+
81+
matrix_password="$MATRIX_PASSWORD"
82+
if [[ -z "$matrix_password" ]]; then
83+
echo "Please provide a Matrix password."
84+
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."
85+
echo "Matrix password: "
86+
read -s matrix_password
87+
fi
88+
fi
89+
90+
export GITHUB_TOKEN="$github_token"
91+
export GITHUB_USER_NAME="$github_user_name"
92+
export GITHUB_USER_EMAIL="$github_user_email"
93+
94+
export NO_GPG="$NO_GPG"
95+
export GPG_ID="$gpg_id"
96+
export GPG_PASSPHRASE="$gpg_passphrase"
97+
export GPG_KEY="$gpg_key"
98+
99+
export NO_MATRIX="$NO_MATRIX"
100+
export MATRIX_URL="$matrix_url"
101+
export MATRIX_USER="$matrix_user"
102+
export MATRIX_PASSWORD="$matrix_password"
103+
104+
105+
# cat $ENV_TEMPLATE or fall back to .env.template
106+
cat "${ENV_TEMPLATE:-.env.template}" | envsubst > .env

actions/embed/.env.template

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
GITHUB_TOKEN=$GITHUB_TOKEN
2+
GITHUB_USER_NAME=$GITHUB_USER_NAME
3+
GITHUB_USER_EMAIL=$GITHUB_USER_EMAIL
4+
5+
NO_GPG=$NO_GPG
6+
GPG_ID=$GPG_ID
7+
GPG_KEY=$GPG_KEY
8+
GPG_PASSPHRASE=$GPG_PASSPHRASE
9+
10+
NO_MATRIX=$NO_MATRIX
11+
MATRIX_URL=$MATRIX_URL
12+
MATRIX_USER=$MATRIX_USER
13+
MATRIX_PASSWORD=$MATRIX_PASSWORD

actions/env.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package actions
2+
3+
import (
4+
_ "embed"
5+
"fmt"
6+
"os"
7+
8+
"github.com/ipfs/kuboreleaser/util"
9+
)
10+
11+
type Env struct{}
12+
13+
//go:embed embed/.env.sh
14+
var envScript string
15+
16+
//go:embed embed/.env.template
17+
var envTemplate string
18+
19+
func (ctx Env) Check() error {
20+
if _, err := os.Stat(".env"); os.IsNotExist(err) {
21+
return fmt.Errorf("file .env does not exist yet in the current directory (%w)", ErrIncomplete)
22+
}
23+
return nil
24+
}
25+
26+
func (ctx Env) Run() error {
27+
envScriptFile, err := os.CreateTemp("", ".env.*.sh")
28+
if err != nil {
29+
return err
30+
}
31+
_, err = envScriptFile.WriteString(envScript)
32+
if err != nil {
33+
return err
34+
}
35+
err = os.Chmod(envScriptFile.Name(), 0755)
36+
if err != nil {
37+
return err
38+
}
39+
envTemplateFile, err := os.CreateTemp("", ".env.*.sh")
40+
if err != nil {
41+
return err
42+
}
43+
_, err = envTemplateFile.WriteString(envTemplate)
44+
if err != nil {
45+
return err
46+
}
47+
48+
cmd := util.Command{
49+
Name: envScriptFile.Name(),
50+
Stdin: os.Stdin,
51+
Env: append(os.Environ(), fmt.Sprintf("ENV_TEMPLATE=%s", envTemplateFile.Name())),
52+
}
53+
err = cmd.Run()
54+
if err != nil {
55+
return err
56+
}
57+
58+
return nil
59+
}

actions/publish_to_github.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,17 @@ func (ctx PublishToGitHub) Run() error {
7171
}
7272
}
7373

74-
_, err := ctx.GitHub.GetOrCreateRelease(repos.Kubo.Owner, repos.Kubo.Repo, ctx.Version.String(), ctx.Version.String(), body, ctx.Version.IsPrerelease())
74+
latestRelease, err := ctx.GitHub.GetLatestRelease(repos.Kubo.Owner, repos.Kubo.Repo)
75+
if err != nil {
76+
return err
77+
}
78+
79+
latestVersion, err := util.NewVersion(latestRelease.GetTagName())
80+
if err != nil {
81+
return err
82+
}
83+
84+
_, 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)
7585
if err != nil {
7686
return err
7787
}

0 commit comments

Comments
 (0)