-
Notifications
You must be signed in to change notification settings - Fork 0
134 lines (117 loc) · 3.93 KB
/
test-command.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
name: test-command
on:
push:
branches:
- main
pull_request: null
concurrency:
group: test-command
cancel-in-progress: false
jobs:
test-command:
name: test relock command
runs-on: "ubuntu-latest"
if: github.event.pull_request.title != 'relock w/ conda-lock'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.TEST_PAT }}
- name: backup lock file
run: |
gh pr checkout 112
cp conda-lock.yml ../conda-lock-backup.yml
env:
GH_TOKEN: ${{ secrets.TEST_PAT }}
- name: make uid
id: uid
run: |
uid=$(od -x /dev/urandom | head -1 | awk '{OFS="-"; print $2$3,$4,$5,$6,$7$8$9}')
echo "uid=${uid}" > "$GITHUB_OUTPUT"
- name: move relock code to current branch
run: |
if [[ "${IS_PR}" == "true" ]]; then
branch=pull/${{ github.event.number }}/head
else
branch=main
fi
git checkout main
sed -i \
"s#conda-incubator/relock-conda@main#conda-incubator/relock-conda@${branch}#g" \
.github/workflows/relock.yml
sed -i \
"s#@@GIT_USER_NAME@@#${UID}#g" \
.github/workflows/relock.yml
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add .github/workflows/relock.yml
git commit -m "[ci skip] move relock code to current branch for testing" --allow-empty
git push
env:
IS_PR: ${{ github.event_name == 'pull_request' }}
UID: ${{ steps.uid.outputs.uid }}
- name: trigger relock via comment
run: |
gh pr comment 112 --body "/relock-conda"
env:
GH_TOKEN: ${{ secrets.TEST_PAT }}
- name: wait for relock
run: |
sleep 60
- name: check for updates
run: |
gh pr checkout 112
diffval=$(diff conda-lock.yml ../conda-lock-backup.yml || :)
if [[ "${diffval}" == "" ]]; then
echo "no relock happened!"
exit 1
fi
env:
GH_TOKEN: ${{ secrets.TEST_PAT }}
- name: ensure git committer is correct
run: |
loginfo=$(git log --name-status HEAD^..HEAD)
echo "${loginfo}"
if [[ "${loginfo}" != *"Author: github-actions"* ]]; then
echo "git committer is not correct!"
exit 1
fi
env:
UID: ${{ steps.uid.outputs.uid }}
- name: ensure a comment was made
run: |
latest_login=$(gh pr view 112 --json comments --jq '.comments[-1].author.login')
echo "latest_login: ${latest_login}"
if [[ "${latest_login}" != "github-actions" ]]; then
echo "no comment was made!"
exit 1
fi
env:
GH_TOKEN: ${{ secrets.TEST_PAT }}
- name: cleanup
if: always()
run: |
if [[ "${IS_PR}" == "true" ]]; then
branch=pull/${{ github.event.number }}/head
else
branch=main
fi
git checkout main
sed -i \
"s#conda-incubator/relock-conda@${branch}#conda-incubator/relock-conda@main#g" \
.github/workflows/relock.yml
sed -i \
"s#${UID}#@@GIT_USER_NAME@@#g" \
.github/workflows/relock.yml
git add .github/workflows/relock.yml
git commit -m "[ci skip] move relock code back to main" --allow-empty
git push
gh pr checkout 112
cp ../conda-lock-backup.yml conda-lock.yml
git add conda-lock.yml
git commit -m "[ci skip] restore old lock file" --allow-empty
git push
env:
GH_TOKEN: ${{ secrets.TEST_PAT }}
IS_PR: ${{ github.event_name == 'pull_request' }}
UID: ${{ steps.uid.outputs.uid }}