-
Notifications
You must be signed in to change notification settings - Fork 0
90 lines (90 loc) · 3.67 KB
/
test.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
name: Test github-update-submodules CLI, release update-submodules to PyPI
on:
push:
branches: [ main, test ]
tags: [ v* ]
workflow_dispatch:
inputs:
ref:
description: 'runsascoded/update-submodules repo ref to install'
init:
description: "Initial commit SHA to initialize this test's branch to"
default: 'b72d4de78127f569d106e665767298a5004baffa'
env:
GH_TOKEN: ${{ github.token }}
jobs:
test:
name: Test github-update-submodules
runs-on: ubuntu-latest
env:
init: ${{ inputs.init || 'b72d4de78127f569d106e665767298a5004baffa' }}
steps:
- name: Set env vars
run: |
# Store the triggering branch (cf. https://github.com/github/docs/issues/15319#issuecomment-1662257301)
echo "REF=${{ inputs.ref || (github.event.pull_request && github.head_ref || github.ref_name) }}" >> $GITHUB_ENV
# Store a temporary branch name in `$branch`
echo "branch=test-${{ github.run_id }}" >> $GITHUB_ENV
- name: Initialize test branch
uses: runsascoded/tmp-branch-action@v1
with:
branch: ${{ env.branch }}
sha: ${{ env.init }}
- name: Install update-submodules
run: pip install git+https://github.com/$GITHUB_REPOSITORY@$REF
- name: Update submodules
id: update
run: github-update-submodules -b$branch
- run: "echo \"steps.update.outputs.commit: ${{ steps.update.outputs.commit }}\""
- name: Wait for `gh api` to reflect new commit on branch
run: |
i=0
n=5
while [ 1 ]; do
commit="$(gh api /repos/$GITHUB_REPOSITORY/git/ref/heads/$branch | jq -r .object.sha)"
if [ $commit != $init ] || [ $i -ge $n ]; then break; fi
echo "$i/$n: waiting for branch $branch to show a commit other than $init (expected ${{ steps.update.outputs.commit }})…"
sleep 1
let i=$i+1
done
if [ $i -ge $n ]; then
msg=Branch $branch still shows commit $init after $n seconds
echo "::error::$msg"
echo "$msg"
exit 1
elif [ $i -gt 0 ]; then
msg="Branch $branch took $n seconds to update from initial value $init"
echo "::warning::$msg"
echo "$msg"
fi
- name: Verify submodule updates
run: |
echo "Branch $branch"
commit="$(gh api /repos/$GITHUB_REPOSITORY/git/ref/heads/$branch | jq -r .object.sha)"
echo "commit: $commit"
tree="$(gh api /repos/$GITHUB_REPOSITORY/git/commits/$commit | jq -r .tree.sha)"
echo "tree: $tree"
elems="$(gh api /repos/$GITHUB_REPOSITORY/git/trees/$tree | jq -c '.tree | map({ "key": .path, "value": .sha }) | from_entries')"
expected='{".gitmodules":"7816159e836aec22afcbcb75f56f706883890054","test0":"f398921287dae85b39c97f5273f8a8a9ebdc76d7","test1":"65d3b0bef66bfb952f14c70e22cbe78aa9613e97"}'
echo "elems: $elems"
echo "expected: $expected"
[ "$elems" == "$expected" ] && echo 'Success!'
release:
name: Release `update-submodules` to PyPI
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.9'
- run: pip install -e .
- name: Build, release
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: |
pip install setuptools twine wheel
python setup.py sdist bdist_wheel
twine upload dist/*