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

fix : move command exec into golang http in irgsh-cli. #147

Merged
merged 3 commits into from
Mar 19, 2023
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
106 changes: 53 additions & 53 deletions .github/workflows/generic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Generic github actions
on:
push:
branches-ignore:
- 'master'
- "master"

permissions:
contents: write
Expand All @@ -12,67 +12,67 @@ jobs:
build-devel:
runs-on: ubuntu-latest
steps:
- name: Get current date
run: echo "irgsh_build_date=$(TZ='Asia/Jakarta' date +'%Y%m%d%H%M')" >> $GITHUB_ENV
- uses: actions/checkout@v3
- name: Install needed apt packages
uses: awalsh128/[email protected]
with:
packages: gpg pbuilder debootstrap devscripts python3-apt reprepro make
version: 1.0
- uses: actions/setup-go@v3
with:
go-version: '1.13.14'
- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Build development release
run: |
echo ${{ env.irgsh_build_date }}-development-build > VERSION
make release
mv target/{release,pre-release}.tar.gz
- uses: actions/upload-artifact@v3
with:
name: pre-release.tar.gz
path: target/
- name: Get current date
run: echo "irgsh_build_date=$(TZ='Asia/Jakarta' date +'%Y%m%d%H%M')" >> $GITHUB_ENV
- uses: actions/checkout@v3
- name: Install needed apt packages
uses: awalsh128/[email protected]
with:
packages: gpg pbuilder debootstrap devscripts python3-apt reprepro make
version: 1.0
- uses: actions/setup-go@v3
with:
go-version: "1.13.14"
- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Build development release
run: |
echo ${{ env.irgsh_build_date }}-development-build > VERSION
make release
mv target/{release,pre-release}.tar.gz
- uses: actions/upload-artifact@v3
with:
name: pre-release.tar.gz
path: target/
outputs:
irgsh_build_date: ${{ env.irgsh_build_date }}

release:
runs-on: ubuntu-latest
needs: [build-devel]
steps:
- uses: actions/download-artifact@v3
with:
name: pre-release.tar.gz
- name: Extract pre-release
run: |
tar xvzf pre-release.tar.gz
cp $(find . -type f -name "irgsh-cli") .
- name: Create github pre-release
uses: softprops/[email protected]
with:
name: ${{ needs.build-devel.outputs.irgsh_build_date }} Development Release
body: Development release ${{ needs.build-devel.outputs.irgsh_build_date }}
draft: false
prerelease: true
tag_name: ${{ needs.build-devel.outputs.irgsh_build_date }}-development-build
files: |
pre-release.tar.gz
irgsh-cli
- uses: actions/download-artifact@v3
with:
name: pre-release.tar.gz
- name: Extract pre-release
run: |
tar xvzf pre-release.tar.gz
cp $(find . -type f -name "irgsh-cli") .
- name: Create github pre-release
uses: softprops/[email protected]
with:
name: ${{ needs.build-devel.outputs.irgsh_build_date }} Development Release
body: Development release ${{ needs.build-devel.outputs.irgsh_build_date }}
draft: false
prerelease: true
tag_name: ${{ needs.build-devel.outputs.irgsh_build_date }}-development-build
files: |
pre-release.tar.gz
irgsh-cli

deploy:
runs-on: ubuntu-latest
needs: [release]
steps:
- name: Deploy to irgsh development server
uses: kudaliar032/tendang-action@v1
with:
url: ${{ secrets.RAFI_TENDANG_URL }}
token: ${{ secrets.RAFI_DEPLOYMENT_KEY }}
name: ${{ secrets.RAFI_DEPLOYMENT_NAME }}
- name: Deploy to irgsh development server
uses: kudaliar032/tendang-action@v1
with:
url: ${{ secrets.RAFI_TENDANG_URL }}
token: ${{ secrets.RAFI_DEPLOYMENT_KEY }}
name: ${{ secrets.RAFI_DEPLOYMENT_NAME }}
104 changes: 52 additions & 52 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Master github actions
on:
push:
branches:
- 'master'
- "master"

permissions:
contents: write
Expand All @@ -12,66 +12,66 @@ jobs:
build-release:
runs-on: ubuntu-latest
steps:
- name: Get current date
run: echo "irgsh_build_date=$(TZ='Asia/Jakarta' date +'%Y%m%d%H%M')" >> $GITHUB_ENV
- uses: actions/checkout@v3
- name: Install needed apt packages
uses: awalsh128/[email protected]
with:
packages: gpg pbuilder debootstrap devscripts python3-apt reprepro make
version: 1.0
- uses: actions/setup-go@v3
with:
go-version: '1.13.14'
- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Build nightly release
run: |
echo ${{ steps.date.outputs.date }}-nightly-build > VERSION
make release
- uses: actions/upload-artifact@v3
with:
name: release.tar.gz
path: target/
- name: Get current date
run: echo "irgsh_build_date=$(TZ='Asia/Jakarta' date +'%Y%m%d%H%M')" >> $GITHUB_ENV
- uses: actions/checkout@v3
- name: Install needed apt packages
uses: awalsh128/[email protected]
with:
packages: gpg pbuilder debootstrap devscripts python3-apt reprepro make
version: 1.0
- uses: actions/setup-go@v3
with:
go-version: "1.13.14"
- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Build nightly release
run: |
echo ${{ steps.date.outputs.date }}-nightly-build > VERSION
make release
- uses: actions/upload-artifact@v3
with:
name: release.tar.gz
path: target/
outputs:
irgsh_build_date: ${{ env.irgsh_build_date }}

