Docker Repository Update #491
This file contains hidden or 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: Docker Repository Update | |
| on: | |
| push: | |
| branches: | |
| - master | |
| schedule: | |
| - cron: '0 5 * * 0-4' # 5 AM UTC, Sunday through Thursday | |
| pull_request: | |
| types: [ labeled ] | |
| jobs: | |
| update_docker_repo_info: | |
| if: ${{ github.event_name == 'pull_request' && github.event.label.name == 'test-dockers-update' || github.event_name == 'schedule' }} | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.CONTENT_BOT_GITHUB_TOKEN }} | |
| - name: Set up Python environment | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.9' | |
| - name: Set up pipenv | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install pipenv | |
| - name: Install dependencies | |
| run: pipenv install | |
| - name: Run update-docker-repo-info script | |
| env: | |
| SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }} | |
| SLACK_CHANNEL: ${{ secrets.SLACK_CHANNEL }} | |
| SLACK_TEST_CHANNEL: ${{ secrets.SLACK_TEST_CHANNEL }} | |
| DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }} | |
| DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} | |
| run: | | |
| if [[ "${{ github.event.label.name }}" == "test-dockers-update" ]]; then | |
| CHANNEL="$SLACK_TEST_CHANNEL" | |
| else | |
| CHANNEL="$SLACK_CHANNEL" | |
| fi | |
| pipenv run ./update-docker-repo-info.py --slack-token "$SLACK_TOKEN" --slack-channel "$CHANNEL" --dockerhub-user "$DOCKERHUB_USER" --dockerhub-password "$DOCKERHUB_PASSWORD" | |
| - name: Configure Git for commit | |
| run: | | |
| git config --global user.email "content-bot@users.noreply.github.com" | |
| git config --global user.name "content-bot" | |
| - name: Check for changes | |
| id: git_status | |
| run: | | |
| EVENT_NAME="${{ github.event_name }}" | |
| if [ "$EVENT_NAME" == "pull_request" ]; then | |
| git fetch | |
| git switch $GITHUB_HEAD_REF | |
| git pull | |
| fi | |
| git status --short > git_changes.txt | |
| cat git_changes.txt | |
| if [ -s git_changes.txt ]; then | |
| echo "git_changes=true" >> $GITHUB_ENV | |
| else | |
| echo "git_changes=false" >> $GITHUB_ENV | |
| fi | |
| - name: Upload artifacts (if changes) | |
| if: env.git_changes == 'true' | |
| run: | | |
| mkdir -p artifacts | |
| cat git_changes.txt | awk '$1 != "D" {print $2}' | sed 's:/*$::' | xargs -I {} cp -rf {} artifacts/. || echo "cp failed for some reason. continue..." | |
| - name: Commit and push changes | |
| if: env.git_changes == 'true' | |
| run: | | |
| git add . | |
| git commit -m "$(date): auto repo info update [skip ci]" | |
| git push | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Print completion message | |
| run: echo "Docker repository update complete." |