Sync Examples From Provider #18
This file contains hidden or 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: Sync Examples From Provider | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 0 * * 5' | |
jobs: | |
Sync: | |
if: github.repository_owner == 'alibabacloud-automation' | |
runs-on: ubuntu-latest | |
permissions: write-all | |
steps: | |
- name: checkout | |
uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Download Terraform & Terraform-docs | |
run: | | |
if [ ! -f /usr/local/bin/terraform ]; then | |
wget -q https://releases.hashicorp.com/terraform/1.6.0/terraform_1.6.0_linux_amd64.zip | |
unzip terraform_1.6.0_linux_amd64.zip -d /usr/local/bin/ | |
fi | |
mkdir terraform-docs && cd terraform-docs | |
curl -sSLo ./terraform-docs.tar.gz https://terraform-docs.io/dl/v0.19.0/terraform-docs-v0.19.0-$(uname)-amd64.tar.gz | |
tar -xzf terraform-docs.tar.gz | |
chmod +x terraform-docs | |
sudo mv terraform-docs /usr/local/bin/ | |
cd .. | |
rm -rf terraform-docs | |
terraform-docs version | |
- name: sync examples | |
id: sync_examples | |
run: | | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git config --global user.name "github-actions[bot]" | |
latestVersion=$(curl -s https://api.github.com/repos/aliyun/terraform-provider-alicloud/releases/latest) | |
published_date=$(echo $latestVersion | jq '.published_at') | |
version=$(echo $latestVersion | jq '.tag_name') | |
echo "version=${version//\"/}" >> $GITHUB_OUTPUT | |
published_timestamp=$(date -d ${published_date//\"/} +%s) | |
current_time=$(date +%s) | |
time_diff=$(( (current_time - published_timestamp) / (60*60*24) )) | |
if [ "$time_diff" -gt 7 ]; then | |
echo "no update" | |
echo "update=false" >> $GITHUB_OUTPUT | |
else | |
git clone -b ${version//\"/} https://github.com/aliyun/terraform-provider-alicloud.git terraform-provider-alicloud | |
go run scripts/sync_examples_from_provider.go ${version//\"/} | |
bash scripts/doc-generate.sh quickstarts >> /dev/null | |
rm -rf terraform-provider-alicloud | |
echo "update=true" >> $GITHUB_OUTPUT | |
fi | |
- name: Commit & Push changes | |
if: steps.sync_examples.outputs.update == 'true' | |
uses: actions-js/push@master | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
message: 'sync examples from Provider ${{ steps.sync_examples.outputs.version }}' | |
branch: main | |