Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyCTHsu committed Sep 19, 2024
1 parent 4dd912a commit 0c72d23
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 11 deletions.
9 changes: 9 additions & 0 deletions .github/filters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
gemfile:
- Gemfile
- Appraisals
- datadog.gemspec
- tasks/appraisal.rake
- .github/workflows/lock-dependency.yml
- lib/datadog/version.rb
- appraisal/**
- gemfiles/**
71 changes: 60 additions & 11 deletions .github/workflows/lock-dependency.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,73 @@
name: Lock Dependency

# This action cannot be skipped altogether because it is a mandatory status check.
# Instead we conditionally skip it at job level, instead of workflow level.
on:
workflow_dispatch:
inputs:
branch:
description: 'Branch to be lock dependency'
required: true
# Testing purpose, to be removed before merge.
# Execute on `push` and not `pull_request` because `pull_request`
# always compares if the `paths` have changed compared to the PR base.
# This is an issue because it means that all commits to the branch
# will trigger the gemfile update process, which is unnecessary and expensive.
#
# By executing on `push`, GitHub compares `paths` with the parent commit,
# meaning the gemfile update process will only execute on the exact commit
# that changes any of the `paths`.
#
# Because this process is slow and expensive, and we commit the gemfile changes back
# to the branch, we have an additional filter to only execute this action on branches
# attached to a PR.
#
# We could do the inverse: execute this action on `pull_request`, and additionally check
# if `paths` was changed compared to the parent commit, but this proved more complicated.
push:
branches:
- tonycthsu/automate-update-gemfiles

# Ensure obsolete job is cancelled if another commit is pushed to the same branch.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
# TODO: In order to fully automate this workflow for each PR,
# have a reliable way to precheck job to understand whether it need to be updated
debug: # Debugging job to check the concurrency environment
name: Debug concurrency environment
runs-on: ubuntu-latest
steps:
- run: echo ${{ github.workflow }}
- run: echo ${{ github.ref }}
pr:
name: Check pull request attached
runs-on: ubuntu-latest
outputs:
pr_found: ${{ steps.pr.outputs.pr_found }}
pr_base_ref: ${{ steps.pr.outputs.pr.base.ref }}
steps:
# Only execute if there's a PR attached to this branch.
# Because we execute on `push`, we have to double check here if this is part of a PR.
- uses: 8BitJonny/gh-get-current-pr@3.0.0
id: pr
with:
filterOutClosed: true # Don't trigger on commits with closed PRs, including merges into `master`.
- name: "Pull Request ${{ steps.pr.outputs.number }}"
if: steps.pr.outputs.pr_found == 'true'
run: |
echo "from ${{ fromJSON(steps.pr.outputs.pr).head.ref }}"
echo "to ${{ fromJSON(steps.pr.outputs.pr).base.ref }}"
dependency:
name: Check dependency changed
needs: pr
if: ${{ needs.pr.outputs.pr_found == 'true' }}
runs-on: ubuntu-latest
outputs:
changes: ${{ steps.changes.outputs.gemfile }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: changes
with:
base: ${{ github.ref_name }}
filters: .github/filters.yml
lock:
runs-on: ubuntu-latest
needs: dependency
if: ${{ needs.dependency.outputs.changes == 'true' }}
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -72,6 +119,7 @@ jobs:
path: gemfiles/${{ matrix.engine.name }}_${{ matrix.engine.version }}*

commit:
name: Commit changes
needs: lock
runs-on: ubuntu-latest
permissions:
Expand All @@ -85,7 +133,8 @@ jobs:
pattern: lock-dependency-${{ github.run_id }}-*
merge-multiple: true

- run: git diff --color
- name: debug
run: git diff --color

- uses: stefanzweifel/git-auto-commit-action@v5
with:
Expand Down

0 comments on commit 0c72d23

Please sign in to comment.