diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 4220e451..e70451c9 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -1,96 +1,79 @@ # # Documentation deployment workflow. # -# Documentation is always deployed for master and release-* branches. -# In addition, there is a 'latest' alias that points to the version -# of the latest release, which is updated whenever a new release is -# published. +# Documentation is always deployed on a new release and commit to the 'main' branch. +# When release has a latest semantic version, a 'latest' alias is applied as well. # -name: docs +name: Documentation +run-name: "${{ github.ref_name }}: Documentation" + on: push: branches: - - master - - release-* + - main + create: tags: - - v* + - "v[0-9]+.[0-9]+.[0-9]+" jobs: + precheck: + name: Precheck + runs-on: ubuntu-latest + outputs: + version: ${{ steps.check.outputs.version }} + release: ${{ steps.check.outputs.release }} + steps: + - name: Extract version + id: check + run: |- + ref_type="${{ github.ref_type }}" + version="${{ github.ref_name }}" + release="false" + + if [ "${ref_type}" == "tag" ]; then + # Trim patch number. + version="${version%.*}" + release="true" + fi + + if [ "${ref_type}" == "branch" ] && [ "${version}" == "main" ]; then + release=true + fi + + echo "version=${version}" >> $GITHUB_OUTPUT + echo "release=${release}" >> $GITHUB_OUTPUT + deploy_docs: name: Deploy documentation runs-on: ubuntu-latest - strategy: - matrix: - python-version: [ 3.8 ] + needs: [precheck] + if: needs.precheck.outputs.release == 'true' steps: - - name: Checkout repository - uses: actions/checkout@v3 + - name: Checkout + uses: actions/checkout@v4 - - name: Get latest repository version - id: latest_version + - name: Get latest tag + id: latest_tag uses: oprypin/find-latest-tag@v1 with: repository: ${{ github.repository }} - prefix: 'v' - - - name: Extract version from branch name - id: branch_version - uses: actions/github-script@v6 - env: - BRANCH_NAME: ${{ github.ref_name }} - with: - result-encoding: string - script: | - const branch = process.env.BRANCH_NAME - if (branch.includes('release')) { - const prefix = 'v' - const version = branch.substring(branch.lastIndexOf('-') + 1, branch.length) - return version.startsWith(prefix) ? version : prefix + version - } - return branch - - - name: Shorten tag version - id: tag_version - if: ${{ github.ref_type == 'tag' }} - uses: actions/github-script@v6 - env: - TAG_NAME: ${{ github.ref_name }} - with: - result-encoding: string - script: | - version = process.env.TAG_NAME - return version.substring(0, version.lastIndexOf('.')) - - - name: Export versions as environment variables - run: | - echo "BRANCH_VERSION=${{ steps.branch_version.outputs.result }}" >> $GITHUB_ENV - echo "LATEST_VERSION=${{ steps.latest_version.outputs.tag }}" >> $GITHUB_ENV - echo "TAG_VERSION=${{ steps.tag_version.outputs.result }}" >> $GITHUB_ENV + regex: '^v\d+\.\d+\.\d+$' - - name: Configure Git user + - name: Fetch gh-pages run: | git config user.name github-actions - git config user.email github-actions@github.com - - - name: Fetch gh-pages repository - run: | + git config user.email github-actions@kubitect.io git fetch origin gh-pages --depth=1 - - name: Set up Python runtime - uses: actions/setup-python@v4 + - name: Setup Python + uses: actions/setup-python@v5 with: - python-version: ${{ matrix.python-version }} - - - name: Install Python dependencies - run: | - pip install -r docs/requirements.txt + python-version: 3.12 - name: Deploy documentation - if: ${{ github.ref_type == 'branch' }} - run: | - mike deploy --push --update-aliases ${{ env.BRANCH_VERSION }} - - - name: Deploy documentation and update alias for latest - if: ${{ github.ref_type == 'tag' && env.LATEST_VERSION == env.BRANCH_VERSION }} + env: + version: ${{ needs.precheck.outputs.version }} + latest: ${{ github.ref_name == steps.latest_tag.outputs.tag && 'latest' || '' }} run: | - mike deploy --push --update-aliases ${{ env.TAG_VERSION }} latest + pip install -r docs/requirements.txt + mike deploy --push --update-aliases ${version} ${latest} diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml deleted file mode 100644 index dd64f51f..00000000 --- a/.github/workflows/go-test.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: go test - -on: - push: - branches: - - master - pull_request: - branches: - - master - -jobs: - test: - strategy: - fail-fast: false - matrix: - os: - - ubuntu-latest - - macos-latest - runs-on: ${{ matrix.os }} - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Install Go - uses: actions/setup-go@v3 - with: - go-version-file: "go.mod" - - name: Install Python - uses: actions/setup-python@v4 - with: - python-version: 3.8 - - name: Install virtualenv - run: | - pip install --upgrade virtualenv - - name: Run Go Tests - run: | - go test ./... -v - diff --git a/.github/workflows/release-binaries.yml b/.github/workflows/release-binaries.yml new file mode 100644 index 00000000..e5c94ae3 --- /dev/null +++ b/.github/workflows/release-binaries.yml @@ -0,0 +1,41 @@ +name: Release +run-name: "${{ github.ref_name }}: Release" + +on: + release: + types: + - published + +env: + go-version: 1.18 + +jobs: + releases-matrix: + name: Release Go Binaries + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + goos: + - linux + - darwin + goarch: + - "386" + - amd64 + - arm64 + exclude: + - goarch: "386" + goos: darwin + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Release binaries + uses: wangyoucao577/go-release-action@v1 + with: + binary_name: kubitect + extra_files: LICENSE + goos: ${{ matrix.goos }} + goarch: ${{ matrix.goarch }} + goversion: ${{ env.go-version }} + github_token: ${{ github.token }} diff --git a/.github/workflows/release-cli-binaries.yml b/.github/workflows/release-cli-binaries.yml deleted file mode 100644 index 2a2ff7d6..00000000 --- a/.github/workflows/release-cli-binaries.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: cli release - -on: - release: - types: [ published ] - -env: - CLI_PATH: . - -jobs: - releases-matrix: - name: Release Go Binary - runs-on: ubuntu-latest - strategy: - matrix: - goos: [ linux, darwin ] - goarch: [ "386", amd64, arm64 ] - exclude: - - goarch: "386" - goos: darwin - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Release binaries - uses: wangyoucao577/go-release-action@v1 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - goos: ${{ matrix.goos }} - goarch: ${{ matrix.goarch }} - goversion: 1.18 - binary_name: "kubitect" - project_path: ${{ env.CLI_PATH }} - extra_files: LICENSE diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..a4fa5a0b --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,44 @@ +name: Tests +run-name: "${{ github.ref_name }}: Tests" + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + test: + name: Go tests + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-latest + - macos-latest + go: + - 1.18 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install Go + uses: actions/setup-go@v5 + with: + go-version-file: "go.mod" + + - name: Install Python + uses: actions/setup-python@v5 + with: + python-version: 3.12 + + - name: Install virtualenv + run: | + pip install --upgrade virtualenv + + - name: Run Go Tests + run: | + go test ./... -v