Skip to content

Fix Import Script Limit and Env Vars (#203) #15

Fix Import Script Limit and Env Vars (#203)

Fix Import Script Limit and Env Vars (#203) #15

name: Build and Release Astro Import Script
on:
push:
tags:
- 'import/v*'
permissions:
contents: write
jobs:
build:
name: Build
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
matrix:
goos: [ linux, windows, darwin ]
goarch: [ amd64, arm64 ]
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
go-version-file: 'go.mod'
cache: true
- run: go mod download
- name: Get version
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/tags/import/}" >> $GITHUB_OUTPUT
- name: Build
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
run: |
output_name="terraform-provider-astro-import-script-${{ steps.get_version.outputs.VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }}"
if [ "${{ matrix.goos }}" = "windows" ]; then
output_name="${output_name}.exe"
fi
go build -o "${output_name}" ./import/import_script.go
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: binary-${{ matrix.goos }}-${{ matrix.goarch }}
path: terraform-provider-astro-import-script-*
if-no-files-found: warn
compression-level: 6
overwrite: false
include-hidden-files: false
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
go-version-file: 'go.mod'
cache: true
- run: go fmt ./import/import_script.go
- run: go vet ./import/import_script.go
- run: make validate-fmt
release:
name: Create Release
needs: [build, lint]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: binary-*
merge-multiple: true # This will merge all matching artifacts into one directory
- name: Get the version
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Generate Changelog
id: changelog
run: |
# Extract previous tag
PREVIOUS_TAG=$(git describe --tags --abbrev=0 $(git rev-list --tags --skip=1 --max-count=1))
# Generate changelog with PR numbers and authors in the desired format
CHANGELOG=$(git log ${PREVIOUS_TAG}..HEAD --pretty=format:"* %s by @%an in #%b" | \
sed -E 's/\(#[0-9]+\)//g' | \ # Remove PR numbers if they exist in commit message
sed -E 's/ */ /g' | \ # Clean up extra spaces
sed -E 's/ in #$//') # Remove trailing "in #" if no PR number
# Store changelog in output
echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_version.outputs.VERSION }}
release_name: Astro Import Script ${{ steps.get_version.outputs.VERSION }}
body: |
## What's Changed
${{ steps.changelog.outputs.CHANGELOG }}
For full changelog, see [here](https://github.com/${{ github.repository }}/compare/${{ env.PREVIOUS_TAG }}...${{ steps.get_version.outputs.VERSION }})
draft: false
prerelease: false
- name: Upload Release Assets
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs').promises;
const { repo: { owner, repo }, sha } = context;
const release = await github.rest.repos.getReleaseByTag({
owner,
repo,
tag: '${{ steps.get_version.outputs.VERSION }}'
});
const files = await fs.readdir('.');
for (const file of files) {
if (file.startsWith('terraform-provider-astro-import-script-')) {
await github.rest.repos.uploadReleaseAsset({
owner,
repo,
release_id: release.data.id,
name: file,
data: await fs.readFile(file)
});
}
}