Sync Tags from openim-server and chat to openim-docker #168
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: Sync Tags from openim-server and chat to openim-docker | |
on: | |
schedule: | |
- cron: '0 0 * * *' # Runs at 00:00 every day | |
workflow_dispatch: # Also allows manual triggering | |
push: | |
branches: | |
- main | |
jobs: | |
sync-tags: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout openim-docker repo | |
uses: actions/checkout@v2 | |
with: | |
repository: 'openimsdk/openim-docker' | |
token: ${{ secrets.BOT_GITHUB_TOKEN }} | |
- name: Set up Docker and Docker Compose | |
uses: docker/setup-buildx-action@v1 | |
- name: Install dependencies | |
run: sudo apt-get update && sudo apt-get install -y jq curl | |
- name: Fetch the latest tag of openim-server | |
id: server-tag | |
run: echo "SERVER_TAG=$(curl -s https://api.github.com/repos/openimsdk/open-im-server/tags | jq -r '.[0].name')" >> $GITHUB_ENV | |
- name: Fetch the latest tag of chat | |
id: chat-tag | |
run: echo "CHAT_TAG=$(curl -s https://api.github.com/repos/openimsdk/chat/tags | jq -r '.[0].name')" >> $GITHUB_ENV | |
- name: Update .env.example with the latest tags | |
run: | | |
sed -i "s/SERVER_IMAGE_VERSION=.*/SERVER_IMAGE_VERSION=${SERVER_TAG}/" .env.example | |
sed -i "s/CHAT_IMAGE_VERSION=.*/CHAT_IMAGE_VERSION=${CHAT_TAG}/" .env.example | |
- name: Commit and Push Changes | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "kubbot" | |
git add .env.example | |
git commit -m "Update server and chat image versions to ${SERVER_TAG} and ${CHAT_TAG}" || echo "No changes to commit" | |
# git push | |
- name: Check if tag exists | |
id: check-tag | |
run: | | |
if git ls-remote --tags origin | grep "${SERVER_TAG}-${CHAT_TAG}"; then | |
echo "Tag exists, skipping creation and push." | |
echo "TAG_EXISTS=true" >> $GITHUB_ENV | |
else | |
echo "TAG_EXISTS=false" >> $GITHUB_ENV | |
fi | |
- name: Create and Push New Tag | |
if: env.TAG_EXISTS == 'false' | |
run: | | |
git tag "${SERVER_TAG}-${CHAT_TAG}" | |
git push origin "${SERVER_TAG}-${CHAT_TAG}" |