Run scheduled jobs #305
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: Run scheduled jobs | |
on: | |
schedule: | |
- cron: '0 0 * * *' # Runs daily at midnight | |
jobs: | |
update-kinto-admin: | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
shell: bash | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Get current version | |
id: current_rs_version | |
run: | | |
CURRENT_RS_VERSION=$(cat kinto-admin/VERSION) | |
echo "Current Version: $CURRENT_RS_VERSION" | |
echo "version=$CURRENT_RS_VERSION" >> $GITHUB_OUTPUT | |
- name: Get latest release version | |
id: latest_release_version | |
run: | | |
LATEST_RELEASE_VERSION=$(curl -s https://api.github.com/repos/Kinto/kinto-admin/releases/latest | jq -r .tag_name) | |
echo "Latest Version: $LATEST_RELEASE_VERSION" | |
echo "version=${LATEST_RELEASE_VERSION#v}" >> $GITHUB_OUTPUT | |
- name: Compare versions | |
id: compare_versions | |
env: | |
LATEST_RELEASE_VERSION: ${{ steps.latest_release_version.outputs.version }} | |
CURRENT_RS_VERSION: ${{ steps.current_rs_version.outputs.version }} | |
run: | | |
LATEST_VERSION=$(npx --yes semver "$CURRENT_RS_VERSION" "$LATEST_RELEASE_VERSION" | tail -n 1) | |
if [ "$LATEST_VERSION" != "$CURRENT_RS_VERSION" ]; then | |
echo "Kinto Admin update ready" | |
echo "update_needed=true" >> $GITHUB_OUTPUT | |
else | |
echo "Kinto Admin up to date" | |
echo "update_needed=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Configure git | |
if: ${{ steps.compare_versions.outputs.update_needed == 'true' }} | |
# https://github.com/orgs/community/discussions/26560 | |
run: | | |
git config user.name github-actions[bot] | |
git config user.email 41898282+github-actions[bot]@users.noreply.github.com | |
- name: Create branch | |
id: create_branch | |
if: ${{ steps.compare_versions.outputs.update_needed == 'true' }} | |
env: | |
BRANCH_NAME: updates/kinto-admin-${{ steps.latest_release_version.outputs.version }} | |
LATEST_RELEASE: ${{ steps.latest_release_version.outputs.version }} | |
run: | | |
git fetch origin --no-tags --quiet 'refs/heads/updates/*:refs/remotes/origin/updates/*' | |
if [ "$(git rev-parse --quiet --verify origin/$BRANCH_NAME)" ]; then | |
echo "Branch $BRANCH_NAME already exists on origin." | |
echo "pr_needed=false" >> $GITHUB_OUTPUT | |
else | |
git checkout -b "$BRANCH_NAME" | |
git push origin $BRANCH_NAME | |
echo "pr_needed=true" >> $GITHUB_OUTPUT | |
fi | |
# making an API request so the commit is signed | |
- name: Commit change | |
if: ${{ steps.compare_versions.outputs.update_needed == 'true' && steps.create_branch.outputs.pr_needed == 'true'}} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
BRANCH_NAME: updates/kinto-admin-${{ steps.latest_release_version.outputs.version }} | |
LATEST_RELEASE: ${{ steps.latest_release_version.outputs.version }} | |
run: | | |
echo "$LATEST_RELEASE" > kinto-admin/VERSION | |
SHA=$(git rev-parse $BRANCH_NAME:kinto-admin/VERSION) | |
CONTENT=$(base64 -i kinto-admin/VERSION) | |
gh api --method PUT /repos/:owner/:repo/contents/kinto-admin/VERSION \ | |
--field message="Update Kinto Admin to $LATEST_RELEASE" \ | |
--field content="$CONTENT" \ | |
--field encoding="base64" \ | |
--field branch="$BRANCH_NAME" \ | |
--field sha="$SHA" | |
- name: Create pull request | |
if: ${{ steps.compare_versions.outputs.update_needed == 'true' && steps.create_branch.outputs.pr_needed == 'true'}} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
BRANCH_NAME: updates/kinto-admin-${{ steps.latest_release_version.outputs.version }} | |
run: | | |
PR_REF=$(gh pr create \ | |
--title "Update Kinto Admin version to ${{ steps.latest_release_version.outputs.version }}" \ | |
--body "Updating kinto-admin to latest release" \ | |
--base "main" \ | |
--head "$BRANCH_NAME" \ | |
--label "dependencies") | |
gh pr merge --auto --squash $PR_REF |