Skip to content

Commit

Permalink
Added Auto-Update workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Grutschus committed Dec 19, 2023
1 parent f566535 commit 4c88161
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 3 deletions.
116 changes: 116 additions & 0 deletions .github/workflows/auto-update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: Auto Update

on:
schedule:
- cron: "0 7 * * *"

jobs:
auto-update:
name: "Auto-Update Rewinged Docker Image"
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write

env:
JSONPATH_ALPINE: .jobs.docker-image-alpine.strategy.matrix.version
REMOTE_GITHUB_REPO: pdepend/pdepend

steps:
- name: Checkout
uses: actions/checkout@v3
with:
token: ${{ secrets.WORKFLOW_TOKEN }}

- name: Get lastest version from Github
uses: octokit/request-action@v2.x
id: pdepend_latest_release
with:
route: GET /repos/${{ env.REMOTE_GITHUB_REPO }}/releases/latest
env:
GITHUB_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}

- name: "Get OUR lastest version for Alpine"
id: get_alpine_latest_version
uses: mikefarah/yq@master
with:
cmd: yq '${{ env.JSONPATH_ALPINE }}.[-1].pdepend' '.github/workflows/docker.yml'

- name: Set Environment
run: |
echo '${{ steps.pdepend_latest_release.outputs.data }}' > latest_release.json
echo "PDEPEND_LATEST=$(echo '${{ fromJson(steps.pdepend_latest_release.outputs.data).tag_name }}')" >> $GITHUB_ENV
echo "PDEPEND_VERSION_MAJOR=$(echo '${{ fromJson(steps.pdepend_latest_release.outputs.data).tag_name }}' | cut -d '.' -f1)" >> $GITHUB_ENV
echo "PDEPEND_VERSION_MINOR=$(echo '${{ fromJson(steps.pdepend_latest_release.outputs.data).tag_name }}' | cut -d '.' -f1-2)" >> $GITHUB_ENV
echo "PDEPEND_VERSION_ALPINE=${{ steps.get_alpine_latest_version.outputs.result }}" >> $GITHUB_ENV
- name: Get Download URL
id: get_download_url
uses: mikefarah/yq@master
with:
cmd: yq -oy '.assets[] | select(.name == "pdepend.phar") | .browser_download_url' 'latest_release.json'

- name: Download PHAR
run: |
curl -v -L '${{ steps.get_download_url.outputs.result }}' -o 'pdepend.phar'
echo "PDEPEND_PHAR_HASH=$( sha256sum pdepend.phar | cut -d ' ' -f1 )" >> $GITHUB_ENV
rm -f latest_release.json
- run: |
echo Latest Version: $PDEPEND_LATEST
echo Major version: $PDEPEND_VERSION_MAJOR
echo Minor version: $PDEPEND_VERSION_MINOR
echo Our Alpine Version: $PDEPEND_VERSION_ALPINE
echo Download Hash PHAR: $PDEPEND_PHAR_HASH
- name: Handle version < 1
if: ${{ env.PDEPEND_VERSION_MAJOR == '0' }}
run: |
echo PDEPEND_VERSION_MAJOR="" >> $GITHUB_ENV
echo PDEPEND_VERSION_MINOR="" >> $GITHUB_ENV
- name: Fix Major versions Alpine
if: ${{ env.PDEPEND_LATEST != env.PDEPEND_VERSION_ALPINE }}
uses: mikefarah/yq@master
with:
cmd: |
yq -i 'with((${{ env.JSONPATH_ALPINE }}[] | select(.pdepend_major == "${{ env.PDEPEND_VERSION_MAJOR }}")); .pdepend_major = "")' .github/workflows/docker.yml
- name: Fix Minor versions Alpine
if: ${{ env.PDEPEND_LATEST != env.PDEPEND_VERSION_ALPINE }}
uses: mikefarah/yq@master
with:
cmd: |
yq -i 'with((${{ env.JSONPATH_ALPINE }}[] | select(.pdepend_minor == "${{ env.PDEPEND_VERSION_MINOR }}")); .pdepend_minor = "")' .github/workflows/docker.yml
- name: Fix Latest Alpine
if: ${{ env.PDEPEND_LATEST != env.PDEPEND_VERSION_ALPINE }}
uses: mikefarah/yq@master
with:
cmd: |
yq -i 'with((${{ env.JSONPATH_ALPINE }}[] | select(.latest == true)); .latest = false)' .github/workflows/docker.yml
- name: "Add new Version for Alpine"
if: ${{ env.PDEPEND_LATEST != env.PDEPEND_VERSION_ALPINE }}
uses: mikefarah/yq@master
with:
cmd: |
yq -i '${{ env.JSONPATH_ALPINE }} = ${{ env.JSONPATH_ALPINE }} + {"pdepend": "${{ env.PDEPEND_LATEST }}", "pdepend_major": "${{ env.PDEPEND_VERSION_MAJOR }}", "pdepend_minor": "${{ env.PDEPEND_VERSION_MINOR }}", "sha256": "${{ env.PDEPEND_PHAR_HASH }}", "latest": true}' .github/workflows/docker.yml
- name: Create Pull Request
if: ${{ env.PDEPEND_LATEST != env.PDEPEND_VERSION_ALPINE }}
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
git switch -c "update-${{ env.PDEPEND_LATEST }}"
git config --global user.name "github-actions"
git config --global user.email \
"41898282+github-actions[bot]@users.noreply.github.com"
git add .github/workflows/docker.yml
git commit --message "Version ${{ env.PDEPEND_LATEST }}"
git push --set-upstream origin "update-${{ env.PDEPEND_LATEST }}"
gh pr create --title "Version ${{ env.PDEPEND_LATEST }}" --body ''
6 changes: 3 additions & 3 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ on:
paths-ignore:
- "README.md"
- "LICENSE.md"
- ".editorconfig"
- ".github/workflows/auto-update.yml"
pull_request:
schedule:
- cron: "0 7 * * 1-4"

jobs:
docker-image-alpine:
strategy:
matrix:
version:
- pdepend: "2.15.1"
pdepend_minor: "2.15"
pdepend_major: "2"
pdepend_minor: "2.15"
sha256: "d14701de2c16ba2fdec40b6c73f8c6ba03a60c93b619493ce80a23d161a129d6"
latest: true

Expand Down

0 comments on commit 4c88161

Please sign in to comment.