Release Pipeline #19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release Pipeline | |
on: | |
workflow_dispatch: | |
inputs: | |
release_type: | |
description: 'Release type (patch, minor, major)' | |
required: false | |
default: 'patch' | |
type: string | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Bump version | |
id: version | |
run: | | |
current_version=$(git tag --list 'v*' --sort=-v:refname | head -n 1 | sed 's/^v//') | |
if [[ -z $current_version ]]; then | |
current_version="0.0.0" | |
fi | |
pip install --upgrade semver | |
next_version=$(pysemver nextver $current_version ${{ github.event.inputs.release_type }}) | |
echo "Current version: $current_version" | |
echo "Next version: $next_version" | |
echo "next_version=$next_version" >> "$GITHUB_ENV" | |
- name: Build and push the Docker image to Docker Hub | |
run: | | |
docker build . --file Dockerfile --tag tonur/tenable-exporter:$next_version | |
docker login -u "tonur" -p "${{ secrets.DOCKER_ACCESS_TOKEN }}" | |
docker push tonur/tenable-exporter:$next_version | |
# Tag and push with "latest" | |
docker tag tonur/tenable-exporter:$next_version tonur/tenable-exporter:latest | |
docker push tonur/tenable-exporter:latest | |
- name: Create and push release branch | |
run: | | |
git config user.name "GitHub Actions Bot" | |
git config user.email "<>" | |
git checkout -b release/$next_version | |
git tag -a v$next_version -m "Release $next_version" | |
git push origin release/$next_version | |
git push origin v$next_version | |
- name: Create GitHub release | |
run: | | |
body="Run the Docker image: \`docker run -p 8080:<your_port> -e TIO_ACCESS_KEY=your_access_key -e TIO_SECRET_KEY=your_secret_key tonur/tenable-exporter:$next_version\`" | |
curl -X POST -H "Authorization: token ${{ secrets.RELEASE_GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
"https://api.github.com/repos/${{ github.repository }}/releases" \ | |
-d "{\"tag_name\": \"v$next_version\", \"name\": \"$next_version\", \"body\": \"$body\", \"draft\": true, \"prerelease\": false}" |