release:
runs-on: ubuntu-latest
needs: [build-release]
steps:
- uses: actions/download-artifact@v3
with:
name: release.tar.gz
- name: Extract release
run: |
tar xvzf release.tar.gz
cp $(find . -type f -name "irgsh-cli") .
- name: Create github release
uses: softprops/[email protected]
with:
name: ${{ needs.build-release.outputs.irgsh_build_date }} Nightly Release
body: Nightly release
draft: false
prerelease: false
tag_name: ${{ needs.build-release.outputs.irgsh_build_date }}-nightly-build
files: |
release.tar.gz
irgsh-cli
- uses: actions/download-artifact@v3
with:
name: release.tar.gz
- name: Extract release
run: |
tar xvzf release.tar.gz
cp $(find . -type f -name "irgsh-cli") .
- name: Create github release
uses: softprops/[email protected]
with:
name: ${{ needs.build-release.outputs.irgsh_build_date }} Nightly Release
body: Nightly release
draft: false
prerelease: false
tag_name: ${{ needs.build-release.outputs.irgsh_build_date }}-nightly-build
files: |
release.tar.gz
irgsh-cli

deploy:
runs-on: ubuntu-latest
needs: [release]
steps:
- name: Deploy to irgsh server
uses: kudaliar032/tendang-action@v1
with:
url: ${{ secrets.RANI_TENDANG_URL }}
token: ${{ secrets.RANI_DEPLOYMENT_KEY }}
name: ${{ secrets.RANI_DEPLOYMENT_NAME }}
- name: Deploy to irgsh server
uses: kudaliar032/tendang-action@v1
with:
url: ${{ secrets.RANI_TENDANG_URL }}
token: ${{ secrets.RANI_DEPLOYMENT_KEY }}
name: ${{ secrets.RANI_DEPLOYMENT_NAME }}
2 changes: 1 addition & 1 deletion .gitpod.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM debian:buster-slim
RUN apt update && apt install -y gpg pbuilder debootstrap devscripts python-apt reprepro make && \
RUN apt update && apt install -y gpg pbuilder debootstrap devscripts python3-apt reprepro make && \
curl -O https://storage.googleapis.com/golang/go1.13.14.linux-amd64.tar.gz && \
tar -xf go1.13.14.linux-amd64.tar.gz && \
mv go /usr/local && \
Expand Down
62 changes: 53 additions & 9 deletions cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ type Submission struct {
SourceBranch string `json:"sourceBranch"`
}

type GithubReleaseResponse struct {
Url string `json:"url"`
Assets []struct {
Name string `json:"name"`
BrowserDownloadUrl string `json:"browser_download_url"`
}
}

var (
app *cli.App
homeDir string
Expand Down Expand Up @@ -815,36 +823,72 @@ func main() {
Name: "update",
Usage: "Update the irgsh-cli tool",
Action: func(c *cli.Context) (err error) {
cmdStr := "curl -ksL 'https://api.github.com/repos/BlankOn/irgsh-go/releases/latest' | jq -r '.assets | .[] | select(.name == \"irgsh-cli\")| .browser_download_url'"
output, err := exec.Command("bash", "-c", cmdStr).Output()
var (
cmdStr = "ln -sf /usr/bin/irgsh-cli /usr/bin/irgsh && /usr/bin/irgsh-cli --version"
downloadURL string
githubResponse GithubReleaseResponse
githubAssetName = "irgsh-cli"
url = "https://api.github.com/repos/BlankOn/irgsh-go/releases/latest"
)

response, err := http.Get(url)
if err != nil {
log.Println("error: %v\n", err)
log.Printf("error: %v\n", err)
log.Println("Failed to get package name.")

return
}
downloadURL := strings.TrimSuffix(string(output), "\n")
defer response.Body.Close()

body, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Printf("error: %v\n", err)

return
}

if err := json.Unmarshal(body, &githubResponse); err != nil {
log.Printf("error: %v\n", err)

return err
}

for _, asset := range githubResponse.Assets {
if asset.Name == githubAssetName {
downloadURL = strings.TrimSuffix(string(asset.BrowserDownloadUrl), "\n")
break
}
}

log.Println(downloadURL)
log.Println("Self-updating...")

resp, err := http.Get(downloadURL)
if err != nil {
log.Println(err)
log.Printf("error: %v\n", err)

return err
}

defer resp.Body.Close()

err = update.Apply(resp.Body, update.Options{})
if err != nil {
log.Println(err)
log.Printf("error: %v\n", err)

return err
}
cmdStr = "ln -sf /usr/bin/irgsh-cli /usr/bin/irgsh && /usr/bin/irgsh-cli --version"

log.Println(cmdStr)
output, err = exec.Command("bash", "-c", cmdStr).Output()

output, err := exec.Command("bash", "-c", cmdStr).Output()
if err != nil {
log.Println(output)
log.Println("error: %v\n", err)
log.Printf("error: %v\n", err)
log.Println("Failed to get package name.")
}
log.Println("Updated to " + strings.TrimSuffix(string(output), "\n"))

return
},
},
Expand Down
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ else
apt install -y docker.io
fi

apt install -y gnupg pbuilder debootstrap devscripts debhelper python-apt reprepro jq
apt install -y gnupg pbuilder debootstrap devscripts debhelper python3-apt reprepro jq

if [ -f ./target/release.tar.gz ]; then
# For development/testing purpose
Expand Down