Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement improvements requested by the IP Shipyard team #38

Merged
merged 4 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Check warning on line 23 in actions/env.go

View check run for this annotation

Codecov / codecov/patch

actions/env.go#L19-L23

Added lines #L19 - L23 were not covered by tests
}

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
}

Check warning on line 46 in actions/env.go

View check run for this annotation

Codecov / codecov/patch

actions/env.go#L26-L46

Added lines #L26 - L46 were not covered by tests

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
}

Check warning on line 56 in actions/env.go

View check run for this annotation

Codecov / codecov/patch

actions/env.go#L48-L56

Added lines #L48 - L56 were not covered by tests

return nil

Check warning on line 58 in actions/env.go

View check run for this annotation

Codecov / codecov/patch

actions/env.go#L58

Added line #L58 was not covered by tests
}
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 @@
}
}

_, 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
}

Check warning on line 77 in actions/publish_to_github.go

View check run for this annotation

Codecov / codecov/patch

actions/publish_to_github.go#L74-L77

Added lines #L74 - L77 were not covered by tests

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

Check warning on line 82 in actions/publish_to_github.go

View check run for this annotation

Codecov / codecov/patch

actions/publish_to_github.go#L79-L82

Added lines #L79 - L82 were not covered by tests

_, 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)

Check warning on line 84 in actions/publish_to_github.go

View check run for this annotation

Codecov / codecov/patch

actions/publish_to_github.go#L84

Added line #L84 was not covered by tests
if err != nil {
return err
}
Expand Down
Loading