Skip to content

Update json dependency (#18) #110

Update json dependency (#18)

Update json dependency (#18) #110

Workflow file for this run

name: CI
on:
push:
branches:
- master
pull_request:
permissions:
contents: read
packages: write
pages: write
id-token: write
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"
bundler-cache: true
- name: Install restic and sqlite3 for integration tests
run: sudo apt-get update && sudo apt-get install -y restic sqlite3
- run: bin/test
env:
KAMAL_BACKUP_RUN_INTEGRATION: "1"
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
files: ./coverage/coverage.xml
fail_ci_if_error: false
release_gate:
runs-on: ubuntu-latest
needs: test
outputs:
publish_artifacts: ${{ steps.check_release.outputs.publish_artifacts }}
should_release: ${{ steps.check_release.outputs.should_release }}
stable: ${{ steps.check_release.outputs.stable }}
tag: ${{ steps.check_release.outputs.tag }}
version: ${{ steps.check_release.outputs.version }}
version_changed: ${{ steps.check_release.outputs.version_changed }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"
- name: Check release state
id: check_release
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
VERSION=$(ruby -r ./lib/kamal_backup/version -e 'puts KamalBackup::VERSION')
TAG="v${VERSION}"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
if ruby -rrubygems/version -e 'exit Gem::Version.new(ARGV.fetch(0)).prerelease? ? 0 : 1' "$VERSION"; then
echo "stable=false" >> "$GITHUB_OUTPUT"
else
echo "stable=true" >> "$GITHUB_OUTPUT"
fi
GEM_NAME="kamal-backup"
ALL_PUBLISHED_VERSIONS=$(( \
gem list ^${GEM_NAME}$ -r --all 2>/dev/null || true; \
gem list ^${GEM_NAME}$ -r --prerelease 2>/dev/null || true; \
) | sed -n 's/.*(\(.*\)).*/\1/p' \
| tr ',' '\n' \
| sed 's/^[[:space:]]*//;s/[[:space:]]*$//' \
| sed '/^$/d' \
| sort -u )
if echo "$ALL_PUBLISHED_VERSIONS" | grep -Fxq "$VERSION"; then
version_changed=false
else
version_changed=true
fi
echo "version_changed=${version_changed}" >> "$GITHUB_OUTPUT"
if git ls-remote --exit-code --tags origin "refs/tags/${TAG}" >/dev/null 2>&1; then
tag_missing=false
else
tag_missing=true
fi
if gh release view "$TAG" >/dev/null 2>&1; then
release_missing=false
else
release_missing=true
fi
release_ref=false
if [ "$GITHUB_REF" = "refs/heads/${{ github.event.repository.default_branch }}" ]; then
release_ref=true
fi
if [ "$release_ref" = "true" ] && { [ "$version_changed" = "true" ] || [ "$tag_missing" = "true" ]; }; then
echo "publish_artifacts=true" >> "$GITHUB_OUTPUT"
else
echo "publish_artifacts=false" >> "$GITHUB_OUTPUT"
fi
if [ "$release_ref" = "true" ] && { [ "$version_changed" = "true" ] || [ "$tag_missing" = "true" ] || [ "$release_missing" = "true" ]; }; then
echo "should_release=true" >> "$GITHUB_OUTPUT"
else
echo "should_release=false" >> "$GITHUB_OUTPUT"
fi
image:
runs-on: ubuntu-latest
needs: [test, release_gate]
steps:
- uses: actions/checkout@v4
- id: version
name: Read kamal-backup version
run: |
VERSION=$(ruby -r ./lib/kamal_backup/version -e 'puts KamalBackup::VERSION')
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
if [ "${{ needs.release_gate.outputs.publish_artifacts }}" = "true" ]; then
echo "version_tag=true" >> "$GITHUB_OUTPUT"
else
echo "version_tag=false" >> "$GITHUB_OUTPUT"
fi
if ruby -rrubygems/version -e 'exit Gem::Version.new(ARGV.fetch(0)).prerelease? ? 0 : 1' "$VERSION"; then
echo "stable=false" >> "$GITHUB_OUTPUT"
else
echo "stable=true" >> "$GITHUB_OUTPUT"
fi
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
if: github.event_name != 'pull_request'
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/crmne/kamal-backup
tags: |
type=ref,event=branch
type=ref,event=tag
type=sha,prefix=sha-
type=raw,value=${{ steps.version.outputs.version }},enable=${{ steps.version.outputs.version_tag == 'true' }}
type=raw,value=latest,enable=${{ steps.version.outputs.version_tag == 'true' && steps.version.outputs.stable == 'true' }}
labels: |
org.opencontainers.image.version=${{ steps.version.outputs.version }}
- uses: docker/build-push-action@v6
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
gem:
runs-on: ubuntu-latest
needs: [test, release_gate]
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"
bundler-cache: true
- name: Build gem
run: gem build kamal-backup.gemspec
- name: Inspect gem
run: |
ruby -rrubygems/package -e '
spec = Gem::Package.new(Dir["kamal-backup-*.gem"].first).spec
puts "name=#{spec.name}"
puts "version=#{spec.version}"
puts "summary=#{spec.summary}"
puts "executables=#{spec.executables.join(",")}"
'
- name: Check if version needs publishing
if: github.event_name != 'pull_request' && needs.release_gate.outputs.should_release == 'true'
id: check_version
run: |
set -euo pipefail
VERSION=$(ruby -r ./lib/kamal_backup/version -e 'puts KamalBackup::VERSION')
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
GEM_NAME="kamal-backup"
ALL_PUBLISHED_VERSIONS=$(( \
gem list ^${GEM_NAME}$ -r --all 2>/dev/null || true; \
gem list ^${GEM_NAME}$ -r --prerelease 2>/dev/null || true; \
) | sed -n 's/.*(\(.*\)).*/\1/p' \
| tr ',' '\n' \
| sed 's/^[[:space:]]*//;s/[[:space:]]*$//' \
| grep . \
| sort -u )
if echo "$ALL_PUBLISHED_VERSIONS" | grep -Fxq "$VERSION"; then
echo "version_changed=false" >> "$GITHUB_OUTPUT"
else
echo "version_changed=true" >> "$GITHUB_OUTPUT"
fi
shell: bash
- name: Publish to RubyGems
if: steps.check_version.outputs.version_changed == 'true'
run: |
mkdir -p "$HOME/.gem"
touch "$HOME/.gem/credentials"
chmod 0600 "$HOME/.gem/credentials"
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > "$HOME/.gem/credentials"
output=$(gem push "kamal-backup-${VERSION}.gem" 2>&1) || {
echo "$output"
if echo "$output" | grep -q "Repushing of gem versions is not allowed"; then
echo "Version already exists on RubyGems, skipping"
exit 0
else
exit 1
fi
}
env:
GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_AUTH_TOKEN }}
VERSION: ${{ steps.check_version.outputs.version }}
release:
runs-on: ubuntu-latest
needs: [test, release_gate, image, gem]
if: github.event_name != 'pull_request' && needs.release_gate.outputs.should_release == 'true'
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"
- name: Create GitHub release
run: |
set -euo pipefail
VERSION=$(ruby -r ./lib/kamal_backup/version -e 'puts KamalBackup::VERSION')
TAG="v${VERSION}"
release_target="$GITHUB_SHA"
git fetch --tags --force
if git rev-parse -q --verify "refs/tags/${TAG}" >/dev/null; then
tag_sha=$(git rev-list -n 1 "${TAG}")
if [ "$tag_sha" != "$GITHUB_SHA" ] && [ "${{ needs.release_gate.outputs.version_changed }}" = "true" ]; then
echo "::error::Tag ${TAG} already exists at ${tag_sha}, not ${GITHUB_SHA}."
exit 1
fi
release_target="$tag_sha"
else
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag "$TAG" "$GITHUB_SHA"
git push origin "$TAG"
fi
if gh release view "$TAG" >/dev/null 2>&1; then
echo "GitHub release $TAG already exists."
exit 0
fi
prerelease_args=()
if ruby -rrubygems/version -e "exit Gem::Version.new(ARGV.fetch(0)).prerelease? ? 0 : 1" "$VERSION"; then
prerelease_args=(--prerelease)
fi
previous_tag=$(git tag --sort=-v:refname --list 'v*' | awk -v current="$TAG" '$0 != current { print; exit }')
if [ -n "$previous_tag" ]; then
commit_range="${previous_tag}..${release_target}"
else
commit_range="${release_target}"
fi
commits=$(git log --reverse --format='* %H %s' "$commit_range" | grep -Ev '^\* [0-9a-f]+ (docs|test|chore):' || true)
if [ -z "$commits" ]; then
commits=$(git log --reverse --format='* %H %s' "$commit_range")
fi
{
echo "## Changelog"
echo "$commits"
if [ -n "$previous_tag" ]; then
echo
echo "**Full Changelog**: https://github.com/${GITHUB_REPOSITORY}/compare/${previous_tag}...${TAG}"
fi
} > release-notes.md
gh release create "$TAG" \
--target "$release_target" \
--notes-file release-notes.md \
"${prerelease_args[@]}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
docs:
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"
- uses: actions/configure-pages@v5
- name: Install docs dependencies
working-directory: docs
run: bundle install
- name: Build docs
working-directory: docs
run: bundle exec jekyll build
- uses: actions/upload-pages-artifact@v3
if: github.event_name != 'pull_request' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
with:
path: docs/_site
deploy-docs:
runs-on: ubuntu-latest
needs: docs
if: github.event_name != 'pull_request' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
concurrency:
group: pages
cancel-in-progress: false
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- id: deployment
uses: actions/deploy-pages@v4