Auto updates #3765
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: Auto updates | |
# Run every 3 hours or manually | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "0 */3 * * *" | |
jobs: | |
deploy: | |
env: | |
GH_TOKEN: ${{ github.token }} | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: 3.x | |
- name: Install Poetry | |
run: | | |
pip install -U pip | |
pip install poetry | |
poetry config virtualenvs.create false | |
poetry install --with dev --without docs | |
# Get the latest release tag for each repo | |
- run: echo GOVUK_FRONTEND_VERSION=$(make get-latest-release-tag REPO=alphagov/govuk-frontend) >> $GITHUB_ENV | |
- run: echo GOVUK_FRONTEND_JINJA_VERSION=$(make get-latest-release-tag REPO=LandRegistry/govuk-frontend-jinja) >> $GITHUB_ENV | |
- run: echo GOVUK_FRONTEND_DJANGO_BRANCH_NAME=updates__$(echo ${{ env.GOVUK_FRONTEND_VERSION }} | sed 's/\./_/g')__$(echo ${{ env.GOVUK_FRONTEND_JINJA_VERSION }} | sed 's/\./_/g') >> $GITHUB_ENV | |
- name: Git fetch all | |
run: git fetch --all | |
# Check if the branch already exists | |
- name: Check if branch "origin/${{ env.GOVUK_FRONTEND_DJANGO_BRANCH_NAME }}" exists (not using git rev-parse) | |
run: | | |
if git ls-remote --heads origin ${{ env.GOVUK_FRONTEND_DJANGO_BRANCH_NAME }} | grep -q ${{ env.GOVUK_FRONTEND_DJANGO_BRANCH_NAME }}; then | |
echo "Branch origin/${{ env.GOVUK_FRONTEND_DJANGO_BRANCH_NAME }} already exists" | |
echo GOVUK_FRONTEND_DJANGO_SKIP_GENERATION=True >> $GITHUB_ENV | |
fi | |
# If there was a PR opened already, exit | |
- name: Check if PR exists | |
run: | | |
if gh pr list --state all --base main --head ${{ env.GOVUK_FRONTEND_DJANGO_BRANCH_NAME }} | grep -q ${{ env.GOVUK_FRONTEND_DJANGO_BRANCH_NAME }}; then | |
echo "PR for ${{ env.GOVUK_FRONTEND_DJANGO_BRANCH_NAME }} already exists" | |
echo GOVUK_FRONTEND_DJANGO_SKIP_GENERATION=True >> $GITHUB_ENV | |
fi | |
# Create a new branch with the GOVUK_FRONTEND_DJANGO_BRANCH_NAME | |
- name: Create new branch | |
if: ${{ env.GOVUK_FRONTEND_DJANGO_SKIP_GENERATION != 'True' }} | |
run: git checkout -b ${{ env.GOVUK_FRONTEND_DJANGO_BRANCH_NAME }} | |
- name: Upgrade components | |
if: ${{ env.GOVUK_FRONTEND_DJANGO_SKIP_GENERATION != 'True' }} | |
run: make upgrade-components GOVUK_FRONTEND_VERSION=${{ env.GOVUK_FRONTEND_VERSION }} GOVUK_FRONTEND_JINJA_VERSION=${{ env.GOVUK_FRONTEND_JINJA_VERSION }} | |
# If there were no changes, quit the job | |
- name: Check for changes | |
if: ${{ env.GOVUK_FRONTEND_DJANGO_SKIP_GENERATION != 'True' }} | |
run: | | |
if [[ -z $(git status --porcelain) ]]; then | |
echo "No changes to commit" | |
exit 78 | |
fi | |
- name: Commit changes | |
if: ${{ env.GOVUK_FRONTEND_DJANGO_SKIP_GENERATION != 'True' }} | |
run: | | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git config --global user.name "github-actions[bot]" | |
git add . | |
git commit -m "Updates" | |
git push --set-upstream origin ${{ env.GOVUK_FRONTEND_DJANGO_BRANCH_NAME }} | |
- name: Create pull request | |
if: ${{ env.GOVUK_FRONTEND_DJANGO_SKIP_GENERATION != 'True' }} | |
run: gh pr create -B main -H ${{ env.GOVUK_FRONTEND_DJANGO_BRANCH_NAME }} --title 'Updates for GOV.UK Frontend ${{ env.GOVUK_FRONTEND_VERSION }} and GOV.UK Frontend Jinja ${{ env.GOVUK_FRONTEND_JINJA_VERSION }}' --body 'Created by Github action' |