Skip to content

auto-update

auto-update #572

Workflow file for this run

name: auto-update
on:
schedule:
- cron: "0 0 * * *"
push:
branches:
- feat/github-actions
- main
permissions:
id-token: write
contents: write
pull-requests: write
concurrency:
group: deploy-prod-stack
jobs:
auto-update:
runs-on: ubuntu-latest
env:
AWS_REGION: ap-northeast-1
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ env.AWS_REGION }}
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
- name: Install serverless
run: npm install -g serverless@^3
- name: Note docker image digest
id: docker-image-digest
run: |
docker pull public.ecr.aws/lambda/python:latest
SHA256_DIGEST=$(docker inspect public.ecr.aws/lambda/python:latest | jq -r '.[0].RepoDigests[0] | split(":") | .[1]' )
echo "SHA256_DIGEST=${SHA256_DIGEST}" >> $GITHUB_OUTPUT
- name: Note Chromium versions
id: chrome-versions
run: |
WHOLE_JSON=$(curl https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json)
CHANNEL="Stable"
REVISION=$(echo $WHOLE_JSON | jq -r '.channels.Stable.revision')
echo "REVISION=${REVISION}" >> $GITHUB_OUTPUT
CHROME_VERSION=$(echo $WHOLE_JSON | jq -r '.channels.Stable.version')
echo "CHROME_VERSION=${CHROME_VERSION}" >> $GITHUB_OUTPUT
MAJOR_VERSION=$(echo $WHOLE_JSON | jq -r '.channels.Stable.version | split(".") | .[0]')
echo "MAJOR_VERSION=${MAJOR_VERSION}" >> $GITHUB_OUTPUT
- name: Update Selenium
id: selenium-version
run: |
echo "SELENIUM_VERSION=$(curl -s https://pypi.org/pypi/selenium/json | jq -r .info.version)" >> $GITHUB_OUTPUT
- name: Update Dockerfile
run: |
SHA256_DIGEST=${{ steps.docker-image-digest.outputs.SHA256_DIGEST }}
CHROME_VERSION=${{ steps.chrome-versions.outputs.CHROME_VERSION }}
SELENIUM_VERSION=${{ steps.selenium-version.outputs.SELENIUM_VERSION }}
sed -r "s/public.ecr.aws\/lambda\/python[:@a-z0-9]+/public.ecr.aws\/lambda\/python\@sha256\:${SHA256_DIGEST}/g; s/chrome-for-testing-public\/[0-9.]+/chrome-for-testing-public\/${CHROME_VERSION}/g; s/selenium==[0-9\.]*/selenium==${SELENIUM_VERSION}/g" -i Dockerfile
- name: Deploy
run: sls deploy
- name: Note chrome version
id: chrome-version
run: |
CHROME_VERSION=$(docker run --rm --entrypoint '' serverless-docker-selenium-lambda-prod:img /opt/chrome/chrome --version | awk '{print $2}' | sed -e 's/^[[:space:]]*//')
echo "CHROME_VERSION=${CHROME_VERSION}" >> $GITHUB_OUTPUT
- name: Note python version
id: python-version
run: |
PYTHON_VERSION=$(docker run --rm --entrypoint '' serverless-docker-selenium-lambda-prod:img python -V | awk '{print $2}')
echo "PYTHON_VERSION=${PYTHON_VERSION}" >> $GITHUB_OUTPUT
- name: Invoke
id: invoke
run: sls invoke -f demo > /tmp/scraping-result.txt
- name: Clean up (ECR costs)
run: sls remove
- name: Archive result
uses: actions/upload-artifact@v3
if: ${{ !env.ACT }}
with:
name: scraping-result
path: /tmp/scraping-result.txt
- name: Test
run: cat /tmp/scraping-result.txt | grep -q "This domain is for use in illustrative examples in documents"
- name: Update README
run: |
CHROME_VERSION=${{ steps.chrome-versions.outputs.CHROME_VERSION }}
SELENIUM_VERSION=${{ steps.selenium-version.outputs.SELENIUM_VERSION }}
PYTHON_VERSION=${{ steps.python-version.outputs.PYTHON_VERSION }}
sed -r "s/- chromium [0-9.]+/- chromium ${CHROME_VERSION}/g; s/- chromedriver [0-9.]+/- chromedriver ${CHROME_VERSION}/g; s/- selenium [0-9.]+/- selenium ${SELENIUM_VERSION}/g; s/- Python [0-9.]+/- Python ${PYTHON_VERSION}/g" -i README.md
- name: Detect changes
id: detect-changes
run: |
DO_RELEASE="yes"
git --no-pager diff --name-only | grep -q "README.md" || DO_RELEASE="no"
git --no-pager diff --name-only | grep -q "Dockerfile" || DO_RELEASE="no"
echo "DO_RELEASE=${DO_RELEASE}" >> $GITHUB_OUTPUT
- name: Setup git config
run: |
# https://qiita.com/thaim/items/3d1a4d09ec4a7d8844ce
git config user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Release
if: ${{ steps.detect-changes.outputs.DO_RELEASE == 'yes' && !env.ACT }}
run: |
BRANCH=$(date +%Y-%m-%d-%H%M%S)
TITLE="Version Updates $(date)"
git checkout -b $BRANCH
git add Dockerfile README.md
echo "SHA256_DIGEST=${{ steps.docker-image-digest.outputs.SHA256_DIGEST }}" > /tmp/body-text.txt
echo "REVISION=${{ steps.chrome-versions.outputs.REVISION }}" >> /tmp/body-text.txt
echo "PYTHON_VERSION=${{ steps.python-version.outputs.PYTHON_VERSION }}" >> /tmp/body-text.txt
echo "SELENIUM_VERSION=${{ steps.selenium-version.outputs.SELENIUM_VERSION }}" >> /tmp/body-text.txt
echo -e "CHROME_VERSION=${{ steps.chrome-versions.outputs.CHROME_VERSION }}\n\n" >> /tmp/body-text.txt
git diff --staged >> /tmp/body-text.txt
git commit -m "${TITLE}"
git push --set-upstream origin $BRANCH
gh pr create --body-file /tmp/body-text.txt --title "PR:${TITLE}"
gh pr merge --delete-branch --merge
gh release create $BRANCH --notes-file /tmp/body-text.txt --title "${TITLE}"
env:
GH_TOKEN: ${{ github.token }}
- name: Publish image
if: ${{ steps.detect-changes.outputs.DO_RELEASE == 'yes' && !env.ACT }}
env:
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
run: |
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
PYTHON_VERSION=${{ steps.python-version.outputs.PYTHON_VERSION }}
SELENIUM_VERSION=${{ steps.selenium-version.outputs.SELENIUM_VERSION }}
CHROME_VERSION=${{ steps.chrome-versions.outputs.CHROME_VERSION }}
MAJOR_PYTHON_VERSION=$(echo $PYTHON_VERSION | cut -d "." -f 1)
MINOR_PYTHON_VERSION=$(echo $PYTHON_VERSION | cut -d "." -f 2)
docker image tag serverless-docker-selenium-lambda-prod:img umihico/aws-lambda-selenium-python:latest
docker image tag serverless-docker-selenium-lambda-prod:img umihico/aws-lambda-selenium-python:${MAJOR_PYTHON_VERSION}
docker image tag serverless-docker-selenium-lambda-prod:img umihico/aws-lambda-selenium-python:${MAJOR_PYTHON_VERSION}.${MINOR_PYTHON_VERSION}
docker image tag serverless-docker-selenium-lambda-prod:img umihico/aws-lambda-selenium-python:${PYTHON_VERSION}
docker image tag serverless-docker-selenium-lambda-prod:img umihico/aws-lambda-selenium-python:${PYTHON_VERSION}-selenium${SELENIUM_VERSION}
docker image tag serverless-docker-selenium-lambda-prod:img umihico/aws-lambda-selenium-python:${PYTHON_VERSION}-chrome${CHROME_VERSION}
docker image tag serverless-docker-selenium-lambda-prod:img umihico/aws-lambda-selenium-python:${PYTHON_VERSION}-selenium${SELENIUM_VERSION}-chrome${CHROME_VERSION}
docker image push --all-tags umihico/aws-lambda-selenium-python