213 lines
6.8 KiB
YAML
213 lines
6.8 KiB
YAML
name: Build and Release
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- 'v*'
|
|
|
|
workflow_dispatch:
|
|
inputs:
|
|
publish:
|
|
description: 'Create Production Release'
|
|
required: true
|
|
type: boolean
|
|
skiptests:
|
|
description: 'Skip Tests'
|
|
required: true
|
|
type: boolean
|
|
|
|
jobs:
|
|
# -----------------------------------------------------------------
|
|
# PREPARE
|
|
# -----------------------------------------------------------------
|
|
prepare:
|
|
name: Prepare Release
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
should_deploy: ${{ steps.buildvars.outputs.should_deploy }}
|
|
pkg_version: ${{ steps.buildvars.outputs.pkg_version }}
|
|
pkg_version_strict: ${{ steps.buildvars.outputs.pkg_version_strict }}
|
|
|
|
steps:
|
|
- uses: actions/checkout@v2
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Get Next Version
|
|
if: ${{ github.event.inputs.publish == 'true' }}
|
|
id: semver
|
|
uses: ietf-tools/semver-action@v1
|
|
with:
|
|
token: ${{ github.token }}
|
|
branch: main
|
|
|
|
- name: Set Next Version Env Var
|
|
if: ${{ github.event.inputs.publish == 'true' }}
|
|
env:
|
|
NEXT_VERSION: ${{ steps.semver.outputs.next }}
|
|
run: |
|
|
echo "NEXT_VERSION=$next" >> $GITHUB_ENV
|
|
|
|
- name: Create Draft Release
|
|
uses: ncipollo/release-action@v1
|
|
if: ${{ github.event.inputs.publish == 'true' }}
|
|
with:
|
|
prerelease: true
|
|
draft: false
|
|
commit: ${{ github.sha }}
|
|
tag: ${{ env.NEXT_VERSION }}
|
|
name: ${{ env.NEXT_VERSION }}
|
|
body: '*pending*'
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Set Build Variables
|
|
id: buildvars
|
|
run: |
|
|
if [[ $NEXT_VERSION ]]; then
|
|
echo "Using AUTO SEMVER mode: $NEXT_VERSION"
|
|
echo "::set-output name=should_deploy::true"
|
|
echo "::set-output name=pkg_version::$NEXT_VERSION"
|
|
echo "::set-output name=pkg_version_strict::${NEXT_VERSION#?}"
|
|
echo "::notice::Release created using branch $GITHUB_REF_NAME"
|
|
elif [[ "$GITHUB_REF" =~ ^refs/tags/v* ]]; then
|
|
echo "Using TAG mode: $GITHUB_REF_NAME"
|
|
echo "::set-output name=should_deploy::true"
|
|
echo "::set-output name=pkg_version::$GITHUB_REF_NAME"
|
|
echo "::set-output name=pkg_version_strict::${GITHUB_REF_NAME#?}"
|
|
echo "::notice::Release created using tag $GITHUB_REF_NAME"
|
|
else
|
|
echo "Using TEST mode: v7.0.0-dev.$GITHUB_RUN_NUMBER"
|
|
echo "::set-output name=should_deploy::false"
|
|
echo "::set-output name=pkg_version::v7.0.0-dev.$GITHUB_RUN_NUMBER"
|
|
echo "::set-output name=pkg_version_strict::7.0.0-dev.$GITHUB_RUN_NUMBER"
|
|
echo "::notice::Non-production build created using branch $GITHUB_REF_NAME"
|
|
fi
|
|
|
|
# -----------------------------------------------------------------
|
|
# TESTS
|
|
# -----------------------------------------------------------------
|
|
tests:
|
|
name: Run Tests
|
|
if: ${{ github.event.inputs.skiptests == 'false' }}
|
|
needs: [prepare]
|
|
runs-on: ubuntu-latest
|
|
container: ghcr.io/ietf-tools/datatracker-test-base:latest
|
|
|
|
services:
|
|
db:
|
|
image: ghcr.io/ietf-tools/datatracker-db:latest
|
|
volumes:
|
|
- mariadb-data:/var/lib/mysql
|
|
env:
|
|
MYSQL_ROOT_PASSWORD: ietf
|
|
MYSQL_DATABASE: ietf_utf8
|
|
MYSQL_USER: django
|
|
MYSQL_PASSWORD: RkTkDPFnKpko
|
|
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
|
|
- name: Prepare for tests
|
|
run: |
|
|
chmod +x ./dev/tests/prepare.sh
|
|
sh ./dev/tests/prepare.sh
|
|
|
|
- name: Ensure DB is ready
|
|
run: |
|
|
/usr/local/bin/wait-for db:3306 -- echo "DB ready"
|
|
|
|
- name: Run all tests
|
|
run: |
|
|
echo "Running checks..."
|
|
./ietf/manage.py check
|
|
echo "Running tests..."
|
|
./ietf/manage.py test --settings=settings_sqlitetest --failfast
|
|
mv latest-coverage.json coverage.json
|
|
|
|
- name: Upload a Coverage Results
|
|
uses: actions/upload-artifact@v3.0.0
|
|
with:
|
|
name: coverage
|
|
path: coverage.json
|
|
|
|
# -----------------------------------------------------------------
|
|
# RELEASE
|
|
# -----------------------------------------------------------------
|
|
release:
|
|
name: Make Release
|
|
if: ${{ always() }}
|
|
needs: [tests, prepare]
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
SHOULD_DEPLOY: ${{needs.prepare.outputs.should_deploy}}
|
|
PKG_VERSION: ${{needs.prepare.outputs.pkg_version}}
|
|
PKG_VERSION_STRICT: ${{needs.prepare.outputs.pkg_version_strict}}
|
|
|
|
steps:
|
|
- uses: actions/checkout@v2
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v3.0.0
|
|
with:
|
|
node-version: 16.x
|
|
|
|
- name: Setup Python
|
|
uses: actions/setup-python@v2
|
|
with:
|
|
python-version: '3.x'
|
|
|
|
- name: Download a Coverage Results
|
|
if: ${{ github.event.inputs.skiptests == 'false' }}
|
|
uses: actions/download-artifact@v3.0.0
|
|
with:
|
|
name: coverage
|
|
|
|
- name: Make Release Build
|
|
env:
|
|
DEBIAN_FRONTEND: noninteractive
|
|
run: |
|
|
echo "PKG_VERSION: $PKG_VERSION"
|
|
echo "PKG_VERSION_STRICT: $PKG_VERSION_STRICT"
|
|
echo "GITHUB_SHA: $GITHUB_SHA"
|
|
echo "GITHUB_REF_NAME: $GITHUB_REF_NAME"
|
|
echo "Running build script..."
|
|
chmod +x ./dev/deploy/build.sh
|
|
sh ./dev/deploy/build.sh
|
|
echo "Setting version $PKG_VERSION_STRICT..."
|
|
sed -i -r -e "s|^__version__ += '.*'$|__version__ = '$PKG_VERSION_STRICT'|" ietf/__init__.py
|
|
sed -i -r -e "s|^__release_hash__ += '.*'$|__release_hash__ = '$GITHUB_SHA'|" ietf/__init__.py
|
|
sed -i -r -e "s|^__release_branch__ += '.*'$|__release_branch__ = '$GITHUB_REF_NAME'|" ietf/__init__.py
|
|
echo "Build release tarball..."
|
|
mkdir -p /home/runner/work/release
|
|
tar -czf /home/runner/work/release/release.tar.gz -X dev/deploy/exclude-patterns.txt .
|
|
|
|
- name: Update CHANGELOG
|
|
id: changelog
|
|
uses: Requarks/changelog-action@v1
|
|
if: env.SHOULD_DEPLOY == 'true'
|
|
with:
|
|
token: ${{ github.token }}
|
|
tag: ${{ env.PKG_VERSION }}
|
|
writeToFile: false
|
|
|
|
- name: Create Release
|
|
uses: ncipollo/release-action@v1
|
|
if: env.SHOULD_DEPLOY == 'true'
|
|
with:
|
|
allowUpdates: true
|
|
draft: false
|
|
tag: ${{ env.PKG_VERSION }}
|
|
name: ${{ env.PKG_VERSION }}
|
|
body: ${{ steps.changelog.outputs.changes }}
|
|
artifacts: "/home/runner/work/release/release.tar.gz,coverage.json"
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Upload Build Artifacts
|
|
uses: actions/upload-artifact@v2.3.1
|
|
if: env.SHOULD_DEPLOY == 'false'
|
|
with:
|
|
name: release
|
|
path: /home/runner/work/release/release.tar.gz
|