Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
342 changes: 342 additions & 0 deletions .github/workflows/release-go-daemons-reusable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,342 @@
name: Release go daemons

on:
workflow_call:
inputs:
start_mongodb:
type: boolean
required: false
default: false
start_redis:
type: boolean
required: false
default: false
dockerfile-image:
description: image for Generate Dockerfile
type: string
required: false
default: ubuntu:22.04
dockerfile-run:
description: addication "run" for Generate Dockerfile
type: string
required: false
default: "echo run"
dockerfile-cmd:
description: addication "cmd" for Generate Dockerfile
type: string
required: false
default: "echo cmd"
deploy-on-docker-hub:
type: boolean
required: false
default: true
deploy-arm:
type: boolean
required: false
default: true

permissions: write-all

jobs:
build:
name: Build and release
runs-on: ubuntu-latest
strategy:
matrix:
arch:
- amd64
- arm64
os:
- linux
go-version:
- '1.24'
include:
- arch: amd64
rpm_arch: x86_64
- arch: arm64
rpm_arch: aarch64
outputs:
body: ${{ steps.release_info.outputs.body }}
html_url: ${{ steps.release_info.outputs.html_url }}
tag_name: ${{ steps.release_info.outputs.tag_name }}
env:
GOPRIVATE: github.com/anyproto
steps:
- uses: actions/checkout@v5
- uses: actions/setup-go@v6
with:
go-version: '${{ matrix.go-version }}'
check-latest: true

- name: git config
run: git config --global url.https://${{ secrets.ANYTYPE_PAT }}@github.com/.insteadOf https://github.com/

- name: Start MongoDB
if: ${{ inputs.start_mongodb }}
uses: supercharge/mongodb-github-action@1.8.0
with:
mongodb-version: 6.0
mongodb-replica-set: test-rs

- name: Start Redis
uses: supercharge/redis-github-action@1.8.0
if: ${{ inputs.start_redis }}
with:
redis-image: redis/redis-stack-server

# build {{
- name: deps
run: make deps CGO_ENABLED=0

- name: unit tests
run: make test CGO_ENABLED=0

- name: build
run: make build CGO_ENABLED=0 BUILD_GOOS=${{ matrix.os }} BUILD_GOARCH=${{ matrix.arch }}
# }}

- name: get release version
id: release-version
run: |
echo "$GITHUB_REF_NAME" | sed 's|^[a-zA-Z]\+|RELEASE_VERSION=|' >> $GITHUB_OUTPUT
echo "$GITHUB_REF_NAME" | sed 's|^[a-zA-Z]\+|RELEASE_VERSION_RPM=|; s|-|_|g' >> $GITHUB_OUTPUT # FPM automatically converts versions for RPM

# create asset {{
- name: create zip archive
if: matrix.os == 'windows'
run: |
zip --junk-paths ${{ github.event.repository.name }}-${{ steps.release-version.outputs.RELEASE_VERSION }}.${{ matrix.os }}-${{ matrix.arch }}.zip bin/*
- name: create tar archive
if: matrix.os != 'windows'
run: |
tar \
--create \
--gzip \
--verbose \
--exclude='.gitignore' \
--file=${{ github.event.repository.name }}-${{ steps.release-version.outputs.RELEASE_VERSION }}.${{ matrix.os }}-${{ matrix.arch }}.tgz \
--directory=bin/ \
.
- name: create package deb
if: matrix.os == 'linux'
uses: fb929/github-action-fpm@master
with:
fpm_opts:
--name ${{ github.event.repository.name }}
--version ${{ steps.release-version.outputs.RELEASE_VERSION }}
--architecture ${{ matrix.arch }}
--url ${{ github.repositoryUrl }}
--description "commit ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}"
--exclude '*/.gitignore'
--exclude '*/.git'
--input-type dir
--output-type deb
fpm_args: ./bin
- name: create package rpm
if: matrix.os == 'linux'
uses: fb929/github-action-fpm@master
with:
fpm_opts:
--name ${{ github.event.repository.name }}
--version ${{ steps.release-version.outputs.RELEASE_VERSION }}
--architecture ${{ matrix.rpm_arch }}
--url ${{ github.repositoryUrl }}
--description "commit ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}"
--exclude '*/.gitignore'
--exclude '*/.git'
--input-type dir
--output-type rpm
fpm_args: ./bin
# }}

- name: debug
run: |
ls -al ./

# upload-release-asset {{
- name: Create release and upload asset zip | Windows
id: release_windows
uses: softprops/action-gh-release@v2
if: matrix.os == 'windows'
with:
name: Release ${{ github.ref_name }}
generate_release_notes: true
draft: false
prerelease: true
# for triggering workflow "push-docker-image-release" - https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#triggering-a-workflow-from-a-workflow
token: ${{ secrets.ANYTYPE_PAT }}
files: |
./${{ github.event.repository.name }}-${{ steps.release-version.outputs.RELEASE_VERSION }}.${{ matrix.os }}-${{ matrix.arch }}.zip

- name: Create release and upload asset tgz | Unix
id: release_unix
uses: softprops/action-gh-release@v2
if: matrix.os != 'windows'
with:
name: Release ${{ github.ref_name }}
generate_release_notes: true
draft: false
prerelease: true
# for triggering workflow "push-docker-image-release" - https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#triggering-a-workflow-from-a-workflow
token: ${{ secrets.ANYTYPE_PAT }}
files: |
./${{ github.event.repository.name }}-${{ steps.release-version.outputs.RELEASE_VERSION }}.${{ matrix.os }}-${{ matrix.arch }}.tgz

