From 3e9adc26b1fa31156c422c447c823f51314e3235 Mon Sep 17 00:00:00 2001 From: Dhi Aurrahman Date: Tue, 23 Jan 2024 15:19:41 +0000 Subject: [PATCH] Setup CI run Signed-off-by: Dhi Aurrahman --- .github/workflows/release.yaml | 51 ++++++++++++++++++++++++++++++++++ .gitignore | 1 + magefile.go | 14 ++++++---- 3 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..2123f7f --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,51 @@ +name: Build and release +on: + push: + branches: + - main + pull_request: + branches: + - main + +concurrency: + group: build-and-release-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build-index: + permissions: + contents: write + runs-on: ubuntu-latest + timeout-minutes: 20 + steps: + - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 + - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 + with: + path: gh-pages + ref: gh-pages + - uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0 + with: + go-version: 1.21.6 + - uses: magefile/mage-action@6a5dcb5fe61f43d7c08a98bc3cf9bc63c308c08e # v3.0.0 + with: + install-only: true + - uses: crazy-max/ghaction-import-gpg@82a020f1f7f605c65dd2449b392a52c3fcfef7ef # v6.0.0 + with: + gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} + passphrase: ${{ secrets.GPG_PASSPHRASE }} + - run: mage packistio + env: + GH_TOKEN: ${{ secrets.GH_TOKEN }} + GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} + - if: github.ref == 'refs/heads/main' + run: mage index https://github.com/tetratelabs/legacy-charts/releases/download/istio- + - if: github.ref == 'refs/heads/main' + uses: stefanzweifel/git-auto-commit-action@8756aa072ef5b4a080af5dc8fef36c5d586e521d # v5.0.0 + with: + repository: gh-pages + commit_message: Apply automatic update for install.sh + branch: gh-pages + commit_user_name: tetrate-ci + commit_user_email: 52504619+tetrate-ci@users.noreply.github.com + commit_author: tetrate-ci[bot] <52504619+tetrate-ci@users.noreply.github.com> + file_pattern: '*.yaml' diff --git a/.gitignore b/.gitignore index 477894d..e6e1a54 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .DS_Store /dist +/gh-pages diff --git a/magefile.go b/magefile.go index 6ad01b9..7f30d31 100644 --- a/magefile.go +++ b/magefile.go @@ -36,26 +36,30 @@ func PackIstio(ctx context.Context) error { // URL gives prefix for the tarballs. For example: https://github.com/tetratelabs/legacy-charts/releases/download. func Index(ctx context.Context, url string) error { dir := filepath.Join("dist") + if _, err := os.Stat(dir); err != nil { + fmt.Println("missing dist, nothing to do") + return nil + } indexYAML := filepath.Join(dir, "index.yaml") - previousIndexYAML := filepath.Join("gh-pages", "index.yaml") + publishedIndexYAML := filepath.Join("gh-pages", "index.yaml") args := []string{ "repo", "index", dir, "--url", url, } - if _, err := os.Stat(previousIndexYAML); err == nil { - args = append(args, "--merge", previousIndexYAML) + if _, err := os.Stat(publishedIndexYAML); err == nil { + args = append(args, "--merge", publishedIndexYAML) } if err := sh.Run(ctx, "helm", args...); err != nil { return err } - b, err := os.ReadFile(filepath.Join(dir, "index.yaml")) + b, err := os.ReadFile(indexYAML) if err != nil { return err } sanitized := strings.ReplaceAll(string(b), "istio-/", "istio-") - return os.WriteFile(indexYAML, []byte(sanitized), os.ModePerm) + return os.WriteFile(publishedIndexYAML, []byte(sanitized), os.ModePerm) } func packVersioned(ctx context.Context, version string) error {