Test PR #538
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: Fuzzy CI | |
on: | |
# push: | |
# branches: [ fuzzy-ci-artefacts-approach ] | |
pull_request: | |
branches: [ fuzzy-ci-artefacts-approach ] | |
types: [ opened, synchronize, reopened, unlabeled, labeled ] | |
env: | |
LABEL_NAME: "fuzzy-diff-looks-good" | |
jobs: | |
# download_curl_api_url: | |
# runs-on: ubuntu-latest | |
# permissions: write-all | |
# # Both with and without permissions, I get a 401 | |
# steps: | |
# - name: Run curl | |
# run: | | |
# curl -LOs -H "Authorization: Bearer ${{ secrets.FUZZY_CI_TOKEN }}" https://api.github.com/repos/pitag-ha/merlin/actions/artifacts/1043780208/zip -D headers.txt | |
# - name: Print return headers | |
# run: cat headers.txt | |
# - name: Ls | |
# run: lspi_url: | |
# runs-on: ubuntu-latest | |
# permissions: write-all | |
# # Both with and without permissions, I get a 401 | |
# steps: | |
# - name: Run curl | |
# run: | | |
# curl -LOs -H "Authorization: Bearer ${{ secrets.FUZZY_CI_TOKEN }}" https://api.github.com/repos/pitag-ha/merlin/actions/artifacts/1043780208/zip -D headers.txt | |
# - name: Print return headers | |
# run: cat headers.txt | |
# - name: Ls | |
# run: ls | |
# - name: Try to unzip | |
# run: unzip zip || cat zip | |
# - name: ls | |
# run: ls | |
# - name: Try to unzip | |
# run: unzip zip || cat zip | |
# - name: ls | |
# run: ls | |
artifact_names: | |
runs-on: ubuntu-20.04 | |
name: Create persistant artifact names | |
outputs: | |
base_branch_data: ${{ steps.base_branch.outputs.name}} | |
merge_branch_data: ${{ steps.merge_branch.outputs.name }} | |
category_data_diff_file: ${{ steps.cat_diff.outputs.name }} | |
env: | |
base_branch_sha: ${{ github.event.pull_request.base.sha }} | |
merge_branch_sha: ${{ github.sha }} | |
source_branch_sha: ${{ github.event.pull_request.head.sha }} | |
pr_num: ${{ github.event.pull_request.number }} | |
steps: | |
- name: Create name for base branch data | |
id: base_branch | |
run: echo "name=pr$pr_num-base-branch-$base_branch_sha" | tee -a "$GITHUB_OUTPUT" | |
- name: Create name for merge branch data | |
id: merge_branch | |
run: echo "name=pr$pr_num-merge-branch-$base_branch_sha-$source_branch_sha" | tee -a "$GITHUB_OUTPUT" | |
- name: Create name for category data diff | |
id: cat_diff | |
run: echo "name=category-data-pr$pr_num-$base_branch_sha...merge$source_branch_sha.diff" | tee -a "$GITHUB_OUTPUT" | |
approve: | |
name: Approve diff | |
needs: artifact_names | |
if: github.event_name == 'pull_request' && github.event.action == 'labeled' && github.event.label.name == 'fuzzy-diff-looks-good' | |
runs-on: ubuntu-20.04 | |
permissions: write-all | |
env: | |
gh_api_artifacts_url: ${{ github.event.pull_request.base.repo.url }}/actions/artifacts | |
cat_data_diff: ${{ needs.artifact_names.outputs.category_data_diff_file }} | |
steps: | |
- name: Retreive category data diff meta-data | |
id: cat_artifact | |
run: | | |
all_artifacts=$(curl -sSL $gh_api_artifacts_url) | |
category_data_artifact=$(echo "$all_artifacts" | jq "first(.artifacts[] | select(.name == \"$cat_data_diff\") )") | |
id=$(echo "$category_data_artifact" | jq ".id") | |
echo "id=$id" | tee -a $GITHUB_OUTPUT | |
workflow_run=$(echo $category_data_artifact | jq ".workflow_run | .id") | |
echo "workflow_run=$workflow_run" | tee -a $GITHUB_OUTPUT | |
- name: Check if category data diff exists | |
env: | |
id: ${{ steps.cat_artifact.outputs.id }} | |
run: | | |
# FIXME (?) | |
if [ -z $id ]; then | |
echo "You seem to have tried to approve a diff that doesn't exist yet.\nWait for the diff to have been generated and then try again." | |
# TODO: Remove the label | |
exit 1 | |
else | |
echo "Category data diff exists" | |
fi | |
- name: Download category data diff | |
env: | |
id: ${{ steps.cat_artifact.outputs.id }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
# Doing this manually, since actions/download-artifact only works on the same workflow run on which the artifact was uploaded | |
curl -sSLO -H "Authorization: Bearer $GITHUB_TOKEN" $gh_api_artifacts_url/$id/zip -D headers.txt | |
- name: Try to unzip downloaded category data diff | |
run: | | |
unzip zip || (echo "Download of diff artifact failed" && cat headers.txt && cat zip && exit 1) | |
- name: Compute category data diff hash | |
id: category_data_diff_hash | |
run: | | |
hash=$(sha256sum $cat_data_diff | awk '{print $1}') | |
echo "hash=$hash" | tee -a $GITHUB_OUTPUT | |
- name: Write HTTP body to file | |
env: | |
repo_url: ${{ github.event.repository.html_url }} | |
cat_workflow_run: ${{ steps.cat_artifact.outputs.workflow_run }} | |
cat_diff_id: ${{ steps.cat_artifact.outputs.id }} | |
cat_hash: ${{ steps.category_data_diff_hash.outputs.hash }} | |
run: | | |
msg=$( cat <<EOF | |
This PR introduces a change in some Merlin query response(s), which has been captured by the fuzzy-test CI. The fuzzy-test diffs of the CI have been approved. Info about the diffs that have been approved: | |
- Distilled data: | |
- Data can be downloaded from $repo_url/actions/runs/$cat_workflow_run | |
- Artifact name with data on target branch (i.e. \`master\` at (...)): (...) | |
- Artifact name with data on PR merge branch, i.e. merge result of source branch (at (...)) and target branch: (...) | |
- Artifact name with diff between the two: | |
- Diff 256-sha: $cat_hash | |
- Full responses: | |
- Data can be downloaded from $repo_url/actions/runs/$cat_workflow_run | |
- Artifact name with data on target branch (i.e. \`master\` at (...)): (...) | |
- Artifact name with data on PR merge branch, i.e. merge result of source branch (at (...)) and target branch: (...) | |
- Artifact name with diff between the two: | |
- Diff 256-sha: <full_reponses_hash> | |
EOF | |
) | |
jq -n --arg msg "$msg" '{ body: $msg }' | tee -a body.json | |
- name: Write comment on PR | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
curl -LsX POST -H "Authorization: Bearer $GITHUB_TOKEN" -d @body.json https://api.github.com/repos/pitag-ha/merlin/issues/6/comments | |
echo $? | |
data: | |
name: Generate data | |
needs: artifact_names | |
runs-on: ubuntu-20.04 | |
if: github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'synchronize' || github.event.action == 'reopened' || ( github.event.action == 'unlabeled' && github.event.label.name == 'fuzzy-diff-looks-good' ) ) | |
# if: false | |
outputs: | |
base_branch_data_name: ${{ env.base_branch_data_name }} | |
merge_branch_data_name: ${{ env.merge_branch_data_name }} | |
env: | |
base_branch_sha: ${{ github.event.pull_request.base.sha }} | |
merge_branch_sha: ${{ github.sha }} | |
base_branch_data_name: ${{ needs.artifact_names.outputs.base_branch_data }} | |
merge_branch_data_name: ${{ needs.artifact_names.outputs.merge_branch_data }} | |
strategy: | |
matrix: | |
commit: ["merge_branch", "base_branch"] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Checking out ${{ matrix.commit }} | |
run: | | |
sha=$${{ matrix.commit }}_sha | |
# echo "sha=$sha" >> $GITHUB_ENV | |
echo "Check out $sha" | |
git checkout $sha | |
# - name: Check if merge was fast-forwarded | |
# if: ${{ matrix.commit == 'merge-commit' }} | |
# run: | | |
# merge_sha=$${{ matrix.commit }} | |
# source=$(git rev-parse $merge_sha^2) | |
# git diff $merge_sha $source | |
- name: Create artifact dir | |
run: mkdir -p data | |
- name: Create data | |
run: | | |
touch data1.json | |
touch data2.json | |
echo "whatever ${{matrix.commit}}, run num: ${{ github.run_number }}" > category_data.json | |
echo "whetever else ${{matrix.commit}}, run num: ${{ github.run_number }}" > full_responses.json | |
working-directory: data | |
- name: Create name for matrix entry data | |
run: echo "data_name=$${{ matrix.commit }}_data_name" >> $GITHUB_ENV | |
- name: Upload data | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ env.data_name }} | |
path: data | |
diff: | |
name: Generate diff | |
runs-on: ubuntu-20.04 | |
needs: [data, artifact_names] | |
env: | |
base: ${{ needs.artifact_names.outputs.base_branch_data }} | |
merge: ${{ needs.artifact_names.outputs.merge_branch_data }} | |
cat_data_diff: ${{ needs.artifact_names.outputs.category_data_diff_file }} | |
steps: | |
- name: Download base branch data | |
env: | |
data_dir: ${{ env.base }} | |
uses: actions/download-artifact@v3 | |
with: | |
name: ${{ env.data_dir }} | |
path: data-${{ env.data_dir }} | |
- name: Download merge branch data | |
env: | |
data_dir: ${{ env.merge }} | |
uses: actions/download-artifact@v3 | |
with: | |
name: ${{ env.data_dir }} | |
path: data-${{ env.data_dir }} | |
- name: Generate category data diff | |
id: category_data_diff | |
# To guarantee idempotence in diff generation, we're using `--labels` to avoids time stamps | |
run: (diff -U 1 --label="$base" --label="$merge" data-$base/category_data.json data-$merge/category_data.json > $cat_data_diff && echo "diff_exists=false" | tee -a "$GITHUB_OUTPUT" ) || echo "diff_exists=true" | tee -a "$GITHUB_OUTPUT" | |
# - name: Remove timestamps from diff | |
# if: ${{ steps.diff.outputs.diff_exists}} | |
# run: sed -E -i 's/^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}//' cat_data_diff | |
- name: Upload diff | |
if: ${{ steps.category_data_diff.outputs.diff_exists}} | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ env.cat_data_diff }} | |
path: ${{ env.cat_data_diff }} | |
output: | |
name: Evaluate diff | |
runs-on: ubuntu-20.04 | |
needs: [diff, artifact_names] | |
steps: | |
- name: Return | |
run: | | |
if "${{ steps.category_data_diff.outputs.diff_exists}}"; then | |
cat $cat_data_diff | |
exit 1 | |
else | |
echo "No diff. All good." | |
exit 0 | |
fi | |
# - name: log PR target | |
# run: git log remotes/origin/${{ github.base_ref }} -n 3 | |
# - name: Find common ancestor | |
# run: | | |
# common_ancestor = $(git merge-base ${{ github.ref }} ${{ github.base_ref }}) | |
# echo "Common ancestor: $common_ancestor" | |
# - name: Checkout code | |
# uses: actions/checkout@v3 | |
# - name: Install OCaml | |
# uses: ocaml/setup-ocaml@v2 | |
# with: | |
# # When updating the compiler here, also update the Irmin build on ... to the new compiler | |
# ocaml-compiler: ocaml-base-compiler.4.14.1 | |
# dune-cache: true | |
# - name: Install dependencies | |
# run: opam install --deps-only . | |
# # TODO: rebase over master before installing merlin. | |
# - name: Install merlin | |
# run: | | |
# opam exec -- dune subst | |
# opam exec -- dune build | |
# opam exec -- dune install | |
# - name: Install merl-an | |
# run: opam pin -y merl-an https://github.com/pitag-ha/merl-an.git | |
# - name: Set up ssh env | |
# uses: webfactory/[email protected] | |
# with: | |
# ssh-private-key: ${{ secrets.DEPLOY_KEY_FOR_FUZZY_CI }} | |
# - name: Clone data repo | |
# run: git clone [email protected]:pitag-ha/merlin-fuzzy-ci-data.git data | |
# - name: Configure git user | |
# run: | | |
# git config user.email "[email protected]>" | |
# git config user.name "Merlin Fuzzy CI" | |
# working-directory: data | |
# - name: Checkout new branch | |
# run: | | |
# git fetch origin | |
# git checkout origin/main | |
# git checkout -b yuhuuu | |
# working-directory: data | |
# - name: Build test code base | |
# run: | | |
# eval $(opam env) | |
# dune build @check | |
# working-directory: data/test-code-base/irmin | |
# - name: Create new data | |
# run: | | |
# eval $(opam env) | |
# merl-an behavior --queries=type-enclosing,occurrences,locate,complete-prefix,errors --sample-size=30 --data=irmin_data --merlin=ocamlmerlin --project=test-code-base/irmin/src/irmin/ | |
# # merl-an behavior --queries=type-enclosing,occurrences,locate,complete-prefix,errors --sample-size=30 --data=irmin_pack_data --merlin=ocamlmerlin --project=irmin/src/irmin-pack --extensions=ml | |
# # merl-an behavior --queries=type-enclosing,occurrences,locate,complete-prefix,errors --sample-size=30 --data=irmin_pack_test_data --merlin=ocamlmerlin --project=irmin/test/irmin-pack --extensions=ml | |
# working-directory: data | |
# - name: Commit new data | |
# run: | | |
# git add irmin_data | |
# git commit -m "Updated data from PR ..." | |
# working-directory: data | |
# - name: Push new data | |
# run: git push --set-upstream -f origin yuhuuu | |
# env: | |
# SSH_PRIVATE_KEY: ${{ secrets.DEPLOY_KEY_FOR_FUZZY_CI }} | |
# working-directory: data | |
# - name: Diff new data with old data | |
# run: | | |
# if [[ -n $(git diff origin/main) ]]; then | |
# echo "See diff on https://github.com/pitag-ha/merlin-fuzzy-ci-data/compare/main...yuhuuu" | |
# exit 1 | |
# else | |
# echo "All good: No diff on merl-an's sample set." | |
# fi | |
# working-directory: data |