From 4272bc2c2f33583ad19f52034a22d73cac9864d0 Mon Sep 17 00:00:00 2001 From: Robert Lin Date: Tue, 20 Oct 2020 13:41:18 +0800 Subject: [PATCH] chore: publishing adjustments --- .github/workflows/publish-latest.yml | 3 +- .github/workflows/publish-release.yml | 33 ++++++++++--------- ...{build_release.sh => build_release_cli.sh} | 5 +-- .scripts/build_release_daemon.sh | 7 ++++ contrib/inertia-publish/main.go | 15 ++++++--- contrib/inertia-publish/templates/doc.go | 2 ++ 6 files changed, 40 insertions(+), 25 deletions(-) rename .scripts/{build_release.sh => build_release_cli.sh} (76%) create mode 100644 .scripts/build_release_daemon.sh create mode 100644 contrib/inertia-publish/templates/doc.go diff --git a/.github/workflows/publish-latest.yml b/.github/workflows/publish-latest.yml index fb8eac54..eee02910 100644 --- a/.github/workflows/publish-latest.yml +++ b/.github/workflows/publish-latest.yml @@ -10,8 +10,7 @@ jobs: steps: - uses: actions/checkout@v1 - name: Build daemon - run: make daemon-release RELEASE=latest - + run: RELEASE=latest bash .scripts/build_release_daemon.sh - name: Publish to GitHub Container Registry run: | echo ${{ secrets.GH_PACKAGES_TOKEN }} | docker login ghcr.io --username $GITHUB_ACTOR --password-stdin diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 9d04dc17..44f490af 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -9,39 +9,42 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - - uses: actions/setup-go@v1 - with: { go-version: '1.15' } - name: Build release run: | - docker login -u ${{ secrets.docker_user }} -p ${{ secrets.docker_key }} - RELEASE=$(git describe --tags) bash .scripts/build_release.sh - - # Inertia daemon - - name: 'daemon: publish to Docker Hub' + RELEASE=$(git describe --tags) bash .scripts/build_release_daemon.sh + - name: Publish to Docker Hub run: | docker login -u ${{ secrets.docker_user }} -p ${{ secrets.docker_key }} # Publish as legacy name docker tag ubclaunchpad/inertiad:$(git describe --tags) ubclaunchpad/inertia:$(git describe --tags) docker push ubclaunchpad/inertia:$(git describe --tags) - - name: 'daemon: publish to GitHub Container Registry' + - name: Publish to GitHub Container Registry run: | echo ${{ secrets.GH_PACKAGES_TOKEN }} | docker login ghcr.io --username $GITHUB_ACTOR --password-stdin docker tag ubclaunchpad/inertiad:$(git describe --tags) ghcr.io/ubclaunchpad/inertiad:$(git describe --tags) docker push ghcr.io/ubclaunchpad/inertiad:$(git describe --tags) - # Inertia CLI - - name: 'cli: publish to GitHub' + cli: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-go@v1 + with: { go-version: '1.15' } + - name: Build release + run: | + RELEASE=$(git describe --tags) bash .scripts/build_release_cli.sh + - name: Publish to GitHub uses: softprops/action-gh-release@v1 with: - files: inertia.v* + files: dist/inertia.v* env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: 'cli: publish to Homebrew and Scoop' + - name: Publish to Homebrew and Scoop if: github.event.release.prerelease != true + env: + GIT_CREDENTIALS: 'ubclaunchpad-bot:${{ secrets.LP_GH_PUBLIC_REPO_TOKEN }}' run: | git config --global user.email 'team+bot@ubclaunchpad.com' git config --global user.name 'ubclaunchpad-bot' - git config --global user.password ${{ secrets.LP_GH_PUBLIC_REPO_TOKEN }} - go run ./contrib/inertia-publish $(git describe --tags) \ + go run ./contrib/inertia-publish $(git describe --tags) --dryrun=false \ homebrew scoop \ - --dryrun=false diff --git a/.scripts/build_release.sh b/.scripts/build_release_cli.sh similarity index 76% rename from .scripts/build_release.sh rename to .scripts/build_release_cli.sh index 3cf5297d..beec3243 100755 --- a/.scripts/build_release.sh +++ b/.scripts/build_release_cli.sh @@ -2,10 +2,7 @@ # Specify platforms and release version PLATFORMS="linux/amd64 linux/386 darwin/amd64 windows/amd64 windows/386" -echo "Building release $RELEASE" - -# Build, tag and push Inertia Docker image -make daemon-release RELEASE="$RELEASE" +echo "Building CLI release $RELEASE" # Build Inertia Go binaries for specified platforms OUTDIR=${OUTDIR:-"dist"} diff --git a/.scripts/build_release_daemon.sh b/.scripts/build_release_daemon.sh new file mode 100644 index 00000000..0e2df6cc --- /dev/null +++ b/.scripts/build_release_daemon.sh @@ -0,0 +1,7 @@ +#! /bin/bash + +# Specify platforms and release version +echo "Building daemon release $RELEASE" + +# Build, tag and push Inertia Docker image +make daemon-release RELEASE="$RELEASE" diff --git a/contrib/inertia-publish/main.go b/contrib/inertia-publish/main.go index ff3de048..36f3d4a8 100644 --- a/contrib/inertia-publish/main.go +++ b/contrib/inertia-publish/main.go @@ -74,6 +74,16 @@ func newCommand(dir, name string, args ...string) *exec.Cmd { return cmd } +func getCloneURL(repository string) string { + // GIT_CREDENTIALS should be $USER:$TOKEN + if creds := os.Getenv("GIT_CREDENTIALS"); creds != "" { + // "Personal access tokens can only be used for HTTPS Git operations."" + // https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token#using-a-token-on-the-command-line + return fmt.Sprintf("https://%s@github.com/%s.git", creds, repository) + } + return fmt.Sprintf("https://github.com/%s.git", repository) +} + type channelConfig struct { Repository string Template string @@ -84,10 +94,7 @@ func (c *channelConfig) Publish(version, outdir string, renderedTemplate []byte, // load repository repoPath := filepath.Join(outdir, c.Repository) os.RemoveAll(repoPath) - clone := newCommand(outdir, "git", "clone", - // "Personal access tokens can only be used for HTTPS Git operations."" - // https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token#using-a-token-on-the-command-line - fmt.Sprintf("https://github.com/%s.git", c.Repository), + clone := newCommand(outdir, "git", "clone", getCloneURL(c.Repository), // clone into subdirectory c.Repository) if err := clone.Run(); err != nil { diff --git a/contrib/inertia-publish/templates/doc.go b/contrib/inertia-publish/templates/doc.go new file mode 100644 index 00000000..ac53e271 --- /dev/null +++ b/contrib/inertia-publish/templates/doc.go @@ -0,0 +1,2 @@ +// Package templates provides template scripts for distribution channels +package templates