Skip to content

Commit

Permalink
use goreleaser v1.26.2
Browse files Browse the repository at this point in the history
  • Loading branch information
chengxiangdong committed Jun 29, 2024
1 parent 474d912 commit 3be6f80
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 215 deletions.
252 changes: 38 additions & 214 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
@@ -1,223 +1,47 @@
# This is a basic workflow to help you get started with Actions

name: pre-release

# Controls when the workflow will run
# This GitHub action can publish assets for release when a tag is created.
# Currently its setup to run on any tag that matches the pattern "v*" (ie. v0.1.0).
#
# This uses an action (paultyng/ghaction-import-gpg) that assumes you set your
# private key in the `GPG_PRIVATE_KEY` secret and passphrase in the `PASSPHRASE`
# secret. If you would rather own your own GPG handling, please fork this action
# or use an alternative one for key handling.
#
# You will need to pass the `--batch` flag to `gpg` in your signing step
# in `goreleaser` to indicate this is being used in a non-interactive mode.
#
name: release
on:
push:
branches: [ master ]
paths:
- 'CHANGELOG.md'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
tags:
- 'v*'
jobs:
scan-api:
# The type of runner that the job will run on
goreleaser:
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
# /home/runner/work/terraform-provider-huaweicloudstack/terraform-provider-huaweicloudstack
- uses: actions/checkout@v3
with:
path: terraform-provider-huaweicloudstack

- uses: actions/checkout@v3
with:
repository: chnsz/terraform-provider-generator
token: ${{ secrets.REVIEWDOG_TOKEN }}
path: terraform-provider-generator

- uses: actions/checkout@v3
with:
repository: chnsz/terraform-api-scan
token: ${{ secrets.REVIEWDOG_TOKEN }}
path: terraform-api-scan

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ">=1.18"

