From b931379bd7202f1269c1204fa47998e5f5b7d13e Mon Sep 17 00:00:00 2001 From: Marlon Saglia Date: Mon, 19 Aug 2024 14:15:49 +0200 Subject: [PATCH] feat(ci): migrate publish-cli workflow to Github Actions --- .github/workflows/publish-cli.yml | 105 ++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 .github/workflows/publish-cli.yml diff --git a/.github/workflows/publish-cli.yml b/.github/workflows/publish-cli.yml new file mode 100644 index 000000000000..7f62342ab7eb --- /dev/null +++ b/.github/workflows/publish-cli.yml @@ -0,0 +1,105 @@ +name: Vespa CLI - Build and Publish + +on: + push: + tags: + - v* + pull_request: + branches: + - master + +defaults: + run: + # Specify to ensure "pipefail and errexit" are set. + # Ref: https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#defaultsrunshell + shell: bash + # This workflow only interacts with the client/go directory, so we can set the working directory here. + working-directory: client/go + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + + - name: Define Build Version + id: meta + run: | + if [[ "${{ github.event_name }}" == "push" && "${{ startswith(github.ref, 'refs/tags/v') }}" == "true" ]]; then + BUILD_VERSION="${{ github.ref_name }}" + else + BUILD_VERSION="0.0.0-dev_${{ github.run_number }}" + fi + + echo "version=${BUILD_VERSION}" >> $GITHUB_OUTPUT + + - name: build + env: + VERSION: ${{ steps.meta.outputs.version }} + run: | + make clean dist + + - name: test + run: | + make test + + - uses: actions/upload-artifact@v4 + with: + name: vespa-cli + path: client/go/dist + retention-days: 1 + + publish: + runs-on: macos-latest + + # if: github.event_name == 'push' && startswith(github.ref, 'refs/tags/v') + needs: + - build-cli + + container: + image: homebrew/brew:latest + + env: + HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.HOMEBREW_GITHUB_API_TOKEN }} + GH_TOKEN: ${{ github.token }} + + steps: + - uses: actions/checkout@v4 + + - uses: actions/download-artifact@v4 + with: + name: vespa-cli + path: client/go/dist + + - name: DEBUG + run: | + pwd + echo "===================== ls -lA =====================" + ls -lA + echo "===================== ls -lA dist =====================" + ls -lA dist + + - name: install-dependencies + env: + HOMEBREW_NO_ANALYTICS: 1 + HOMEBREW_NO_AUTO_UPDATE: 1 + HOMEBREW_NO_INSTALL_CLEANUP: 1 + run: | + brew install --quiet gh zip go + + - name: Publish to GitHub Releases + if: github.event_name == 'push' && github.ref == 'refs/tags/v*' + run: | + make -C client/go clean dist-github + + - name: Publish to Homebrew + if: github.event_name == 'push' && github.ref == 'refs/tags/v*' + run: | + make -C client/go clean dist-homebrew + + - name: Install via Homebrew + if: github.event_name == 'push' && github.ref == 'refs/tags/v*' + run: | + make -C client/go install-brew