1
0
مراية لـ https://github.com/postalserver/postal.git تم المزامنة 2025-11-30 21:32:30 +00:00

chore(build): improve build process, add release please (#2414)

هذا الالتزام موجود في:
Adam Cooke
2023-04-18 14:19:22 +01:00
ملتزم من قبل GitHub
الأصل 76f43140ae
التزام 5222263484
6 ملفات معدلة مع 117 إضافات و180 حذوفات

عرض الملف

@@ -3,63 +3,111 @@ name: CI
on: [push] on: [push]
jobs: jobs:
# lint: release-please:
# name: Lint runs-on: ubuntu-latest
# runs-on: self-hosted if: github.ref == 'refs/heads/main'
# steps: outputs:
# - uses: actions/checkout@v3 release_created: ${{ steps.release-please.outputs.release_created }}
# - run: make ci-lint tag_name: ${{ steps.release-please.outputs.tag_name }} # e.g. v1.0.0
version: ${{ steps.release-please.outputs.version }} # e.g. 1.0.0
all: ${{ toJSON(steps.release-please.outputs) }}
steps:
- uses: google-github-actions/release-please-action@v3
id: release-please
with:
command: manifest
build:
name: CI Image Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: docker/setup-buildx-action@v2
- uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v4
with:
push: true
tags: ghcr.io/postalserver/postal:ci-${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
target: ci
test: test:
name: Test name: Test Suite
runs-on: ubuntu-20.04 runs-on: ubuntu-latest
steps: needs: build
- uses: actions/checkout@v3
- name: Run tests
run: make ci-test
build-latest:
runs-on: ubuntu-20.04
needs: [test]
if: github.ref == 'refs/heads/main'
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Parse git ref - uses: docker/login-action@v2
run: |
echo "DOCKER_TAG_NAME=$(basename $GITHUB_REF)" >> $GITHUB_ENV
- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with: with:
registry: ghcr.io registry: ghcr.io
username: ${{ github.actor }} username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }} password: ${{ secrets.GITHUB_TOKEN }}
- run: docker-compose pull
- name: Build and push Docker image
run: make docker-release
build-release:
runs-on: ubuntu-20.04
needs: [test]
if: contains(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Parse git ref
run: |
echo "DOCKER_TAG_NAME=$(basename $GITHUB_REF)" >> $GITHUB_ENV
- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
run: make docker-release
env: env:
DOCKER_TAG_NAME: "latest" POSTAL_IMAGE: ghcr.io/postalserver/postal:ci-${{ github.sha }}
- run: docker-compose run postal sh -c 'bundle exec rspec'
env:
POSTAL_IMAGE: ghcr.io/postalserver/postal:ci-${{ github.sha }}
release-branch:
name: Release (branch)
runs-on: ubuntu-latest
needs: [build]
if: startsWith(github.ref, 'refs/heads/')
steps:
- uses: actions/checkout@v3
- uses: docker/setup-buildx-action@v2
- uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: tag
run: |
TAG="${GITHUB_REF#refs/heads/}"
if [ -z "$TAG" ]; then exit 1; fi
if [[ $TAG == "main" ]]; then TAG="latest"; else TAG="branch-${TAG}"; fi
echo "tag=${TAG}" >> $GITHUB_OUTPUT
- uses: docker/build-push-action@v4
with:
push: true
tags: |
ghcr.io/postalserver/postal:${{ steps.tag.outputs.tag }}
ghcr.io/postalserver/postal:commit-${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
target: full
publish-image:
name: Publish Image
runs-on: ubuntu-latest
needs: [build, test, release-please]
if: ${{ needs.release-please.outputs.release_created }}
steps:
- uses: actions/checkout@v3
- uses: docker/setup-buildx-action@v2
- uses: docker/login-action@v2
with:
registry: ${{ vars.KRYSTAL_REGISTRY_HOST }}
username: ${{ vars.KRYSTAL_REGISTRY_USERNAME }}
password: ${{ secrets.KRYSTAL_REGISTRY_PASSWORD }}
- uses: docker/build-push-action@v4
with:
push: true
tags: |
ghcr.io/postalserver/postal:stable
ghcr.io/postalserver/postal:${{ needs.release-please.outputs.version }}
cache-from: type=local,src=/cache/krystal-identity
cache-to: type=local,dest=/cache/krystal-identity,mode=max
target: full
build-args: |
VERSION=${{ needs.release-please.outputs.version }}

عرض الملف

@@ -0,0 +1,3 @@
{
".": "2.1.4"
}

عرض الملف

@@ -1,14 +0,0 @@
exports:
- name: CHANGELOG.md
formatter: markdown
options:
title: CHANGELOG
description: This file contains all the latest changes and updates to Postal.
sections:
- title: Features
types: [feat]
- title: Bug Fixes
types: [fix]
#
# There are additional options you can define, check out the README for details.
# https://github.com/krystal/schmersion

عرض الملف

@@ -56,8 +56,8 @@ CMD ["postal"]
# ci target - use --target=ci to skip asset compilation # ci target - use --target=ci to skip asset compilation
FROM base AS ci FROM base AS ci
# prod target - default if no --target option is given # full target - default if no --target option is given
FROM base AS prod FROM base AS full
RUN POSTAL_SKIP_CONFIG_CHECK=1 RAILS_GROUPS=assets bundle exec rake assets:precompile RUN POSTAL_SKIP_CONFIG_CHECK=1 RAILS_GROUPS=assets bundle exec rake assets:precompile
RUN touch /opt/postal/app/public/assets/.prebuilt RUN touch /opt/postal/app/public/assets/.prebuilt

115
Makefile
عرض الملف

@@ -1,115 +0,0 @@
# ==============================================================================
# Welcome to the Makefile
# ==============================================================================
#
# This Makefile contains a series of tasks which can help with building, testing
# and working with the app. The following tasks are available to you:
#
# Image building & releasing actions:
#
# make docker-build - Builds a production Docker image.
# make docker-ci-build - Builds an image without any asset compilation,
# ideal for running test suites and similar tasks.
# make docker-image - Builds a production Docker image and tags it as
# appropriate based on the current branch & tag.
# make docker-release - Builds a production Docker image and uploads to the
# registry.
#
# ==============================================================================
# Configuration
# ==============================================================================
# Docker image name to release the production image as.
DOCKER_IMAGE := ghcr.io/postalserver/postal
# Path to bundle config
BUNDLE_CONFIG ?= $(HOME)/.bundle/config
# Detect if a tty is available
TTY := $(shell [ -t 0 ] && echo 1)
# Tag names
DOCKER_TAG_NAME ?= $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
DOCKER_TAG_VERSION ?= $(shell git describe --tags --exact-match 2>/dev/null)
ifeq ($(DOCKER_TAG_NAME),master)
DOCKER_TAG_NAME = latest
endif
ifeq ($(DOCKER_TAG_NAME),main)
DOCKER_TAG_NAME = latest
endif
# Version string to use
VERSION ?= $(DOCKER_TAG_VERSION)
ifeq ($(VERSION),)
VERSION = $(shell git describe --tags 2>/dev/null)
endif
ifeq ($(VERSION),)
VERSION = 0.0.0-dev
endif
# ==============================================================================
# Image Building
# ==============================================================================
DOCKER_BUILD_CMD = DOCKER_BUILDKIT=1 docker \
build $(if $(TTY),,--progress plain) \
--build-arg VERSION=$(VERSION) \
.
DOCKER_CI_BUILD_CMD = $(DOCKER_BUILD_CMD) --target=ci
.PHONY: docker-build
docker-build:
$(DOCKER_BUILD_CMD)
.PHONY: docker-ci-build
docker-ci-build:
$(DOCKER_CI_BUILD_CMD)
# ==============================================================================
# Image Tagging
# ==============================================================================
.PHONY: docker-image
docker-image: docker-build
$(eval IMAGE := $(shell $(DOCKER_BUILD_CMD) -q))
ifeq ($(DOCKER_TAG_NAME),latest)
docker tag "$(IMAGE)" "$(DOCKER_IMAGE):$(DOCKER_TAG_NAME)"
endif
# ==============================================================================
# Image Releasing
# ==============================================================================
.PHONY: docker-release
docker-release: docker-image
ifeq ($(DOCKER_TAG_NAME),latest)
docker push "$(DOCKER_IMAGE):$(DOCKER_TAG_NAME)"
endif
ifneq ($(DOCKER_TAG_VERSION),)
docker tag "$(DOCKER_IMAGE):$(DOCKER_TAG_NAME)" \
"$(DOCKER_IMAGE):$(DOCKER_TAG_VERSION)" && \
docker push "$(DOCKER_IMAGE):$(DOCKER_TAG_VERSION)"
endif
# ==============================================================================
# Tests
# ==============================================================================
.PHONY: ci-test
ci-test: docker-ci-build
$(eval IMAGE := $(shell $(DOCKER_CI_BUILD_CMD) -q))
$(eval RAND := $(shell echo "$${RANDOM}$$(date +%s)"))
POSTAL_IMAGE=$(IMAGE) \
docker-compose -p "postal$(RAND)" run --rm postal sh -c 'bundle exec rspec'; \
EXIT_CODE=$$?; \
docker-compose -p "postal$(RAND)" down -v; \
exit $$EXIT_CODE
.PHONY: test
test:
bundle exec rspec

عرض الملف

@@ -0,0 +1,15 @@
{
"bootstrap-sha": "76f43140ae57964c871bb654d70d88ecc2210cb1",
"packages": {
".": {
"release-type": "ruby",
"changelog-path": "CHANGELOG.md",
"bump-minor-pre-major": true,
"bump-patch-for-minor-pre-major": true,
"draft": false,
"prerelease": false,
"include-v-in-tag": false
}
},
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json"
}