Skip to content

Commit

Permalink
Setup releases on CI (#13)
Browse files Browse the repository at this point in the history
- release Helm chart
- create GitHub releases
- add CHANGELOGs
  • Loading branch information
tyranron authored Jul 22, 2022
1 parent dd29446 commit 5b27a8c
Show file tree
Hide file tree
Showing 7 changed files with 303 additions and 17 deletions.
183 changes: 169 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CI
on:
push:
branches: ["main"]
tags: ["v*"]
tags: ["helm/**", "v*"]
pull_request:
branches: ["main"]

Expand All @@ -14,9 +14,9 @@ concurrency:
env:
CACHE: ${{ (github.event_name == 'push'
|| github.event_name == 'pull_request')
&& github.ref != 'refs/heads/main'
&& !startsWith(github.ref, 'refs/tags/v')
&& !contains(github.event.head_commit.message, '[fresh ci]') }}
&& github.ref != 'refs/heads/main'
&& !startsWith(github.ref, 'refs/tags/v')
&& !contains(github.event.head_commit.message, '[fresh ci]') }}
RUST_BACKTRACE: 1
RUST_VER: "1.62"

Expand Down Expand Up @@ -48,6 +48,7 @@ jobs:
##########################

clippy:
if: ${{ !startsWith(github.ref, 'refs/tags/helm/') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -64,14 +65,20 @@ jobs:

helm-lint:
name: Lint Helm chart
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
strategy:
fail-fast: false
matrix:
chart: ["baza"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: azure/setup-helm@v3

- run: make helm.lint
- run: make helm.lint chart=${{ matrix.chart }}

rustfmt:
if: ${{ !startsWith(github.ref, 'refs/tags/helm/') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -92,6 +99,7 @@ jobs:

test-e2e:
name: E2E tests
if: ${{ !startsWith(github.ref, 'refs/tags/helm/') }}
needs: ["docker"]
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -122,6 +130,7 @@ jobs:

test-unit:
name: Unit tests
if: ${{ !startsWith(github.ref, 'refs/tags/helm/') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -143,6 +152,7 @@ jobs:
############

docker:
if: ${{ !startsWith(github.ref, 'refs/tags/helm/') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -160,6 +170,7 @@ jobs:
retention-days: 1

rustdoc:
if: ${{ !startsWith(github.ref, 'refs/tags/helm/') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -182,10 +193,10 @@ jobs:

release-docker:
name: Release Docker image
needs: ["docker", "test-e2e"]
if: ${{ github.event_name == 'push'
&& (github.ref == 'refs/heads/main'
|| startsWith(github.ref, 'refs/tags/v')) }}
&& (github.ref == 'refs/heads/main'
|| startsWith(github.ref, 'refs/tags/v')) }}
needs: ["docker", "test-e2e"]
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -236,7 +247,7 @@ jobs:
text: ${{ github.ref }}
regex: '^refs/tags/v((([0-9]+)\.[0-9]+)\.[0-9]+(-.+)?)$'
if: ${{ steps.skip.outputs.no == 'true'
&& startsWith(github.ref, 'refs/tags/v') }}
&& startsWith(github.ref, 'refs/tags/v') }}
- name: Form version Docker tags
id: tags
uses: actions/github-script@v6
Expand All @@ -253,20 +264,20 @@ jobs:
}
return versions;
if: ${{ steps.skip.outputs.no == 'true'
&& startsWith(github.ref, 'refs/tags/v') }}
&& startsWith(github.ref, 'refs/tags/v') }}

- run: make docker.tags
registries=${{ matrix.registry }}
of=build-${{ github.run_number }}
tags=${{ (startsWith(github.ref, 'refs/tags/v')
&& steps.tags.outputs.result)
|| 'edge' }}
|| 'edge' }}
if: ${{ steps.skip.outputs.no == 'true' }}
- run: make docker.push
registries=${{ matrix.registry }}
tags=${{ (startsWith(github.ref, 'refs/tags/v')
&& steps.tags.outputs.result)
|| 'edge' }}
|| 'edge' }}
if: ${{ steps.skip.outputs.no == 'true' }}

# On GitHub Container Registry README is automatically updated on pushes.
Expand All @@ -280,7 +291,7 @@ jobs:
DOCKER_USER: ${{ secrets.DOCKERHUB_BOT_USER }}
DOCKER_PASS: ${{ secrets.DOCKERHUB_BOT_PASS }}
if: ${{ steps.skip.outputs.no == 'true'
&& matrix.registry == 'docker.io' }}
&& matrix.registry == 'docker.io' }}
- name: Update README on Quay.io
uses: christian-korneck/update-container-description-action@v1
with:
Expand All @@ -290,4 +301,148 @@ jobs:
env:
DOCKER_APIKEY: ${{ secrets.QUAYIO_API_TOKEN }}
if: ${{ steps.skip.outputs.no == 'true'
&& matrix.registry == 'quay.io' }}
&& matrix.registry == 'quay.io' }}

