92 lines
No EOL
3.1 KiB
YAML
92 lines
No EOL
3.1 KiB
YAML
name: Auto Build p2pool Node Docker Container
|
|
enable-email-notifications: true
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
schedule:
|
|
- cron: '12 */3 * * *'
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: dind
|
|
|
|
env:
|
|
PACKAGE: p2pool
|
|
DOCKER_REGISTRY: git.shork.ch
|
|
REGISTRY_USER: docker-images
|
|
COMMIT_AUTHOR_NAME: "forgejo-runner"
|
|
COMMIT_AUTHOR_EMAIL: "forgejo-runner@shork.ch"
|
|
COMMIT_MESSAGE: "Update build metadata"
|
|
GET_NEWEST_VERSION_CMD: "curl https://api.github.com/repos/SChernykh/p2pool/tags | jq -r .[0].name"
|
|
GIT_REPO_URL: "https://github.com/SChernykh/p2pool"
|
|
|
|
steps:
|
|
- name: Install dependencies
|
|
shell: sh
|
|
run: |
|
|
echo "Run because of ${{ github.event_name }}"
|
|
apk add --no-cache git nodejs npm bash sed curl jq
|
|
|
|
- uses: actions/checkout@v3
|
|
|
|
- name: Get latest package version
|
|
id: check
|
|
run: |
|
|
newest_version=$(eval "$GET_NEWEST_VERSION_CMD")
|
|
echo "NEWEST_VERSION=$newest_version" >> $GITHUB_ENV
|
|
echo "Newest version: $newest_version"
|
|
echo "Current version: $(cat .last_version)"
|
|
echo "Today number: $(( $(date +%s) / 86400 ))"
|
|
echo "Current number: $(cat .last_rebuild)"
|
|
|
|
|
|
- name: Determine if update is needed
|
|
run: |
|
|
last_version_file=".last_version"
|
|
last_rebuild_file=".last_rebuild"
|
|
|
|
last_version=$(cat $last_version_file 2>/dev/null || echo "none")
|
|
last_rebuild=$(cat $last_rebuild_file 2>/dev/null || echo 0)
|
|
|
|
current_day=$(( $(date +%s) / 86400 ))
|
|
|
|
update="false"
|
|
if [ ${{ github.event_name }} == "workflow_dispatch" ] || [ "$last_version" != "$NEWEST_VERSION" ] || [ $((current_day - last_rebuild)) -gt 14 ]; then
|
|
update="true"
|
|
fi
|
|
|
|
echo "UPDATE=$update" >> $GITHUB_ENV
|
|
|
|
|
|
- name: Start Docker daemon
|
|
if: env.UPDATE == 'true'
|
|
run: |
|
|
dockerd-entrypoint.sh &
|
|
for i in {1..10}; do
|
|
docker info && break
|
|
echo "Waiting for Docker daemon..."
|
|
sleep 3
|
|
done
|
|
docker info || { echo "Docker daemon failed to start."; exit 1; }
|
|
|
|
- name: Build and push Docker image
|
|
if: env.UPDATE == 'true'
|
|
run: |
|
|
git clone $GIT_REPO_URL ../$PACKAGE-build
|
|
cd ../$PACKAGE-build
|
|
git fetch --all --tags
|
|
git checkout tags/$NEWEST_VERSION
|
|
docker build --build-arg NPROC=1 -t $DOCKER_REGISTRY/$REGISTRY_USER/$PACKAGE:latest -t $DOCKER_REGISTRY/$REGISTRY_USER/$PACKAGE:$NEWEST_VERSION .
|
|
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login $DOCKER_REGISTRY -u $REGISTRY_USER --password-stdin
|
|
docker push --all-tags $DOCKER_REGISTRY/$REGISTRY_USER/$PACKAGE
|
|
|
|
- name: Commit updated metadata
|
|
if: env.UPDATE == 'true'
|
|
run: |
|
|
echo "$NEWEST_VERSION" > .last_version
|
|
echo $(( $(date +%s) / 86400 )) > .last_rebuild
|
|
git config user.name "$COMMIT_AUTHOR_NAME"
|
|
git config user.email "$COMMIT_AUTHOR_EMAIL"
|
|
git add .last_version .last_rebuild
|
|
git commit -m "$COMMIT_MESSAGE" || echo "No commit"
|
|
git push |