Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
FalcoSuessgott committed Jul 8, 2024
1 parent 652f867 commit 89c6c32
Show file tree
Hide file tree
Showing 55 changed files with 2,987 additions and 1,344 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/notify-integration-release-via-manual.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Manual release workflow is used for deploying documentation updates
# on the specified branch without making an official plugin release.
name: Notify Integration Release (Manual)
on:
workflow_dispatch:
inputs:
version:
description: "The release version (semver)"
default: 1.0.0
required: false
branch:
description: "A branch or SHA"
default: 'main'
required: false
jobs:
notify-release:
runs-on: ubuntu-latest
steps:
- name: Checkout this repo
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
with:
ref: ${{ github.event.inputs.branch }}
# Ensure that Docs are Compiled
- uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
- shell: bash
run: make generate
- shell: bash
run: |
if [[ -z "$(git status -s)" ]]; then
echo "OK"
else
echo "Docs have been updated, but the compiled docs have not been committed."
echo "Run 'make generate', and commit the result to resolve this error."
exit 1
fi
# Perform the Release
- name: Checkout integration-release-action
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
with:
repository: hashicorp/integration-release-action
path: ./integration-release-action
- name: Notify Release
uses: ./integration-release-action
with:
# The integration identifier will be used by the Packer team to register the integration
# the expected format is packer/<GitHub Org Name>/<plugin-name>
integration_identifier: "packer/hashicorp/scaffolding"
release_version: ${{ github.event.inputs.version }}
release_sha: ${{ github.event.inputs.branch }}
github_token: ${{ secrets.GITHUB_TOKEN }}
54 changes: 54 additions & 0 deletions .github/workflows/notify-integration-release-via-tag.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Notify Integration Release (Tag)
on:
push:
tags:
- '*.*.*' # Proper releases
jobs:
strip-version:
runs-on: ubuntu-latest
outputs:
packer-version: ${{ steps.strip.outputs.packer-version }}
steps:
- name: Strip leading v from version tag
id: strip
env:
REF: ${{ github.ref_name }}
run: |
echo "packer-version=$(echo "$REF" | sed -E 's/v?([0-9]+\.[0-9]+\.[0-9]+)/\1/')" >> "$GITHUB_OUTPUT"
notify-release:
needs:
- strip-version
runs-on: ubuntu-latest
steps:
- name: Checkout this repo
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
with:
ref: ${{ github.ref }}
# Ensure that Docs are Compiled
- uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
- shell: bash
run: make generate
- shell: bash
run: |
if [[ -z "$(git status -s)" ]]; then
echo "OK"
else
echo "Docs have been updated, but the compiled docs have not been committed."
echo "Run 'make generate', and commit the result to resolve this error."
exit 1
fi
# Perform the Release
- name: Checkout integration-release-action
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
with:
repository: hashicorp/integration-release-action
path: ./integration-release-action
- name: Notify Release
uses: ./integration-release-action
with:
# The integration identifier will be used by the Packer team to register the integration
# the expected format is packer/<GitHub Org Name>/<plugin-name>
integration_identifier: "packer/hashicorp/scaffolding"
release_version: ${{ needs.strip-version.outputs.packer-version }}
release_sha: ${{ github.ref }}
github_token: ${{ secrets.GITHUB_TOKEN }}
20 changes: 17 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,28 @@ jobs:

steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: '1.21'
cache: false

- run: go generate -tags tools tools/tools.go

- uses: hashicorp/setup-packer@main

- run: |
make build
make install
packer plugin install github.com/hashicorp/docker
- name: go get
run: go get ./...

- name: Run tests
run: go test -v ./...
- name: unit tests
run: make test

- name: acc tests
run: make test-acc

