|
| 1 | +name: Check the dynamic version of the Benefits package |
| 2 | + |
| 3 | +on: [push, pull_request, workflow_call] |
| 4 | + |
| 5 | +jobs: |
| 6 | + check-dynamic-version: |
| 7 | + runs-on: ubuntu-latest |
| 8 | + steps: |
| 9 | + - name: Checkout code |
| 10 | + uses: actions/checkout@v6 |
| 11 | + with: |
| 12 | + fetch-depth: 0 # fetch all history/tags for setuptools_scm to work |
| 13 | + |
| 14 | + - name: Configure Git |
| 15 | + # required Git setup for creating annotated tags |
| 16 | + run: | |
| 17 | + git config user.name "Version Checker" |
| 18 | + git config user.email "user@checker.org" |
| 19 | +
|
| 20 | + - name: Create annotated tag for testing |
| 21 | + id: create_tag |
| 22 | + run: | |
| 23 | + # create "<current_year>.<current_month>.1" test tag |
| 24 | + TEST_TAG="$(date +'%Y.%m.1')" |
| 25 | + echo "tag=$TEST_TAG" >> $GITHUB_OUTPUT |
| 26 | + git tag -a $TEST_TAG -m "Testing tag" |
| 27 | +
|
| 28 | + - name: Build and start the app container |
| 29 | + run: | |
| 30 | + docker compose build --no-cache client |
| 31 | + docker compose up -d client |
| 32 | +
|
| 33 | + - name: Verify version match |
| 34 | + run: | |
| 35 | + # define expected version |
| 36 | + EXPECTED="${{ steps.create_tag.outputs.tag }}" |
| 37 | +
|
| 38 | + # get actual version from the app container |
| 39 | + # tail is required to ignore the "... objects imported automatically..." banner preceding the version number |
| 40 | + ACTUAL=$(docker compose exec -T client python manage.py shell -c "import benefits; print(benefits.VERSION)" | tail -n 1) |
| 41 | +
|
| 42 | + echo "Expected tag: $EXPECTED" |
| 43 | + echo "Actual tag: $ACTUAL" |
| 44 | +
|
| 45 | + # compare versions |
| 46 | + if [ "$ACTUAL" == "$EXPECTED" ]; then |
| 47 | + echo "Success: Version matches git tag." |
| 48 | + else |
| 49 | + echo "Error: Version mismatch" |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | +
|
| 53 | + - name: Cleanup |
| 54 | + if: ${{ !cancelled() }} # Run even if any of the previous steps fail |
| 55 | + run: | |
| 56 | + docker compose down |
| 57 | + # delete the test tag or simply run true if it doesn't exist |
| 58 | + git tag -d ${{ steps.create_tag.outputs.tag }} || true |
0 commit comments