Verify latest commit in official implementation #154
This file contains hidden or 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: Verify latest commit in official implementation | |
| on: | |
| pull_request: | |
| branches: [ "master" ] | |
| schedule: | |
| - cron: "15 3 * * *" #every day, 03:15 UTC | |
| jobs: | |
| verify-official-commit: | |
| runs-on: ubuntu-latest | |
| env: | |
| GIT_URL: "https://github.com/material-foundation/material-color-utilities.git" | |
| GIT_DIR_NAME: "material-color-utilities" | |
| GIT_BRANCH: "main" | |
| JAVA_IMPL_PATH: "java" | |
| EXPECTED_COMMIT: 4578d0a1 | |
| steps: | |
| - name: Get the latest commit hash | |
| id: latest_official | |
| run: | | |
| git clone ${{ env.GIT_URL }} ${{ env.GIT_DIR_NAME }} \ | |
| --branch ${{ env.GIT_BRANCH }} | |
| cd ${{ env.GIT_DIR_NAME }} | |
| echo "Latest official commit: $(git rev-parse --short=8 --verify HEAD)" | |
| echo "commit_hash=$(git rev-parse --short=8 --verify HEAD)" >> $GITHUB_OUTPUT | |
| - name: Compare to expected commit hash | |
| id: compare_commits | |
| run: | | |
| echo "Expected: ${{ env.EXPECTED_COMMIT }}" | |
| echo "Got: ${{ steps.latest_official.outputs.commit_hash }}" | |
| if [ "${{ steps.latest_official.outputs.commit_hash }}" = "${{ env.EXPECTED_COMMIT }}" ]; then | |
| echo "Commit hashes match." | |
| echo "status=match" >> $GITHUB_OUTPUT | |
| else | |
| echo "Commit hashes do not match." | |
| echo "status=no_match" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Verify no changes to reference java implementation | |
| if: steps.compare_commits.outputs.status != 'match' | |
| run: | | |
| cd ${{ env.GIT_DIR_NAME }} | |
| if ! git diff --exit-code ${{ env.EXPECTED_COMMIT }} HEAD -- ${{ env.JAVA_IMPL_PATH }}; then | |
| echo "Error: Changes detected in "${{ env.JAVA_IMPL_PATH }}" compared to expected commit hash "${{ env.EXPECTED_COMMIT }}"." | |
| echo "Regenerate test cases based on latest official commit (${{ steps.latest_official.outputs.commit_hash }}) and update this workflow file to acknowledge the updated official implementation." | |
| exit 1 | |
| else | |
| echo "No changes detected." | |
| fi |