Skip to content

Commit

Permalink
Simplify auto updates (#913)
Browse files Browse the repository at this point in the history
  • Loading branch information
devpow112 authored Dec 20, 2024
1 parent 98aa14a commit daa009e
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 53 deletions.
51 changes: 27 additions & 24 deletions .github/workflows/update-license.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,54 +14,57 @@ jobs:
name: Update License
runs-on: ubuntu-latest
timeout-minutes: 5
env:
REGEX: ^(Copyright \(c\) )[0-9]{4}( Devon Powell)$
strategy:
matrix:
branch:
- main
- release/jammy
- release/focal
steps:
- name: Checkout
uses: actions/[email protected]
- name: Determine info
shell: bash
id: info
run: |
OLD_YEAR=$(grep -oEi "$REGEX" LICENSE | grep -oEi '[0-9]{4}')
NEW_YEAR=$(date +%Y)
UPDATE_TITLE="Bump LICENSE year from $OLD_YEAR to $NEW_YEAR"
UPDATE_BODY="$UPDATE_TITLE."
echo "license-year=$NEW_YEAR" >> $GITHUB_OUTPUT
echo "update-title=$UPDATE_TITLE" >> $GITHUB_OUTPUT
echo "update-body=$UPDATE_BODY" >> $GITHUB_OUTPUT
- name: Update LICENSE
run: sed -i -E "s/$REGEX/\1$LICENSE_YEAR\2/" LICENSE
env:
LICENSE_YEAR: ${{steps.info.outputs.license-year}}
with:
ref: ${{matrix.branch}}
- name: Generate app token
id: app-token
uses: actions/[email protected]
with:
app-id: ${{secrets.GH_APP_ID}}
private-key: ${{secrets.GH_APP_PRIVATE_KEY}}
- name: Generate user info
id: user-info
- name: Determine info
shell: bash
id: info
run: |
REGEX='^(Copyright \(c\) )[0-9]{4}( Devon Powell)$'
OLD_YEAR=$(grep -oEi "$REGEX" LICENSE | grep -oEi '[0-9]{4}')
NEW_YEAR=$(date +%Y)
UPDATE_TITLE="Bump \`LICENSE\` year from $OLD_YEAR to $NEW_YEAR"
USER_NAME="$GH_APP_SLUG[bot]"
USER_ID=$(gh api "/users/$USER_NAME" --jq .id)
USER_EMAIL="[email protected]"
echo "id=$USER_ID" >> $GITHUB_OUTPUT
echo "name=$USER_NAME" >> $GITHUB_OUTPUT
echo "[email protected]" >> $GITHUB_OUTPUT
echo "replace-regex=$REGEX" >> $GITHUB_OUTPUT
echo "license-year=$NEW_YEAR" >> $GITHUB_OUTPUT
echo "update-title=$UPDATE_TITLE" >> $GITHUB_OUTPUT
echo "update-body=$UPDATE_TITLE." >> $GITHUB_OUTPUT
echo "commit-author=$USER_NAME <$USER_EMAIL>" >> $GITHUB_OUTPUT
env:
GH_APP_SLUG: ${{steps.app-token.outputs.app-slug}}
GH_TOKEN: ${{steps.app-token.outputs.token}}
- name: Update LICENSE
run: sed -i -E "s/$REPLACE_REGEX/\1$LICENSE_YEAR\2/" LICENSE
env:
LICENSE_YEAR: ${{steps.info.outputs.license-year}}
REPLACE_REGEX: ${{steps.info.outputs.replace-regex}}
- name: Handle changes
uses: peter-evans/[email protected]
id: changes
with:
token: ${{steps.app-token.outputs.token}}
commit-message: ${{steps.info.outputs.update-title}}
author: ${{steps.user-info.outputs.commit-author}}
committer: ${{steps.user-info.outputs.commit-author}}
author: ${{steps.info.outputs.commit-author}}
committer: ${{steps.info.outputs.commit-author}}
add-paths: LICENSE
base: ${{matrix.branch}}
branch: auto/update-license
delete-branch: true
title: ${{steps.info.outputs.update-title}}
Expand Down
62 changes: 33 additions & 29 deletions .github/workflows/update-s6-overlay.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,68 +14,72 @@ jobs:
name: Update S6 Overlay
runs-on: ubuntu-latest
timeout-minutes: 5
env:
REGEX: ^(ARG S6_OVERLAY_VERSION=)[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+(\-[0-9])?$
strategy:
matrix:
branch:
- main
- release/jammy
- release/focal
steps:
- name: Checkout
uses: actions/[email protected]
with:
ref: ${{matrix.branch}}
- name: Generate app token
id: app-token
uses: actions/[email protected]
with:
app-id: ${{secrets.GH_APP_ID}}
private-key: ${{secrets.GH_APP_PRIVATE_KEY}}
- name: Determine info
shell: bash
id: info
run: |
REGEX="^(ARG S6_OVERLAY_VERSION=)([0-9]+\.){3}[0-9]+(\-[0-9]+)?$"
OLD_VERSION=$(
grep -oEi "$REGEX" Dockerfile |
grep -oEi '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+(\-[0-9])?$'
grep -oEi '([0-9]+\.){3}[0-9]+(\-[0-9]+)?$'
)
API=https://api.github.com/repos/just-containers/s6-overlay/releases
RELEASES=https://github.com/just-containers/s6-overlay/releases
NEW_VERSION=$(curl -sSf "$API/latest" | jq -r .tag_name)
NEW_VERSION=${NEW_VERSION#'v'}
BUMP='Bump s6 overlay from'
UPDATE_TITLE="$BUMP $OLD_VERSION to $NEW_VERSION"
UPDATE_BODY="$BUMP"
UPDATE_TITLE="Bump s6 overlay from $OLD_VERSION to $NEW_VERSION"
UPDATE_BODY="Bump s6 overlay from"
UPDATE_BODY="$UPDATE_BODY [$OLD_VERSION]($RELEASES/v$OLD_VERSION)"
UPDATE_BODY="$UPDATE_BODY to [$NEW_VERSION]($RELEASES/v$NEW_VERSION)."
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "update-title=$UPDATE_TITLE" >> $GITHUB_OUTPUT
echo "update-body=$UPDATE_BODY" >> $GITHUB_OUTPUT
- name: Update Dockerfile
run: sed -i -E "s/$REGEX/\1$VERSION\2/" Dockerfile
env:
VERSION: ${{steps.info.outputs.version}}
- name: Generate app token
id: app-token
uses: actions/[email protected]
with:
app-id: ${{secrets.GH_APP_ID}}
private-key: ${{secrets.GH_APP_PRIVATE_KEY}}
- name: Generate user info
id: user-info
run: |
USER_NAME="$GH_APP_SLUG[bot]"
USER_ID=$(gh api "/users/$USER_NAME" --jq .id)
USER_EMAIL="[email protected]"
echo "id=$USER_ID" >> $GITHUB_OUTPUT
echo "name=$USER_NAME" >> $GITHUB_OUTPUT
echo "[email protected]" >> $GITHUB_OUTPUT
echo "commit-author=$USER_NAME <$USER_EMAIL>" >> $GITHUB_OUTPUT
echo "replace-regex=$REGEX" >> $GITHUB_OUTPUT
echo "s6-overlay-version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "update-title=$UPDATE_TITLE" >> $GITHUB_OUTPUT
echo "update-body=$UPDATE_BODY" >> $GITHUB_OUTPUT
env:
GH_APP_SLUG: ${{steps.app-token.outputs.app-slug}}
GH_TOKEN: ${{steps.app-token.outputs.token}}
- name: Update Dockerfile
run: sed -i -E "s/$REPLACE_REGEX/\1$S6_OVERLAY_VERSION/" Dockerfile
env:
S6_OVERLAY_VERSION: ${{steps.info.outputs.s6-overlay-version}}
REPLACE_REGEX: ${{steps.info.outputs.replace-regex}}
- name: Handle changes
uses: peter-evans/[email protected]
id: changes
with:
token: ${{steps.app-token.outputs.token}}
commit-message: ${{steps.info.outputs.update-title}}
author: ${{steps.user-info.outputs.commit-author}}
committer: ${{steps.user-info.outputs.commit-author}}
author: ${{steps.info.outputs.commit-author}}
committer: ${{steps.info.outputs.commit-author}}
add-paths: Dockerfile
base: ${{matrix.branch}}
branch: auto/update-s6-overlay
delete-branch: true
title: ${{steps.info.outputs.update-title}}
body: ${{steps.info.outputs.update-body}}
labels: auto,dependencies
labels: |
dependencies
auto
- name: Enable auto-merge
if: steps.changes.outputs.pull-request-operation == 'created'
run: gh pr merge --auto --squash "$PULL_REQUEST_URL"
Expand Down

0 comments on commit daa009e

Please sign in to comment.