Skip to content

Scrape and Build

Scrape and Build #747

name: "Scrape and Build"
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * *"
jobs:
scrape:
runs-on: ubuntu-latest
outputs:
result: ${{ steps.scrapejob.outputs.result }}
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- run: npm ci
working-directory: scripts
- id: scrapejob
run: npm run scrape
working-directory: scripts
env:
GITHUB_TOKEN: ${{ github.token }}
build:
needs: scrape
runs-on: ubuntu-latest
strategy:
matrix:
job: ${{ fromJSON(needs.scrape.outputs.result) }}
permissions:
contents: write
issues: write
env:
SOURCE_OWNER: ${{ fromJSON(matrix.job).source.owner }}
SOURCE_REPOSITORY: ${{ fromJSON(matrix.job).source.repository }}
SOURCE_TAG: ${{ fromJSON(matrix.job).source.tag }}
IMAGE_REPOSITORY: ${{ fromJSON(matrix.job).image.repository }}
IMAGE_TAG: ${{ fromJSON(matrix.job).image.tag }}
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v3
with:
repository: ${{ env.SOURCE_OWNER }}/${{ env.SOURCE_REPOSITORY }}
ref: ${{ env.SOURCE_TAG }}
path: ${{ env.SOURCE_REPOSITORY }}
- uses: actions/checkout@v3
with:
path: stocker
- name: Build image
run: |
exec 2> >(tee -a /tmp/error.log >&2) > >(tee -a /tmp/out.log)
docker build \
--file stocker/repositories/${{ env.IMAGE_REPOSITORY }}/Dockerfile \
--tag ${{ vars.DOCKERHUB_USERNAME }}/${{ env.IMAGE_REPOSITORY }}:${{ env.IMAGE_TAG }} \
--build-arg SOURCE_OWNER=${{ env.SOURCE_OWNER }} \
--build-arg SOURCE_REPOSITORY=${{ env.SOURCE_REPOSITORY }} \
--build-arg SOURCE_TAG=${{ env.SOURCE_TAG }} \
--build-arg IMAGE_REPOSITORY=${{ env.IMAGE_REPOSITORY }} \
--build-arg IMAGE_TAG=${{ env.IMAGE_TAG }} \
${{ env.SOURCE_REPOSITORY }}
- name: Test image
env:
IMAGE: ${{ vars.DOCKERHUB_USERNAME }}/${{ env.IMAGE_REPOSITORY }}:${{ env.IMAGE_TAG }}
working-directory: stocker/repositories/${{ env.IMAGE_REPOSITORY }}
run: |
exec 2> >(tee -a /tmp/error.log >&2) > >(tee -a /tmp/out.log)
./test.bash
- uses: actions/setup-node@v3
with:
node-version: 18
- run: npm ci
working-directory: stocker/scripts
- run: npm run createDockerhubRepository
working-directory: stocker/scripts
env:
INPUT_USERNAME: ${{ vars.DOCKERHUB_USERNAME }}
INPUT_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
INPUT_REPOSITORY: ${{ env.IMAGE_REPOSITORY }}
- run: npm run updateDockerhubRepository
working-directory: stocker/scripts
env:
INPUT_USERNAME: ${{ vars.DOCKERHUB_USERNAME }}
INPUT_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
INPUT_REPOSITORY: ${{ env.IMAGE_REPOSITORY }}
INPUT_FULL_DESCRIPTION_PATH: ${{ env.SOURCE_REPOSITORY }}/README.md
- uses: docker/login-action@v1
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Push image
run: |
exec 2> >(tee -a /tmp/error.log >&2) > >(tee -a /tmp/out.log)
docker push ${{ vars.DOCKERHUB_USERNAME }}/${{ env.IMAGE_REPOSITORY }}:${{ env.IMAGE_TAG }}
- name: Create success history file
if: ${{ success() }}
working-directory: stocker
run: |
mkdir -p .history/${{ env.IMAGE_REPOSITORY }}
cat <<- EOF > .history/${{ env.IMAGE_REPOSITORY }}/${{ env.IMAGE_TAG }}
Successfully built and pushed stocker/${{ env.IMAGE_REPOSITORY }}:${{ env.IMAGE_TAG }}
EOF
- name: Create failure history file
if: ${{ failure() }}
working-directory: stocker
run: |
mkdir -p .history/${{ env.IMAGE_REPOSITORY }}
cat <<- EOF > .history/${{ env.IMAGE_REPOSITORY }}/${{ env.IMAGE_TAG }}
Failed to build stocker/${{ env.IMAGE_REPOSITORY }}:${{ env.IMAGE_TAG }}
---
EOF
- name: View failed job log
if: ${{ failure() }}
id: failure
run: |
set -Eeuo pipefail
echo "log=$(cat /tmp/error.log)" >> $GITHUB_OUTPUT
working-directory: stocker
- name: Append failed job log to history file
run: echo ${{ steps.failure.outputs.log }} >> .history/${{ env.IMAGE_REPOSITORY }}/${{ env.IMAGE_TAG }}
if: ${{ failure() }}
working-directory: stocker
- name: Update repository with history file
if: ${{ success() || failure() }}
working-directory: stocker
timeout-minutes: 5
run: |
set +e
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git add .history/${{ env.IMAGE_REPOSITORY }}/${{ env.IMAGE_TAG }}
git commit -m "Update history file for stocker/${{ env.IMAGE_REPOSITORY }}:${{ env.IMAGE_TAG }}"
git push
while [ $? -ne 0 ]; do
git pull --rebase
git push && break
sleep 5
done
- name: Create issue
if: ${{ failure() }}
uses: actions-ecosystem/action-create-issue@v1
with:
title: "Failed to build stocker/${{ env.IMAGE_REPOSITORY }}:${{ env.IMAGE_TAG }}"
body: |
The build of stocker/${{ env.IMAGE_REPOSITORY }}:${{ env.IMAGE_TAG }} failed.
```
${{ steps.failure.outputs.log }}
```
labels: "bug"
github_token: ${{ github.token }}