release-github:
name: Release on GitHub
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
needs:
- clippy
- release-docker
- rustdoc
- rustfmt
- test-e2e
- test-unit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Parse semver versions from Git tag
id: semver
uses: actions-ecosystem/action-regex-match@v2
with:
text: ${{ github.ref }}
regex: '^refs/tags/v((([0-9]+)\.[0-9]+)\.[0-9]+(-.+)?)$'
- name: Verify Git tag version matches `Cargo.toml` version
run: |
test "${{ steps.semver.outputs.group1 }}" \
== "$(grep -m1 'version = "' Cargo.toml | cut -d'"' -f2)"
- name: Parse CHANGELOG link
id: changelog
run: echo ::set-output
name=link::${{ github.server_url }}/${{ github.repository }}/blob/v${{ steps.semver.outputs.group1 }}/CHANGELOG.md#$(sed -n '/^## \[${{ steps.semver.outputs.group1 }}\]/{s/^## \[\(.*\)\][^0-9]*\([0-9].*\)/\1--\2/;s/[^0-9a-z-]*//g;p;}' CHANGELOG.md)
- name: Parse milestone link
id: milestone
run: echo ::set-output
name=link::${{ github.server_url }}/${{ github.repository }}/milestone/$(sed -n '/^## \[${{ steps.semver.outputs.group1 }}\]/,/Milestone/{s/.*milestone.\([0-9]*\).*/\1/p;}' CHANGELOG.md)

- name: Create GitHub release
uses: softprops/action-gh-release@v1
with:
name: ${{ steps.semver.outputs.group1 }}
body: >
[Changelog](${{ steps.changelog.outputs.link }}) |
[Milestone](${{ steps.milestone.outputs.link }})
prerelease: ${{ contains(steps.semver.outputs.group1, '-') }}

release-helm:
name: Release Helm chart
if: ${{ startsWith(github.ref, 'refs/tags/helm/') }}
needs: ["helm-lint"]
strategy:
max-parallel: 1
matrix:
chart: ["baza"]
runs-on: ubuntu-latest
steps:
- id: skip
run: echo ::set-output name=no::${{
startsWith(github.ref,
format('refs/tags/helm/{0}/', matrix.chart))
}}

- uses: actions/checkout@v3
if: ${{ steps.skip.outputs.no == 'true' }}
- uses: azure/setup-helm@v3
if: ${{ steps.skip.outputs.no == 'true' }}

- name: Parse semver versions from Git tag
id: semver
uses: actions-ecosystem/action-regex-match@v2
with:
text: ${{ github.ref }}
regex: '^refs/tags/helm/${{ matrix.chart }}/((([0-9]+)\.[0-9]+)\.[0-9]+(-.+)?)$'
if: ${{ steps.skip.outputs.no == 'true' }}
- name: Verify Git tag version matches `Chart.yaml` version
run: |
test "${{ steps.semver.outputs.group1 }}" \
== "$(grep -m1 'version: ' helm/${{ matrix.chart }}/Chart.yaml \
| cut -d' ' -f2)"
if: ${{ steps.skip.outputs.no == 'true' }}

- run: make helm.package chart=${{ matrix.chart }}
out-dir=.cache/helm/ clean=yes
if: ${{ steps.skip.outputs.no == 'true' }}

# Helm's digest is just SHA256 checksum:
# https://github.com/helm/helm/blob/v3.9.2/pkg/provenance/sign.go#L417-L418
- name: Generate SHA256 checksum
run: ls -1 | xargs -I {} sh -c "sha256sum {} > {}.sha256sum"
working-directory: .cache/helm/
if: ${{ steps.skip.outputs.no == 'true' }}
- name: Show generated SHA256 checksum
run: cat *.sha256sum
working-directory: .cache/helm/
if: ${{ steps.skip.outputs.no == 'true' }}

- name: Parse CHANGELOG link
id: changelog
run: echo ::set-output
name=link::${{ github.server_url }}/${{ github.repository }}/blob/helm%2F${{ matrix.chart }}%2F${{ steps.semver.outputs.group1 }}/helm/${{ matrix.chart }}/CHANGELOG.md#$(sed -n '/^## \[${{ steps.semver.outputs.group1 }}\]/{s/^## \[\(.*\)\][^0-9]*\([0-9].*\)/\1--\2/;s/[^0-9a-z-]*//g;p;}' helm/${{ matrix.chart }}/CHANGELOG.md)

