SIENTIAPDE-1327

SIENTIAPDE-1327: Replace existing release workflow with a template for improved maintainability and permissions
This commit is contained in:
vitor-aignosi
2025-10-22 16:39:00 -03:00
parent e1da6964f4
commit c33869be9f

View File

@@ -7,140 +7,9 @@ on:
- main - main
jobs: jobs:
create-release: release:
if: github.event.pull_request.merged == true uses: Aignosi/github_workflow_templates/.github/workflows/dataops-module-release.yml@main
runs-on: ubuntu-latest permissions: write-all
permissions:
contents: write
pull-requests: read
steps:
- name: Checkout code
uses: actions/checkout@v4
with: with:
fetch-depth: 0 project_name: 'ingestor'
secrets: inherit
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pyyaml pathspec
- name: Get branch name
id: branch_name
run: |
# Obtém o nome da branch da PR
BRANCH_NAME=${GITHUB_HEAD_REF}
echo "Branch da PR: $BRANCH_NAME"
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
- name: Determine next version
id: next_version
run: |
BRANCH_NAME=${{ steps.branch_name.outputs.branch_name }}
# Baixa todas as tags
git fetch --tags
# Pega a última tag sem filtro
LAST_TAG=$(git tag --sort=-v:refname | head -n1)
echo "Última tag encontrada: $LAST_TAG"
# Se não houver tags, assume 0.0.0
if [ -z "$LAST_TAG" ]; then
LAST_TAG="0.0.0"
fi
# Extrai major, minor, patch
IFS='.' read -r MAJOR MINOR PATCH <<< "$LAST_TAG"
echo "Versão atual: $MAJOR.$MINOR.$PATCH"
# Incrementa conforme tipo de branch
if [[ "$BRANCH_NAME" == release/* ]]; then
NEW_MAJOR=$((MAJOR + 1))
NEW_MINOR=0
NEW_PATCH=0
elif [[ "$BRANCH_NAME" == feature/* ]]; then
NEW_MAJOR=$MAJOR
NEW_MINOR=$((MINOR + 1))
NEW_PATCH=0
elif [[ "$BRANCH_NAME" == fix/* ]]; then
NEW_MAJOR=$MAJOR
NEW_MINOR=$MINOR
NEW_PATCH=$((PATCH + 1))
else
echo "Tipo de branch desconhecido. Abortando."
exit 1
fi
NEXT_VERSION="${NEW_MAJOR}.${NEW_MINOR}.${NEW_PATCH}"
echo "Nova versão calculada: $NEXT_VERSION"
echo "version=$NEXT_VERSION" >> $GITHUB_OUTPUT
- name: Generate encrypted code
id: encrypt_code
run: |
VERSION="${{ steps.next_version.outputs.version }}"
OUTPUT_DIR="encrypted_release"
# Create output directory
mkdir -p $OUTPUT_DIR
# Run encrypt.py script
python encrypt.py . encrypted_code --ignore .gitignore --chunk-size 100000
# Move generated files to output directory
mv encrypted_code_*.yaml $OUTPUT_DIR/ 2>/dev/null || true
# Create a zip file with the encrypted files
zip -r "sientia-opc-ingestor-${VERSION}-encrypted.zip" $OUTPUT_DIR/
echo "encrypted_zip=sientia-opc-ingestor-${VERSION}-encrypted.zip" >> $GITHUB_OUTPUT
echo "encrypted_dir=$OUTPUT_DIR" >> $GITHUB_OUTPUT
- name: Create GitHub Release via API
uses: actions/github-script@v7
with:
script: |
const { repo, owner } = context.repo;
const version = "${{ steps.next_version.outputs.version }}";
const branch = "main";
const encryptedZip = "${{ steps.encrypt_code.outputs.encrypted_zip }}";
console.log(`Criando release para a tag: ${version} a partir da branch ${branch}`);
console.log(`Arquivo zip criptografado: ${encryptedZip}`);
// Read the encrypted zip file
const fs = require('fs');
const zipContent = fs.readFileSync(encryptedZip);
const response = await github.rest.repos.createRelease({
owner,
repo,
tag_name: version,
name: `${version}`,
target_commitish: branch,
generate_release_notes: true
});
// Upload the encrypted zip as an asset
await github.rest.repos.uploadReleaseAsset({
owner,
repo,
release_id: response.data.id,
name: encryptedZip,
data: zipContent,
headers: {
'content-type': 'application/zip'
}
});
console.log(`Release criada com sucesso! URL: ${response.data.html_url}`);
console.log(`Arquivo criptografado anexado: ${encryptedZip}`);