Skip to content

Commit

Permalink
ci: merge main to release (pull request #7175)
Browse files Browse the repository at this point in the history
ci: merge main to release
  • Loading branch information
rjsparks committed Mar 12, 2024
2 parents dd24558 + cee6999 commit 8c72efa
Show file tree
Hide file tree
Showing 30 changed files with 2,191 additions and 441 deletions.
37 changes: 24 additions & 13 deletions .github/workflows/build.yml
Expand Up @@ -62,19 +62,30 @@ jobs:
fetch-depth: 1
fetch-tags: false

- name: Get Next Version
- name: Get Next Version (Prod)
if: ${{ github.ref_name == 'release' }}
id: semver
uses: ietf-tools/semver-action@v1
with:
token: ${{ github.token }}
branch: release
skipInvalidTags: true

- name: Set Next Version Env Var

- name: Get Dev Version
if: ${{ github.ref_name != 'release' }}
id: semverdev
uses: ietf-tools/semver-action@v1
with:
token: ${{ github.token }}
branch: release
skipInvalidTags: true
noVersionBumpBehavior: 'current'
noNewCommitBehavior: 'current'

- name: Set Release Flag
if: ${{ github.ref_name == 'release' }}
run: |
echo "NEXT_VERSION=$nextStrict" >> $GITHUB_ENV
echo "IS_RELEASE=true" >> $GITHUB_ENV
- name: Create Draft Release
uses: ncipollo/release-action@v1.14.0
Expand All @@ -83,24 +94,24 @@ jobs:
prerelease: true
draft: false
commit: ${{ github.sha }}
tag: ${{ env.NEXT_VERSION }}
name: ${{ env.NEXT_VERSION }}
tag: ${{ steps.semver.outputs.nextStrict }}
name: ${{ steps.semver.outputs.nextStrict }}
body: '*pending*'
token: ${{ secrets.GITHUB_TOKEN }}

- name: Set Build Variables
id: buildvars
run: |
if [[ $NEXT_VERSION ]]; then
echo "Using AUTO SEMVER mode: $NEXT_VERSION"
if [[ $IS_RELEASE ]]; then
echo "Using AUTO SEMVER mode: ${{ steps.semver.outputs.nextStrict }}"
echo "should_deploy=true" >> $GITHUB_OUTPUT
echo "pkg_version=$NEXT_VERSION" >> $GITHUB_OUTPUT
echo "::notice::Release $NEXT_VERSION created using branch $GITHUB_REF_NAME"
echo "pkg_version=${{ steps.semver.outputs.nextStrict }}" >> $GITHUB_OUTPUT
echo "::notice::Release ${{ steps.semver.outputs.nextStrict }} created using branch $GITHUB_REF_NAME"
else
echo "Using TEST mode: 11.0.0-dev.$GITHUB_RUN_NUMBER"
echo "Using TEST mode: ${{ steps.semverdev.outputs.nextMajorStrict }}.0.0-dev.$GITHUB_RUN_NUMBER"
echo "should_deploy=false" >> $GITHUB_OUTPUT
echo "pkg_version=11.0.0-dev.$GITHUB_RUN_NUMBER" >> $GITHUB_OUTPUT
echo "::notice::Non-production build 11.0.0-dev.$GITHUB_RUN_NUMBER created using branch $GITHUB_REF_NAME"
echo "pkg_version=${{ steps.semverdev.outputs.nextMajorStrict }}.0.0-dev.$GITHUB_RUN_NUMBER" >> $GITHUB_OUTPUT
echo "::notice::Non-production build ${{ steps.semverdev.outputs.nextMajorStrict }}.0.0-dev.$GITHUB_RUN_NUMBER created using branch $GITHUB_REF_NAME"
fi
# -----------------------------------------------------------------
Expand Down
44 changes: 22 additions & 22 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
20 changes: 19 additions & 1 deletion ietf/__init__.py
Expand Up @@ -6,7 +6,7 @@

# Version must stay in single quotes for automatic CI replace
# Don't add patch number here:
__version__ = '11.0.0-dev'
__version__ = '1.0.0-dev'

# Release hash must stay in single quotes for automatic CI replace
__release_hash__ = ''
Expand All @@ -17,6 +17,24 @@
# set this to ".p1", ".p2", etc. after patching
__patch__ = ""

if __version__ == '1.0.0-dev' and __release_hash__ == '' and __release_branch__ == '':
import subprocess
branch = subprocess.run(
["/usr/bin/git", "branch", "--show-current"],
capture_output=True,
).stdout.decode().strip()
git_hash = subprocess.run(
["/usr/bin/git", "rev-parse", "head"],
capture_output=True,
).stdout.decode().strip()
rev = subprocess.run(
["/usr/bin/git", "describe", "--tags", git_hash],
capture_output=True,
).stdout.decode().strip().split('-', 1)[0]
__version__ = f"{rev}-dev"
__release_branch__ = branch
__release_hash__ = git_hash


# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
Expand Down
118 changes: 117 additions & 1 deletion ietf/api/tests.py
Expand Up @@ -219,7 +219,9 @@ def test_api_set_session_video_url(self):
event = doc.latest_event()
self.assertEqual(event.by, recman)

def test_api_add_session_attendees(self):
def test_api_add_session_attendees_deprecated(self):
# Deprecated test - should be removed when we stop accepting a simple list of user PKs in
# the add_session_attendees() view
url = urlreverse('ietf.meeting.views.api_add_session_attendees')
otherperson = PersonFactory()
recmanrole = RoleFactory(group__type_id='ietf', name_id='recman')
Expand Down Expand Up @@ -285,6 +287,120 @@ def test_api_add_session_attendees(self):
self.assertTrue(session.attended_set.filter(person=recman).exists())
self.assertTrue(session.attended_set.filter(person=otherperson).exists())

def test_api_add_session_attendees(self):
url = urlreverse("ietf.meeting.views.api_add_session_attendees")
otherperson = PersonFactory()
recmanrole = RoleFactory(group__type_id="ietf", name_id="recman")
recman = recmanrole.person
meeting = MeetingFactory(type_id="ietf")
session = SessionFactory(group__type_id="wg", meeting=meeting)
apikey = PersonalApiKey.objects.create(endpoint=url, person=recman)

badrole = RoleFactory(group__type_id="ietf", name_id="ad")
badapikey = PersonalApiKey.objects.create(endpoint=url, person=badrole.person)
badrole.person.user.last_login = timezone.now()
badrole.person.user.save()

# Improper credentials, or method
r = self.client.post(url, {})
self.assertContains(r, "Missing apikey parameter", status_code=400)

r = self.client.post(url, {"apikey": badapikey.hash()})
self.assertContains(r, "Restricted to role: Recording Manager", status_code=403)

r = self.client.post(url, {"apikey": apikey.hash()})
self.assertContains(r, "Too long since last regular login", status_code=400)

recman.user.last_login = timezone.now() - datetime.timedelta(days=365)
recman.user.save()
r = self.client.post(url, {"apikey": apikey.hash()})
self.assertContains(r, "Too long since last regular login", status_code=400)

recman.user.last_login = timezone.now()
recman.user.save()
r = self.client.get(url, {"apikey": apikey.hash()})
self.assertContains(r, "Method not allowed", status_code=405)

recman.user.last_login = timezone.now()
recman.user.save()

# Malformed requests
r = self.client.post(url, {"apikey": apikey.hash()})
self.assertContains(r, "Missing attended parameter", status_code=400)

for baddict in (
"{}",
'{"bogons;drop table":"bogons;drop table"}',
'{"session_id":"Not an integer;drop table"}',
f'{{"session_id":{session.pk},"attendees":"not a list;drop table"}}',
f'{{"session_id":{session.pk},"attendees":"not a list;drop table"}}',
f'{{"session_id":{session.pk},"attendees":[1,2,"not an int;drop table",4]}}',
f'{{"session_id":{session.pk},"attendees":["user_id":{recman.user.pk}]}}', # no join_time
f'{{"session_id":{session.pk},"attendees":["user_id":{recman.user.pk},"join_time;drop table":"2024-01-01T00:00:00Z]}}',
f'{{"session_id":{session.pk},"attendees":["user_id":{recman.user.pk},"join_time":"not a time;drop table"]}}',
# next has no time zone indicator
f'{{"session_id":{session.pk},"attendees":["user_id":{recman.user.pk},"join_time":"2024-01-01T00:00:00"]}}',
f'{{"session_id":{session.pk},"attendees":["user_id":"not an int; drop table","join_time":"2024-01-01T00:00:00Z"]}}',
# Uncomment the next one when the _deprecated version of this test is retired
# f'{{"session_id":{session.pk},"attendees":[{recman.user.pk}, {otherperson.user.pk}]}}',
):
r = self.client.post(url, {"apikey": apikey.hash(), "attended": baddict})
self.assertContains(r, "Malformed post", status_code=400)

bad_session_id = Session.objects.order_by("-pk").first().pk + 1
r = self.client.post(
url,
{
"apikey": apikey.hash(),
"attended": f'{{"session_id":{bad_session_id},"attendees":[]}}',
},
)
self.assertContains(r, "Invalid session", status_code=400)
bad_user_id = User.objects.order_by("-pk").first().pk + 1
r = self.client.post(
url,
{
"apikey": apikey.hash(),
"attended": f'{{"session_id":{session.pk},"attendees":[{{"user_id":{bad_user_id}, "join_time":"2024-01-01T00:00:00Z"}}]}}',
},
)
self.assertContains(r, "Invalid attendee", status_code=400)

# Reasonable request
r = self.client.post(
url,
{
"apikey": apikey.hash(),
"attended": json.dumps(
{
"session_id": session.pk,
"attendees": [
{
"user_id": recman.user.pk,
"join_time": "2023-09-03T12:34:56Z",
},
{
"user_id": otherperson.user.pk,
"join_time": "2023-09-03T03:00:19Z",
},
],
}
),
},
)

self.assertEqual(session.attended_set.count(), 2)
self.assertTrue(session.attended_set.filter(person=recman).exists())
self.assertEqual(
session.attended_set.get(person=recman).time,
datetime.datetime(2023, 9, 3, 12, 34, 56, tzinfo=datetime.timezone.utc),
)
self.assertTrue(session.attended_set.filter(person=otherperson).exists())
self.assertEqual(
session.attended_set.get(person=otherperson).time,
datetime.datetime(2023, 9, 3, 3, 0, 19, tzinfo=datetime.timezone.utc),
)

def test_api_upload_polls_and_chatlog(self):
recmanrole = RoleFactory(group__type_id='ietf', name_id='recman')
recmanrole.person.user.last_login = timezone.now()
Expand Down

0 comments on commit 8c72efa

Please sign in to comment.