- name: Create GitHub release
uses: softprops/action-gh-release@v1
with:
name: helm/${{ matrix.chart }} ${{ steps.semver.outputs.group1 }}
body: >
[Changelog](${{ steps.changelog.outputs.link }}) |
[Overview](${{ github.server_url }}/${{ github.repository }}/tree/helm%2F${{ matrix.chart }}%2F${{ steps.semver.outputs.group1 }}/helm/${{ matrix.chart }}) |
[Values](${{ github.server_url }}/${{ github.repository }}/blob/helm%2F${{ matrix.chart }}%2F${{ steps.semver.outputs.group1 }}/helm/${{ matrix.chart }}/values.yaml)
files: |
.cache/helm/*.tgz
.cache/helm/*.sha256sum
fail_on_unmatched_files: true
prerelease: ${{ contains(steps.semver.outputs.group1, '-') }}
if: ${{ steps.skip.outputs.no == 'true' }}

- name: Parse Git repository name
id: repo
uses: actions-ecosystem/action-regex-match@v2
with:
text: ${{ github.repository }}
regex: '^${{ github.repository_owner }}/(.+)$'

# TODO: Find or write a tool to build index idempotently from GitHub
# releases, and keep on GitHub Pages only the built index.
# https://github.com/helm/chart-releaser/issues/133
- name: Update Helm repository index
run: |
set -ex
git config --local user.email 'actions+${{ github.run_number }}@github.com'
git config --local user.name 'GitHub Actions'
git fetch origin gh-pages:gh-pages
git checkout gh-pages
git reset --hard
mkdir -p helm/
cp -rf .cache/helm/*.tgz helm/
helm repo index helm/ --url=https://${{ github.repository_owner }}.github.io/${{ steps.repo.outputs.group1 }}/helm
git add -v helm/
git commit -m 'Release ${{ steps.semver.outputs.group1 }} version of `${{ matrix.chart }}` Helm chart'
git checkout -
git push origin gh-pages
if: ${{ steps.skip.outputs.no == 'true' }}
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Baza changelog
==============

All user visible changes to this project will be documented in this file. This project uses [Semantic Versioning 2.0.0].




## [0.1.0] · 2022-??-??
[0.1.0]: /../../tree/v0.1.0

### Added

- [S3 API]:
- `PutObject` method with `symlink-to` support. ([#1])
- Deployment:
- [Docker] image. ([#2])
- [Helm] chart. ([#3])
- [CLI]:
- `-l, --log-level` option specifying logging verbosity level. ([#1])
- `-p, --port` option specifying port to run on. ([#1])
- `-r, --root` option specifying directory where all buckets will be stored. ([#1])

[#1]: /../../pull/1
[#2]: /../../pull/2
[#3]: /../../pull/3




[CLI]: https://en.wikipedia.org/wiki/Command-line_interface
[Docker]: https://www.docker.com
[Helm]: https://helm.sh
[S3 API]: https://docs.aws.amazon.com/AmazonS3/latest/API/Type_API_Reference.html
[Semantic Versioning 2.0.0]: https://semver.org
40 changes: 37 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -283,17 +283,51 @@ docker.untar:
# Helm commands #
#################

helm-chart-dir := helm/baza
helm-chart := $(or $(chart),baza)
helm-chart-dir := helm/$(helm-chart)


# Lint project Helm chart.
#
# Usage:
# make helm.lint
# make helm.lint [chart=baza]

helm.lint:
helm lint $(helm-chart-dir)/


# Build Helm package from project Helm chart.
#
# Usage:
# make helm.package [chart=baza]
# [out-dir=(.cache/helm|<dir-path>)] [clean=(no|yes]]

helm-package-dir = $(or $(out-dir),.cache/helm)

helm.package:
ifeq ($(clean),yes)
@rm -rf $(helm-package-dir)
endif
@mkdir -p $(helm-package-dir)/
helm package --destination=$(helm-package-dir)/ $(helm-chart-dir)/


# Create and push Git tag to release project Helm chart.
#
# Usage:
# make helm.release [chart=baza]

helm-git-tag = helm/$(helm-chart)/$(strip \
$(shell grep -m1 'version: ' $(helm-chart-dir)/Chart.yaml | cut -d' ' -f2))

helm.release:
ifeq ($(shell git rev-parse $(helm-git-tag) >/dev/null 2>&1 && echo "ok"),ok)
$(error "Git tag $(helm-git-tag) already exists")
endif
git tag $(helm-git-tag)
git push origin refs/tags/$(helm-git-tag)




##################
Expand All @@ -303,5 +337,5 @@ helm.lint:
.PHONY: all docs down fmt image lint test up \
cargo.doc cargo.fmt cargo.lint \
docker.image docker.tags docker.push docker.tar docker.untar \
helm.lint \
helm.lint helm.package helm.release \
test.e2e test.unit
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Baza
| [GitHub Container Registry](https://github.com/orgs/instrumentisto/packages/container/package/baza)
| [Quay.io](https://quay.io/repository/instrumentisto/baza)

[Changelog](https://github.com/instrumentisto/baza/blob/main/CHANGELOG.md)

Simply scalable files storage without much fuss.

Currently, is under development.
Expand Down
Loading

0 comments on commit 5b27a8c

Please sign in to comment.