cron #1204
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: cron | |
on: | |
push: | |
schedule: | |
- cron: '0 0 * * *' | |
workflow_dispatch: | |
jobs: | |
validate: | |
runs-on: ubuntu-latest | |
outputs: | |
version_name: ${{ steps.set-version-name.outputs.version_name }} | |
is_new_version: ${{ steps.compare-versions.outputs.is_new_version }} | |
publish_version: ${{ steps.set-publish-version.outputs.publish_version }} | |
steps: | |
- name: Install depepndencies | |
run: sudo apt-get install -y curl jq | |
- name: Request current GitHub Synapse Package version | |
run: echo 'SYNAPSE_VERSION='$(curl -SsL https://api.github.com/repos/element-hq/synapse/releases | jq -r '.[].tag_name' | head -n 1) >> $GITHUB_ENV | |
- name: Request current Docker Hub Package version | |
run: echo 'DOCKER_VERSION='$(curl -sSL https://registry.hub.docker.com/v2/repositories/dotwee/matrix-synapse-s3/tags | jq -r '."results"[]["name"] | select(.=="'${{ env.SYNAPSE_VERSION }}'")') >> $GITHUB_ENV | |
- name: Overwrite versions if manually dispatched event | |
if: ${{ github.event.inputs.version_name != '' }} | |
run: | | |
echo 'SYNAPSE_VERSION=${{ github.event.inputs.version_name }}' >> $GITHUB_ENV | |
echo 'DOCKER_VERSION=""' >> $GITHUB_ENV | |
- name: Validate version-name is in format vXX.XX.XX | |
uses: actions-ecosystem/action-regex-match@v2 | |
id: validate-version-name | |
with: | |
text: ${{ env.SYNAPSE_VERSION }} | |
regex: '^v\d+\.\d+\.\d+(?:rc\d+(?:\.\d)*)?$' | |
flags: gm | |
- name: Set & echo version name output | |
if: ${{ steps.validate-version-name.outputs.match == '' }} | |
run: | | |
echo "::error title=Invalid version_name format::The value ${{ env.SYNAPSE_VERSION }} is not a valid version_name value" | |
return -1 | |
- name: Set & echo version name output | |
id: set-version-name | |
run: | | |
echo "SYNAPSE_VERSION=${{ env.SYNAPSE_VERSION }} DOCKER_VERSION=${{ env.DOCKER_VERSION }}" | |
echo "version_name=${{ env.SYNAPSE_VERSION }}" >> $GITHUB_OUTPUT | |
- name: Compare versions | |
id: compare-versions | |
run: echo "is_new_version=${{ env.SYNAPSE_VERSION != env.DOCKER_VERSION }}" >> $GITHUB_OUTPUT | |
- name: Set publish to false if manually triggered | |
id: set-publish-version | |
run: echo "publish_version=${{ github.event.inputs.version_name == '' }}" >> $GITHUB_OUTPUT | |
- name: Echo outputs | |
run: echo "version_name=${{ steps.set-version-name.outputs.version_name }} is_new_version=${{ steps.compare-versions.outputs.is_new_version }} publish_version=${{ steps.set-publish-version.outputs.publish_version }}" | |
release: | |
runs-on: ubuntu-latest | |
needs: validate | |
if: ${{ needs.validate.outputs.is_new_version == 'true' }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Cache Docker layers | |
uses: actions/cache@v4 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_REGISTRY_USERNAME }} | |
password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }} | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ secrets.GH_REGISTRY_USERNAME }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
dotwee/matrix-synapse-s3 | |
ghcr.io/dotwee/matrix-synapse-s3 | |
flavor: | | |
latest=${{ !(contains(needs.validate.outputs.version_name, 'rc')) }} | |
tags: | | |
type=raw,value=${{ needs.validate.outputs.version_name }} | |
type=raw,enable=${{ !(contains(needs.validate.outputs.version_name, 'rc')) }},value=stable | |
type=semver,pattern={{raw}},value=${{ needs.validate.outputs.version_name }} | |
labels: | | |
maintainer=Lukas Wolfsteiner <[email protected]> | |
org.opencontainers.image.title=matrix-synapse-s3 | |
org.opencontainers.image.source="https://github.com/${{ github.repository }}" | |
- name: Build and push docker image with version tag | |
uses: docker/build-push-action@v6 | |
id: docker-build | |
with: | |
platforms: linux/amd64,linux/arm64 | |
build-args: | | |
SYNAPSE_VERSION=${{ needs.validate.outputs.version_name }} | |
SYNAPSE_S3_STORAGE_PROVIDER_COMMIT=main | |
push: ${{ needs.validate.outputs.publish_version == 'true' }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
- name: Update Docker Hub repository description | |
uses: peter-evans/dockerhub-description@v4 | |
if: ${{ needs.validate.outputs.publish_version == 'true' }} | |
with: | |
username: ${{ secrets.DOCKER_REGISTRY_USERNAME }} | |
password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }} | |
repository: dotwee/matrix-synapse-s3 | |
- name: Create a GitHub repository release tag | |
uses: "marvinpinto/action-automatic-releases@latest" | |
if: ${{ needs.validate.outputs.publish_version == 'true' }} | |
with: | |
repo_token: "${{ secrets.GITHUB_TOKEN }}" | |
title: ${{ needs.validate.outputs.version_name }} | |
prerelease: ${{ contains(needs.validate.outputs.version_name, 'rc') }} | |
automatic_release_tag: ${{ needs.validate.outputs.version_name }} |