Skip to content

Commit

Permalink
Update GH workflows (#175)
Browse files Browse the repository at this point in the history
* github/workflows: Update documentation workflow

Update target branch (master -> main).
In addition, deploy docs only on a new release and
on commit to 'main' branch.

* github/workflows: Update tests workflow

Update target branch (master -> main).

* github/workflows: Update release-binaries workflow
  • Loading branch information
MusicDin authored Mar 9, 2024
1 parent ffde055 commit e55a9f2
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 139 deletions.
121 changes: 52 additions & 69 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -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 [email protected]
- name: Fetch gh-pages repository
run: |
git config user.email [email protected]
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}
37 changes: 0 additions & 37 deletions .github/workflows/go-test.yml

This file was deleted.

41 changes: 41 additions & 0 deletions .github/workflows/release-binaries.yml
Original file line number Diff line number Diff line change
@@ -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 }}
33 changes: 0 additions & 33 deletions .github/workflows/release-cli-binaries.yml

This file was deleted.

44 changes: 44 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e55a9f2

Please sign in to comment.