Skip to content

Continuous Delivery #40

Continuous Delivery

Continuous Delivery #40

Workflow file for this run

name: Continuous Delivery
on:
push:
tags: ['v*'] # push events to matching v*, i.e. v1.0, v20.15.10
workflow_dispatch:
inputs:
version_tag:
type: string
description: 'Version tag (in format v1.0.0)'
required: true
default: ''
skip_validate:
type: boolean
description: 'Do not validate a tag with the git commit'
required: true
default: false
publish_as_draft:
type: boolean
description: 'Publish the release as a draft'
required: true
default: false
defaults:
run:
shell: bash
env:
PYTHON_DEFAULT_VERSION: '3.9'
GO_DEFAULT_VERSION: '1.20'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
build-pybindings:
runs-on: ${{ matrix.conf.runner }}
strategy:
fail-fast: false
matrix:
conf:
- { runner: ubuntu-latest, os: linux, arch: amd64 }
- { runner: ubuntu-latest, os: linux, arch: arm64 }
- { runner: macos-12, os: darwin, arch: amd64 }
# macos-13-xlarge instance are Apple silicon instances,
# only large and xlarge instances are available as of yet.
- { runner: macos-13, os: darwin, arch: arm64 }
- { runner: windows-2019, os: windows, arch: amd64 }
outputs:
version: ${{ steps.build.outputs.version }}
steps:
- uses: actions/checkout@v2
- name: Start a Docker container (linux)
if: matrix.conf.os == 'linux' && matrix.conf.arch == 'arm64'
run: |
docker run --privileged --rm tonistiigi/binfmt:qemu-v8.0.4 --install arm64
docker run --detach \
--platform linux/arm64 \
--volume .:/work \
--name builder \
arm64v8/python:${{ env.PYTHON_DEFAULT_VERSION }}-bullseye \
/bin/bash -c "sleep infinity"
- name: Start a Docker container (linux-amd64)
if: matrix.conf.os == 'linux' && matrix.conf.arch == 'amd64'
run: |
docker run --detach \
--volume .:/work \
--name builder \
python:${{ env.PYTHON_DEFAULT_VERSION }}-bullseye \
/bin/bash -c "sleep infinity"
- name: Set up Python ${{ env.PYTHON_DEFAULT_VERSION }} (darwin, windows)
if: matrix.conf.os != 'linux'
uses: actions/setup-python@v2
with:
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
- name: Define command wrapper (linux)
if: matrix.conf.os == 'linux'
run: |
# We'll define a 'run' command that will run our commands in the container.
echo '#!/bin/bash' > run
echo 'command="$*"; docker exec --workdir /work/python-bindings builder /bin/bash -c "$command"' >> run
chmod +x run
sudo mv run /usr/local/bin/run
- name: Define command wrapper (darwin)
if: matrix.conf.os == 'darwin'
run: |
# MacOS wrapper just runs commands in python-bindings directory
echo '#!/bin/bash' > run
echo 'pushd python-bindings; "$@"; popd' >> run
chmod +x run
sudo mv run /usr/local/bin/run
- name: Define command wrapper (windows)
if: matrix.conf.os == 'windows'
run: |
# Windows wrapper just runs commands in python-bindings directory
echo '#!/bin/bash' > run
echo 'pushd python-bindings; "$@"; popd' >> run
chmod +x run
mv run /usr/bin/run
- name: Install system dependencies (linux)
if: matrix.conf.os == 'linux'
run: |
run apt update -y
run apt install scons patchelf libnss3-dev -y
- name: Install Python dependencies
run: |
run make deps
- name: Build Python bindings
id: build
run: |
run make build
- if: matrix.conf.os == 'linux'
run: |
sudo chmod -R a+r python-bindings
- name: Upload Python bindings
uses: actions/upload-artifact@v2
with:
name: py-terraform-provider-b2-${{ matrix.conf.os }}-${{ matrix.conf.arch }}
path: python-bindings/dist/py-terraform-provider-b2
if-no-files-found: error
retention-days: 1
build-and-deploy:
needs: [build-pybindings]
env:
NOPYBINDINGS: 1 # do not build python bindings
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create-release.outputs.upload_url }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Go ${{ env.GO_DEFAULT_VERSION }}
uses: actions/setup-go@v2.1.3
with:
go-version: ${{ env.GO_DEFAULT_VERSION }}
- name: Install dependencies
run: |
make deps
- name: Download python bindings for all OSes
uses: actions/download-artifact@v2
with:
path: python-bindings/dist/artifacts/
- name: Postprocess python bindings
working-directory: python-bindings/dist
run: |
mv artifacts/py-terraform-provider-b2-linux-amd64/py-terraform-provider-b2 py-terraform-provider-b2-linux-amd64
mv artifacts/py-terraform-provider-b2-linux-arm64/py-terraform-provider-b2 py-terraform-provider-b2-linux-arm64
mv artifacts/py-terraform-provider-b2-darwin-amd64/py-terraform-provider-b2 py-terraform-provider-b2-darwin-amd64
mv artifacts/py-terraform-provider-b2-darwin-arm64/py-terraform-provider-b2 py-terraform-provider-b2-darwin-arm64
mv artifacts/py-terraform-provider-b2-windows-amd64/py-terraform-provider-b2 py-terraform-provider-b2-windows-amd64
- name: Set release version output
id: version
run: |
tag=${{ inputs.version_tag != '' && inputs.version_tag || github.ref_name }}
# Strip the prefix 'v'
version=${tag:1}
echo "version=$version" >> $GITHUB_OUTPUT
- name: Read the Changelog
id: read-changelog
uses: mindsers/changelog-reader-action@v2
with:
version: ${{ steps.version.outputs.version }}
- name: Import GPG key
id: import_gpg
uses: paultyng/ghaction-import-gpg@v2.1.0
env:
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
PASSPHRASE: ${{ secrets.PASSPHRASE }}
- name: Create GitHub release
uses: goreleaser/goreleaser-action@v6
with:
version: '~> v2'
args: release --clean -p 1 ${{ inputs.skip_validate && '--skip validate' || '' }}
env:
GORELEASER_CURRENT_TAG: v${{ steps.version.outputs.version }}
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
- name: Update GitHub release
uses: softprops/action-gh-release@v1
with:
name: v${{ steps.version.outputs.version }}
body: ${{ steps.read-changelog.outputs.changes }}
draft: ${{ inputs.publish_as_draft }}
prerelease: false