- name: e2e tests
run: make test-e2e
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
example/packer_cache
.envrc
packer-plugin-goss
tests/debug-goss-spec.yaml
tests/goss-spec.yaml
tests/goss.json
e2e/debug-goss-spec.yaml
e2e/goss-spec.yaml
e2e/goss.json
34 changes: 34 additions & 0 deletions .golang-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
linters-settings:
lll:
line-length: 180
allow-leading-space: true
linters:
enable-all: true
disable:
- testpackage
- forbidigo
- paralleltest
- wrapcheck
- gochecknoglobals
- varnamelen
- funlen
- gomnd
- containedctx
- nlreturn
- wsl
- err113
- exhaustruct
- nolintlint
- maintidx
- dupl
- revive
- depguard
- tagalign
- perfsprint
- godox
- intrange
- copyloopvar
- gomoddirectives
- goconst
- godot
- execinquery
2 changes: 2 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ env:
- PACKER_PROTOCOL_VERSION=x5.0
before:
hooks:
- go generate -tags tools tools/tools.go
- go mod tidy
- go test ./...
- make plugin-check
builds:
-
id: plugin-check
Expand Down
14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
repos:
- repo: https://github.com/tekwizely/pre-commit-golang
rev: v1.0.0-rc.1
hooks:
- id: go-build-mod
- id: go-test-mod
- id: go-vet-mod
- id: go-staticcheck-mod
- id: go-fmt
- id: go-fumpt
- id: go-imports
- id: go-lint
- id: golangci-lint-mod
args: [-c.golang-ci.yml]
1 change: 1 addition & 0 deletions .web-docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# packer provisioner goss
45 changes: 45 additions & 0 deletions .web-docs/metadata.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

# Details on using this Integration template can be found at https://github.com/hashicorp/integration-template
# This metadata.hcl file and the adjacent `components` docs directory should
# be kept in a `.web-docs` directory at the root of your plugin repository.
integration {
name = "Integration Template"
description = "This is an integration template"
identifier = "packer/hashicorp/scaffolding"
flags = [
# Remove if the plugin does not conform to the HCP Packer requirements.
#
# Please refer to our docs if you want your plugin to be compatible with
# HCP Packer: https://developer.hashicorp.com/packer/docs/plugins/creation/hcp-support
"hcp-ready",
# This signals that the plugin is unmaintained and will eventually not be
# working with a future version of Packer.
#
# On the integrations, this will end-up as an icon on the plugin's main card.
"archived",
]
docs {
# If you'd prefer not to publish docs on HashiCorp websites, you can
# set `process_docs` to `false`. If `process_docs` is `false`, you MUST
# provide a `external_url` so we can link back to your plugin repo.
process_docs = true
# Note that the README location is relative to this file. We recommend
# keeping the default value, as the adjacent `compile-to-webdocs` script
# will automatically copy the README from the `docs` directory of this
# repository to the correct location.
readme_location = "./README.md"
# `external_url` allows us to link back to your plugin repo.
external_url = "https://github.com/hashicorp/integration-template"
}
license {
type = "MPL-2.0"
url = "https://github.com/hashicorp/integration-template/blob/main/LICENSE.md"
}
component {
type = "provisioner"
name = "Component Name (e.g HappyCloud Shell)"
slug = "name"
}
}
132 changes: 132 additions & 0 deletions .web-docs/scripts/compile-to-webdocs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#!/usr/bin/env bash
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0


# Converts the folder name that the component documentation file
# is stored in into the integration slug of the component.
componentTypeFromFolderName() {
if [[ "$1" = "builders" ]]; then
echo "builder"
elif [[ "$1" = "provisioners" ]]; then
echo "provisioner"
elif [[ "$1" = "post-processors" ]]; then
echo "post-processor"
elif [[ "$1" = "datasources" ]]; then
echo "data-source"
else
echo ""
fi
}