- name: Get the provider release version
run: |
version=$(head -n 4 terraform-provider-hcs/CHANGELOG.md | grep "^## " | awk '{printf "v%s", $2}')
echo "VERSION=$version" >> $GITHUB_ENV
- name: Build Terraform Provider
run: |
cd terraform-provider-hcs
make build FLAGS='-mod=readonly'
cd ..
- name: export schemas for the providers
env:
TF_CLI_CONFIG_FILE: ${{ github.workspace }}/hw_dev.tfrc
run: |
cat>${{ github.workspace }}/hw_dev.tfrc<<EOF
provider_installation {
dev_overrides {
"huaweicloud/hcs" = "/home/runner/go/bin"
}
direct {}
}
EOF
cd terraform-api-scan
terraform init
terraform providers schema -json > schema.json
cd ..
- name: parse APIs that golangsdk/go-SDK resources depend-on
run: |
cp terraform-api-scan/*.go terraform-provider-hcs/
subPackPath="/huaweicloud"
providerSchemaPath="../terraform-api-scan/schema.json"
cd terraform-provider-hcs
rm -rf docs/api
mkdir docs/api
go run *.go -basePath=./ -outputDir=docs/api/ -providerSchemaPath=${providerSchemaPath}
# terraform-api-scan can not copy static yaml files in workflow, do it manually
cp ../terraform-api-scan/config/static/*.yaml docs/api/
cd ..
- name: parse APIs that auto-generated resources depend-on
run: |
cd terraform-api-scan/scan-autogen-code
go run main.go -inputDir=../../terraform-provider-generator/src/main/resources -outputDir=../../terraform-provider-hcs/docs/api -providerSchemaPath=../schema.json
cd ../../
- name: commit APIs that resources depend-on
uses: stefanzweifel/git-auto-commit-action@v4
with:
repository: terraform-provider-huaweicloudstack
file_pattern: 'docs/api/*.yaml'
commit_message: Update APIs that resources depend-on ${{ env.VERSION }}

generate-schema:
if: ${{ always() }}
needs: scan-api

runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ">=1.18"

# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
# /home/runner/work/terraform-provider-huaweicloudstack/terraform-provider-huaweicloudstack
- uses: actions/checkout@v3
with:
path: terraform-provider-huaweicloudstack
ref: master

- uses: actions/checkout@v3
with:
repository: chnsz/huaweicloudstack-provider-json
token: ${{ secrets.REVIEWDOG_TOKEN }}
path: huaweicloudstack-provider-json

- name: import the latest codes of provider and build
run: |
cd huaweicloud-provider-json
go get github.com/huaweicloud/terraform-provider-hcs@master
go build -o generate-schemas
cp ./generate-schemas ../terraform-provider-hcs
cd ..
- name: generate-schema
shell: bash {0}
run: |
cd terraform-provider-hcs
target="./docs/json"
rm -rf $target
echo -e "\ntry to update the product config file..."
./generate-schemas -product
if [ $? -ne 0 ]; then
echo "[WARN] failed to update the product config file, using the existing one!"
fi
echo -e "\ntry to update the resource schema files..."
./generate-schemas -r -name="all" -output-dir=$target
echo -e "\ntry to update the data source schema files..."
./generate-schemas -d -name="all" -output-dir=$target
rm -f $target/data-sources/vpc_route.json
rm -f $target/resources/networking_port.json
- name: Get the provider release version
run: |
version=$(head -n 4 terraform-provider-hcs/CHANGELOG.md | grep "^## " | awk '{printf "v%s", $2}')
echo "VERSION=$version" >> $GITHUB_ENV
- name: auto-commit
uses: stefanzweifel/git-auto-commit-action@v4
with:
repository: terraform-provider-huaweicloudstack
file_pattern: 'docs/json/'
commit_message: Update schema json files based-on ${{ env.VERSION }}

acc-test:
if: ${{ always() }}
needs: [scan-api, generate-schema]

env:
HCS_ACCESS_KEY: ${{ secrets.HCS_ACCESS_KEY }}
HCS_SECRET_KEY: ${{ secrets.HCS_SECRET_KEY }}
HCS_DOMAIN_NAME: ${{ secrets.HCS_DOMAIN_NAME }}
HCS_REGION_NAME: cn-north-4
HCS_ADMIN: "true"
HCS_ENTERPRISE_PROJECT_ID: "0"
HCS_ENTERPRISE_PROJECT_ID_TEST: "0"

runs-on: ubuntu-latest
steps:
- name: Checkout
-
name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Go
-
name: Unshallow
run: git fetch --prune --unshallow
-
name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ">=1.18"

# run acceptance test
- name: Run acceptance basic test
# run the step only when HCS_ACCESS_KEY is setted
if: ${{ env.HCS_ACCESS_KEY }}
shell: bash {0}
run: |
result=0
total=0
last_tag=$(git tag --sort=-creatordate | sed -n 1p)
all_files=$(git diff $last_tag --name-only huaweicloud | grep -v "_test.go")
echo -e "the following files have changed since $last_tag:\n$all_files\n"
for f in $all_files; do
path=${f%/*}
if [ "X$path" != "Xhuaweicloud" ]; then
# update path to "huaweicloud/services/acceptance/xxx"
path=${path/"services"/"services/acceptance"}
fi
org_file=${f##*/}
test_file=$path/${org_file/%.go/_test.go}
if [ -f "./${test_file}" ]; then
basic_case=$(grep "^func TestAcc" ./${test_file} | grep _basic | awk 'NR==1{print $2}' | awk -F '(' '{print $1}')
if [ "X$basic_case" != "X" ]; then
total=`expr $total + 1`
echo -e "\n[$total] `date` run acceptance basic test: $basic_case"
make testacc TEST="./$path" TESTARGS="-run ${basic_case}"
if [ $? -ne 0 ]; then
result=`expr $result + 1`
fi
fi
else
echo -e "\n[skipped] --- ./${test_file} does not exist"
fi
done
echo -e "\n[summary] $result failed in $total acceptance basic tests"
exit $result
-
name: Import GPG key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v5
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
version: v1.26.2
args: release --clean
env:
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* The new resources and data sources added in the new version are as follows:

* **New Resources:**
+ `hcs_backup`
+ `hcs_dcs_backup`
+ `hcs_dcs_instance`
+ `hcs_swr_image_retention_policy`
+ `hcs_swr_image_trigger`
Expand Down

0 comments on commit 3be6f80

Please sign in to comment.