-
Notifications
You must be signed in to change notification settings - Fork 73
workflow updates to handle unified docs #316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
chrisroberts
wants to merge
1
commit into
main
Choose a base branch
from
unified-docs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| name: New Unified Docs Version | ||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| branch: | ||
| description: Vagrant documentation branch | ||
| type: string | ||
| default: vagrant/2.x | ||
| required: true | ||
| new-version: | ||
| description: New Vagrant version | ||
| type: string | ||
| required: true | ||
| previous-version: | ||
| description: Previous Vagrant version | ||
| type: string | ||
| required: true | ||
| workflow_dispatch: | ||
| inputs: | ||
| branch: | ||
| description: Vagrant documentation branch | ||
| type: string | ||
| default: vagrant/2.x | ||
| required: true | ||
| new-version: | ||
| description: New Vagrant version | ||
| type: string | ||
| required: true | ||
| previous-version: | ||
| description: Previous Vagrant version | ||
| type: string | ||
| required: true | ||
|
|
||
| jobs: | ||
| create-new-version: | ||
| runs-on: ['self-hosted', 'ondemand', 'linux', 'type=t3.small'] | ||
| if: github.repository == 'hashicorp/vagrant-builders' | ||
| continue-on-error: true | ||
| permissions: | ||
| contents: write | ||
| id-token: write | ||
| steps: | ||
| - name: Secrets | ||
| id: secrets | ||
| uses: hashicorp/vault-action@v2 | ||
| with: | ||
| url: ${{ steps.vault-auth.outputs.addr }} | ||
| caCertificate: ${{ steps.vault-auth.outputs.ca_certificate }} | ||
| token: ${{ steps.vault-auth.outputs.token }} | ||
| secrets: | ||
| kv/data/teams/vagrant/hashibot unified_docs_token; | ||
| - name: Checkout local | ||
| uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | ||
| with: | ||
| path: local | ||
| - name: Checkout unified docs | ||
| uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | ||
| with: | ||
| repository: hashicorp/web-unified-docs | ||
| token: ${{ steps.secrets.outputs.unified_docs_token }} | ||
| path: docs | ||
| - name: Create directory | ||
| env: | ||
| VERSION: ${{ inputs.new-version }} | ||
| PREVIOUS_VERSION: ${{ inputs.previous-version }} | ||
| BRANCH: ${{ inputs.branch }} | ||
| GITHUB_TOKEN: ${{ steps.secrets.outputs.unified_docs_token }} | ||
| HASHIBOT_USERNAME: ${{ vars.HASHIBOT_USERNAME }} | ||
| HASHIBOT_EMAIL: ${{ vars.HASHIBOT_EMAIL }} | ||
| run: | | ||
| source local/.ci/load.sh | ||
| pushd docs || exit | ||
| export repository="hashicorp/web-unified-docs | ||
| hashibot_git | ||
|
|
||
| # Ensure versions have a v prefix | ||
| test "${VERSION:0:1}" != "v" && VERSION="v${VERSION}" | ||
| test "${PREVIOUS_VERSION:0:1}" != "v" && PREVIOUS_VERSION="v${PREVIOUS_VERSION}" | ||
|
|
||
| git checkout "${BRANCH}" || exit | ||
| pushd content/vagrant || exit | ||
|
|
||
| # If the version directory already exists, do nothing | ||
| if ls "${VERSION}" > /dev/null 2>&1; then | ||
| echo "Directory already exists, stopping" | ||
| exit | ||
| fi | ||
|
|
||
| mkdir "${VERSION}" || exit | ||
| cp -r "./${PREVIOUS_VERSION}/." "./${VERSION}/." || exit | ||
|
|
||
| git add "./${VERSION}" || exit | ||
| git status | ||
| git commit -m "Add Vagrant version ${VERSION}" || exit | ||
| git push origin | ||
| failure: | ||
| runs-on: ['self-hosted', 'ondemand', 'linux', 'type=t3.small'] | ||
| if: ${{ github.repository == 'hashicorp/vagrant-builders' && failure() }} | ||
| needs: [create-new-version] | ||
| permissions: | ||
| contents: write | ||
| id-token: write | ||
| steps: | ||
| - name: Secrets | ||
| id: secrets | ||
| uses: hashicorp/vault-action@v2 | ||
| with: | ||
| url: ${{ steps.vault-auth.outputs.addr }} | ||
| caCertificate: ${{ steps.vault-auth.outputs.ca_certificate }} | ||
| token: ${{ steps.vault-auth.outputs.token }} | ||
| secrets: | ||
| kv/data/teams/vagrant/hashibot webhook; | ||
| - name: Code Checkout | ||
| uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | ||
| - name: Send Notification | ||
| run: | | ||
| . .ci/load-ci.sh || exit | ||
| slack -m "$(printf "Vagrant unified doc new version creation failed\n\n- <%s|%s>" "${WORKFLOW_URL}" "${WORKFLOW_NAME}")" | ||
| env: | ||
| SLACK_WEBHOOK: ${{ steps.secrets.outputs.webhook }} | ||
| SLACK_CHANNEL: '#feed-vagrant' | ||
| SLACK_USERNAME: Vagrant Bot | ||
| SLACK_TITLE: Vagrant Unified Documentation | ||
| SLACK_STATE: error | ||
| WORKFLOW_NAME: ${{ github.event.workflow_run.name }} | ||
| WORKFLOW_URL: ${{ github.event.workflow_run.html_url }} | ||
|
|
||
|
|
||
|
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| name: Generate Unified Docs PR | ||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| branch: | ||
| description: Vagrant documentation branch | ||
| type: string | ||
| default: vagrant/2.x | ||
| required: true | ||
| target: | ||
| description: Target for PR | ||
| type: string | ||
| default: main | ||
| required: true | ||
| release-tag: | ||
| description: Tag for Vagrant release | ||
| type: string | ||
| required: true | ||
| version: | ||
| description: Version for Vagrant release | ||
| type: string | ||
| required: true | ||
| workflow_call: | ||
| inputs: | ||
| branch: | ||
| description: Vagrant documentation branch | ||
| type: string | ||
| default: vagrant/2.x | ||
| required: true | ||
| target: | ||
| description: Target for PR | ||
| type: string | ||
| default: main | ||
| required: true | ||
| release-tag: | ||
| description: Tag for Vagrant release | ||
| type: string | ||
| required: true | ||
| version: | ||
| description: Version for Vagrant release | ||
| type: string | ||
| required: true | ||
| outputs: | ||
| pr-url: | ||
| description: URL of unified docs PR | ||
| value: ${{ jobs.create-pr.outputs.url }} | ||
|
|
||
| jobs: | ||
| create-pr: | ||
| runs-on: ['self-hosted', 'ondemand', 'linux', 'type=t3.small'] | ||
| if: github.repository == 'hashicorp/vagrant-builders' | ||
| permissions: | ||
| id-token: write | ||
| contents: read | ||
| outputs: | ||
| url: ${{ steps.pr.outputs.url }} | ||
| steps: | ||
| - name: Authentication | ||
| id: vault-auth | ||
| run: vault-auth | ||
| - name: Secrets | ||
| id: secrets | ||
| uses: hashicorp/vault-action@v2 | ||
| with: | ||
| url: ${{ steps.vault-auth.outputs.addr }} | ||
| caCertificate: ${{ steps.vault-auth.outputs.ca_certificate }} | ||
| token: ${{ steps.vault-auth.outputs.token }} | ||
| secrets: | ||
| kv/data/teams/vagrant/hashibot unified_docs_token; | ||
| - name: Checkout unified docs | ||
| uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | ||
| with: | ||
| repository: hashicorp/web-unified-docs | ||
| token: ${{ steps.secrets.outputs.unified_docs_token }} | ||
| - name: Release branch | ||
| env: | ||
| BRANCH: ${{ inputs.branch }} | ||
| RELEASE_BRANCH: release/vagrant-${{ inputs.release-tag }} | ||
| run: | | ||
| test "origin/${RELEASE_BRANCH}" = "$(git branch -r --list "origin/${RELEASE_BRANCH}" --format "%(refname:short)")" && exit | ||
| git checkout "${BRANCH}" || exit | ||
| git checkout -b "${RELEASE_BRANCH}" | ||
| - name: Create PR | ||
| id: pr | ||
| env: | ||
| GITHUB_TOKEN: ${{ steps.secrets.outputs.unified_docs_token }} | ||
| head: release/vagrant-${{ inputs.release-tag }} | ||
| base: ${{ inputs.target }} | ||
| title: "[PUBLISH] Vagrant release ${{ inputs.release-tag }}" | ||
| body: | | ||
| Vagrant release documentation publication. | ||
|
|
||
| **Vagrant tag**: \`${{ inputs.release-tag }}\` | ||
| **Vagrant version**: \`${{ inputs.version }}\` | ||
| run: | | ||
| pr_url="$(gh pr create --base "${base}" --head "${head}" --title "${title}" --body "${body") || exit | ||
| printf "url=%s\n" "${pr_url}" >> "${GITHUB_OUTPUT}" | ||
| printf "PR: %s\n" "${pr_url}" | ||
| notify: | ||
| runs-on: ['self-hosted', 'ondemand', 'linux', 'type=t3.small'] | ||
| if: github.repository == 'hashicorp/vagrant-builders' | ||
| needs: [create-pr] | ||
| permissions: | ||
| contents: write | ||
| id-token: write | ||
| steps: | ||
| - name: Secrets | ||
| id: secrets | ||
| uses: hashicorp/vault-action@v2 | ||
| with: | ||
| url: ${{ steps.vault-auth.outputs.addr }} | ||
| caCertificate: ${{ steps.vault-auth.outputs.ca_certificate }} | ||
| token: ${{ steps.vault-auth.outputs.token }} | ||
| secrets: | ||
| kv/data/teams/vagrant/slack webhook; | ||
| - name: Code Checkout | ||
| uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | ||
| - name: Send Notification | ||
| run: | | ||
| . .ci/load-ci.sh || exit | ||
| slack -m "$(printf "Vagrant unified documentation pull request generated (@vagrant)\n\n- <%s|Approve and merge>" "${PR_URL}")" | ||
| env: | ||
| SLACK_WEBHOOK: ${{ steps.secrets.outputs.webhook }} | ||
| SLACK_CHANNEL: '#feed-vagrant' | ||
| SLACK_USERNAME: Vagrant Release Process | ||
| SLACK_TITLE: Vagrant Unified Documentation | ||
| SLACK_STATE: warn | ||
| PR_URL: ${{ needs.create-pr.outputs.url }} | ||
|
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium
Copilot Autofix
AI 8 months ago
To fix this problem, you should add an explicit
permissionsblock to thenext-versionjob in.github/workflows/release.yml, minimizing the permissions to the least privilege necessary. Based on the job's actions (simple calculation and exporting an output), there is no indication that it needs any elevated permissions, so the minimal block should bepermissions: contents: read. This will ensure that the GITHUB_TOKEN for this job only has read access to repository contents and cannot perform any write actions. No methods, additional imports, or other definitions are needed; only an update to the job definition in the YAML workflow file is required.