# $1: The content to adjust links
# $2: The organization of the integration
rewriteLinks() {
local result="$1"
local organization="$2"

urlSegment="([^/]+)"
urlAnchor="(#[^/]+)"

# Rewrite Component Index Page links to the Integration root page.
#
# (\1) (\2) (\3)
# /packer/plugins/datasources/amazon#anchor-tag-->
# /packer/integrations/hashicorp/amazon#anchor-tag
local find="\(\/packer\/plugins\/$urlSegment\/$urlSegment$urlAnchor?\)"
local replace="\(\/packer\/integrations\/$organization\/\2\3\)"
result="$(echo "$result" | sed -E "s/$find/$replace/g")"


# Rewrite Component links to the Integration component page
#
# (\1) (\2) (\3) (\4)
# /packer/plugins/datasources/amazon/parameterstore#anchor-tag -->
# /packer/integrations/{organization}/amazon/latest/components/datasources/parameterstore
local find="\(\/packer\/plugins\/$urlSegment\/$urlSegment\/$urlSegment$urlAnchor?\)"
local replace="\(\/packer\/integrations\/$organization\/\2\/latest\/components\/\1\/\3\4\)"
result="$(echo "$result" | sed -E "s/$find/$replace/g")"

# Rewrite the Component URL segment from the Packer Plugin format
# to the Integrations format
result="$(echo "$result" \
| sed "s/\/datasources\//\/data-source\//g" \
| sed "s/\/builders\//\/builder\//g" \
| sed "s/\/post-processors\//\/post-processor\//g" \
| sed "s/\/provisioners\//\/provisioner\//g" \
)"

echo "$result"
}

# $1: Docs Dir
# $2: Web Docs Dir
# $3: Component File
# $4: The org of the integration
processComponentFile() {
local docsDir="$1"
local webDocsDir="$2"
local componentFile="$3"

local escapedDocsDir="$(echo "$docsDir" | sed 's/\//\\\//g' | sed 's/\./\\\./g')"
local componentTypeAndSlug="$(echo "$componentFile" | sed "s/$escapedDocsDir\///g" | sed 's/\.mdx//g')"

# Parse out the Component Slug & Component Type
local componentSlug="$(echo "$componentTypeAndSlug" | cut -d'/' -f 2)"
local componentType="$(componentTypeFromFolderName "$(echo "$componentTypeAndSlug" | cut -d'/' -f 1)")"
if [[ "$componentType" = "" ]]; then
echo "Failed to process '$componentFile', unexpected folder name."
echo "Documentation for components must be stored in one of:"
echo "builders, provisioners, post-processors, datasources"
exit 1
fi


# Calculate the location of where this file will ultimately go
local webDocsFolder="$webDocsDir/components/$componentType/$componentSlug"
mkdir -p "$webDocsFolder"
local webDocsFile="$webDocsFolder/README.md"
local webDocsFileTmp="$webDocsFolder/README.md.tmp"

# Copy over the file to its webDocsFile location
cp "$componentFile" "$webDocsFile"

# Remove the Header
local lastMetadataLine="$(grep -n -m 2 '^\-\-\-' "$componentFile" | tail -n1 | cut -d':' -f1)"
cat "$webDocsFile" | tail -n +"$(($lastMetadataLine+2))" > "$webDocsFileTmp"
mv "$webDocsFileTmp" "$webDocsFile"

# Remove the top H1, as this will be added automatically on the web
cat "$webDocsFile" | tail -n +3 > "$webDocsFileTmp"
mv "$webDocsFileTmp" "$webDocsFile"

# Rewrite Links
rewriteLinks "$(cat "$webDocsFile")" "$4" > "$webDocsFileTmp"
mv "$webDocsFileTmp" "$webDocsFile"
}

# Compiles the Packer SDC compiled docs folder down
# to a integrations-compliant folder (web docs)
#
# $1: The directory of the plugin
# $2: The directory of the SDC compiled docs files
# $3: The output directory to place the web-docs files
# $4: The org of the integration
compileWebDocs() {
local docsDir="$1/$2"
local webDocsDir="$1/$3"

echo "Compiling MDX docs in '$2' to Markdown in '$3'..."
# Create the web-docs directory if it hasn't already been created
mkdir -p "$webDocsDir"

# Copy the README over
cp "$docsDir/README.md" "$webDocsDir/README.md"

# Process all MDX component files (exclude index files, which are unsupported)
for file in $(find "$docsDir" | grep "$docsDir/.*/.*\.mdx" | grep --invert-match "index.mdx"); do
processComponentFile "$docsDir" "$webDocsDir" "$file" "$4"
done
}

compileWebDocs "$1" "$2" "$3" "$4"
Loading

0 comments on commit 89c6c32

Please sign in to comment.