- name: Create release and upload assets deb and rpm | Linux
id: release_linux
uses: softprops/action-gh-release@v2
if: matrix.os == 'linux'
with:
name: Release ${{ github.ref_name }}
generate_release_notes: true
draft: false
prerelease: true
# for triggering workflow "push-docker-image-release" - https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#triggering-a-workflow-from-a-workflow
token: ${{ secrets.ANYTYPE_PAT }}
files: |
./${{ github.event.repository.name }}_${{ steps.release-version.outputs.RELEASE_VERSION }}_${{ matrix.arch }}.deb
./${{ github.event.repository.name }}-${{ steps.release-version.outputs.RELEASE_VERSION_RPM }}-1.${{ matrix.rpm_arch }}.rpm
# }}

- name: Get release info
id: release_info
uses: actions/github-script@v7
with:
script: |
const release_id = Number('${{ steps.release_windows.outputs.id || steps.release_unix.outputs.id || steps.release_linux.outputs.id }}');
const { data } = await github.rest.repos.getRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id
});
core.setOutput('body', data.body || '');
core.setOutput('html_url', data.html_url);
core.setOutput('tag_name', data.tag_name);


push-docker-image:
name: Build Docker image and push to registry
needs:
- build
runs-on: ubuntu-22.04
steps:
- name: Set deploy-platforms
run: |
if [ "${{ inputs.deploy-arm }}" = "true" ]; then
echo "DEPLOY_PLATFORMS=linux/amd64,linux/arm64" >> $GITHUB_ENV
else
echo "DEPLOY_PLATFORMS=linux/amd64" >> $GITHUB_ENV
fi

- name: release version only numbers
id: release-version
run: |
echo "${{ needs.build.outputs.tag_name }}" | sed 's|^[a-zA-Z]\+|RELEASE_VERSION=|' >> $GITHUB_OUTPUT

- name: Set env ARTIFACT_PREFIX
run: |
echo ARTIFACT_PREFIX=${{ github.event.repository.name }}_${{ steps.release-version.outputs.RELEASE_VERSION }} >> $GITHUB_ENV

- name: Download release asset amd64
uses: dsaltares/fetch-gh-release-asset@1.1.2
with:
version: tags/${{ needs.build.outputs.tag_name }}
file: ${{ env.ARTIFACT_PREFIX }}_amd64.deb
token: ${{ secrets.GITHUB_TOKEN }}

- name: Download release asset arm64
if: ${{ inputs.deploy-arm }}
uses: dsaltares/fetch-gh-release-asset@1.1.2
with:
version: tags/${{ needs.build.outputs.tag_name }}
file: ${{ env.ARTIFACT_PREFIX }}_arm64.deb
token: ${{ secrets.GITHUB_TOKEN }}

- name: Generate Dockerfile
run: |
cat <<EOF > Dockerfile
# syntax=docker/dockerfile:1
FROM ${{ inputs.dockerfile-image }}
LABEL org.opencontainers.image.source=${{ github.repositoryUrl }}
LABEL org.opencontainers.image.description=https://tech.anytype.io
LABEL org.opencontainers.image.licenses=MIT
ARG TARGETARCH
COPY ${{ env.ARTIFACT_PREFIX }}_\${TARGETARCH}.deb .
RUN apt-get install -y ./${{ env.ARTIFACT_PREFIX }}_\${TARGETARCH}.deb && rm -f ./${{ env.ARTIFACT_PREFIX }}_\${TARGETARCH}.deb
RUN ${{ inputs.dockerfile-run }}
RUN rm -rf /var/lib/apt/lists/*
EXPOSE 443
EXPOSE 8000
EXPOSE 8080
CMD ${{ inputs.dockerfile-cmd }}
EOF

- name: Debug
run: pwd; cat Dockerfile; ls -R

# push to registry
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Push to github registry
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
platforms: ${{ env.DEPLOY_PLATFORMS }}
push: true
tags: |
ghcr.io/${{ github.repository }}:latest
ghcr.io/${{ github.repository }}:${{ needs.build.outputs.tag_name }}
outputs: type=image,name=target,annotation-index.org.opencontainers.image.description=https://tech.anytype.io

- name: Login to Docker Hub
if: ${{ inputs.deploy-on-docker-hub }}
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Push to Docker Hub registry
if: ${{ inputs.deploy-on-docker-hub }}
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
platforms: ${{ env.DEPLOY_PLATFORMS }}
push: true
tags: |
docker.io/${{ github.repository }}:latest
docker.io/${{ github.repository }}:${{ needs.build.outputs.tag_name }}
outputs: type=image,name=target,annotation-index.org.opencontainers.image.description=https://tech.anytype.io


notify:
needs:
- build
- push-docker-image
if: ${{ always() }}
runs-on: ubuntu-latest
steps:
- name: Notify Slack (workflow result)
uses: ravsamhq/notify-slack-action@v2
with:
status: ${{ (contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')) && 'failure' || 'success' }}
notification_title: "${{ (contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')) && '❌' || 'βœ…' }} {workflow} {repo}"
message_format: |
*Release:* <${{ needs.build.outputs.html_url }}|${{ needs.build.outputs.tag_name || 'none' }}>
*Description:*
${{ needs.build.outputs.body || 'no changes, build skipped' }}
footer: "Linked Repo <{repo_url}|{repo}> | <{run_url}|View Workflow Run>"
env:
SLACK_WEBHOOK_URL: ${{ (contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')) && secrets.SLACK_WEBHOOK_URL_ALERTS || secrets.SLACK_WEBHOOK_URL_RELEASE_TRAIN }}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ need grant the repository access to the organization secret https://github.com/o
```
cat <<EOF > .github/workflows/secret-scanner.yml
---
name: Searching for secrets

on:
- push
- pull_request
Expand Down