diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml new file mode 100644 index 0000000..6756a4e --- /dev/null +++ b/.github/workflows/cancel.yml @@ -0,0 +1,26 @@ +name: Cancel Dispatch + +on: + repository_dispatch: + types: [cancel-command] +jobs: + promote-release: + runs-on: ubuntu-latest + steps: + - name: Set Env Variables + id: env_info + run: | + ISSUE_TITLE=$(jq -r .client_payload.github.payload.issue.title $GITHUB_EVENT_PATH) + echo ::set-output name=issuetitle::$ISSUE_TITLE + echo ::set-output name=issuenm::$(jq .client_payload.github.payload.issue.number $GITHUB_EVENT_PATH) + echo ::set-output name=requestor::$(jq -r .client_payload.github.actor $GITHUB_EVENT_PATH) + - name: Delete branch + uses: dawidd6/action-delete-branch@v3 + with: + github_token: ${{ github.token }} + branches: ${{ steps.env_info.outputs.issuetitle }} + - name: Close Issue + uses: peter-evans/close-issue@v1 + with: + issue-number: ${{ steps.env_info.outputs.issuenm }} + comment: Cancelling rollout as requested by @${{ steps.env_info.outputs.requestor }}. diff --git a/.github/workflows/chat-ops.yml b/.github/workflows/chat-ops.yml new file mode 100644 index 0000000..71114cb --- /dev/null +++ b/.github/workflows/chat-ops.yml @@ -0,0 +1,15 @@ +name: Chat Ops + +on: + issue_comment: + types: [created] + +jobs: + launcher: + runs-on: ubuntu-latest + steps: + - name: Command Dispatch + uses: peter-evans/slash-command-dispatch@v2 + with: + token: ${{ secrets.ACTIONS_TOKEN }} + commands: release, release-rc, promote, cancel, finish diff --git a/.github/workflows/finish.yml b/.github/workflows/finish.yml new file mode 100644 index 0000000..7b615b5 --- /dev/null +++ b/.github/workflows/finish.yml @@ -0,0 +1,26 @@ +name: Finish Dispatch + +on: + repository_dispatch: + types: [finish-command] +jobs: + promote-release: + runs-on: ubuntu-latest + steps: + - name: Set Env Variables + id: env_info + run: | + ISSUE_TITLE=$(jq -r .client_payload.github.payload.issue.title $GITHUB_EVENT_PATH) + echo ::set-output name=issuetitle::$ISSUE_TITLE + echo ::set-output name=issuenm::$(jq .client_payload.github.payload.issue.number $GITHUB_EVENT_PATH) + echo ::set-output name=requestor::$(jq -r .client_payload.github.actor $GITHUB_EVENT_PATH) + - name: Delete branch + uses: dawidd6/action-delete-branch@v3 + with: + github_token: ${{ github.token }} + branches: ${{ steps.env_info.outputs.issuetitle }} + - name: Close Issue + uses: peter-evans/close-issue@v1 + with: + issue-number: ${{ steps.env_info.outputs.issuenm }} + comment: Rollout finished by @${{ steps.env_info.outputs.requestor }} - closing issue. diff --git a/.github/workflows/promote.yml b/.github/workflows/promote.yml new file mode 100644 index 0000000..641511c --- /dev/null +++ b/.github/workflows/promote.yml @@ -0,0 +1,81 @@ +name: Promote Dispatch + +on: + repository_dispatch: + types: [promote-command] +jobs: + promote-release: + runs-on: ubuntu-latest + steps: + - name: Set Env Variables + id: env_info + run: | + echo ::set-output name=issuetitle::$(jq -r .client_payload.github.payload.issue.title $GITHUB_EVENT_PATH) + echo ::set-output name=issuenm::$(jq .client_payload.github.payload.issue.number $GITHUB_EVENT_PATH) + echo ::set-output name=labels::$(jq .client_payload.github.payload.issue.labels $GITHUB_EVENT_PATH) + echo ::set-output name=requestor::$(jq .client_payload.github.actor $GITHUB_EVENT_PATH) + - name: Set New Env (Integration) + if: ${{ !contains(steps.env_info.outputs.labels, 'promoted to integration') }} + run: | + echo "NEW_ENV=integration" >> $GITHUB_ENV + - name: Set New Env (Production) + if: ${{ contains(steps.env_info.outputs.labels, 'promoted to integration') }} + run: | + echo "NEW_ENV=production" >> $GITHUB_ENV + - uses: actions/checkout@v3 + with: + ref: ${{ steps.env_info.outputs.issuetitle }} + - name: GitHub Pull Request Action + id: create_pr + uses: repo-sync/pull-request@v2.6.2 + with: + source_branch: ${{ steps.env_info.outputs.issuetitle }} + destination_branch: ${{ env.NEW_ENV }} + github_token: ${{ secrets.GITHUB_TOKEN }} + pr_title: "Promoting ${{ steps.env_info.outputs.issuetitle }} to ${{ env.NEW_ENV }}" + pr_body: "Promoting release ${{ steps.env_info.outputs.issuetitle }} to the $NEW_ENV environment as requested by @${{ steps.env_info.outputs.requestor }}." + - name: Get PR number + id: pr_num + run: | + echo ::set-output name=prnm::$( echo ${{ steps.create_pr.outputs.pr_url }} | awk -F'/' '{print $NF}') + # - name: Auto-merge + # uses: actions/github-script@v2 + # with: + # github-token: ${{ secrets.GITHUB_TOKEN }} + # script: | + # github.pulls.merge({ + # owner: context.repo.owner, + # repo: context.repo.repo, + # pull_number: ${{ steps.pr_num.outputs.prnm}}, + # merge_method: "squash" + # }) + - name: Apply label to issue + uses: actions/github-script@v1 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + github.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: ${{steps.env_info.outputs.issuenm}}, + labels: ["promoted to ${{ env.NEW_ENV }}"] + }) + - name: Create comment + uses: peter-evans/create-or-update-comment@v1 + with: + repository: ${{ github.event.client_payload.github.payload.repository.full_name }} + issue-number: "${{ steps.env_info.outputs.issuenm }}" + body: | + Promoted release ${{ steps.env_info.outputs.issuetitle }} to ${{ env.NEW_ENV }}! + # - name: Delete branch + # if: ${{ env.NEW_ENV == 'production' }} + # uses: dawidd6/action-delete-branch@v3 + # with: + # github_token: ${{ github.token }} + # branches: ${{ steps.env_info.outputs.issuetitle }} + # - name: Close Issue + # if: ${{ env.NEW_ENV == 'production' }} + # uses: peter-evans/close-issue@v1 + # with: + # issue-number: ${{ steps.env_info.outputs.issuenm }} + # comment: Rollout completed by ${{ steps.env_info.outputs.requestor }} - closing issue. diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..5f255c3 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,143 @@ +name: Release Dispatch + +on: + repository_dispatch: + types: [release-command] +jobs: + create-release-branch: + runs-on: ubuntu-latest + steps: + - name: Get Environment Info + id: env_info + run: | + ISSUE_TITLE=$(jq -r .client_payload.github.payload.issue.title $GITHUB_EVENT_PATH) + echo ::set-output name=release::$(git ls-remote --heads https://github.com/$GITHUB_REPOSITORY $ISSUE_TITLE) + echo ::set-output name=issuenm::$(jq .client_payload.github.payload.issue.number $GITHUB_EVENT_PATH) + echo ::set-output name=issuetitle::$ISSUE_TITLE + + - name: Create Release Branch + uses: peterjgrainger/action-create-branch@v1.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + branch: "${{ steps.env_info.outputs.issuetitle }}" + if: ${{ steps.env_info.outputs.release == null }} + + - name: Alert that release already exists + run: | + echo "Release branch ${{ steps.env_info.outputs.issuetitle }} already exists. Skipping..." + if: ${{ steps.env_info.outputs.release != null }} + + - name: Check if label exists + uses: actions/github-script@v1 + id: label_check + continue-on-error: true + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + github.issues.getLabel({ + owner: context.repo.owner, + repo: context.repo.repo, + name: "${{ steps.env_info.outputs.issuetitle }}" + }) + + - name: Create label to be used for release + uses: actions/github-script@v1 + id: create_label + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + github.issues.createLabel({ + owner: context.repo.owner, + repo: context.repo.repo, + name: "${{ steps.env_info.outputs.issuetitle }}", + color: "2d5893" + }) + if: ${{ steps.label_check.outcome == 'failure' }} + + - name: Apply label to issue + uses: actions/github-script@v1 + if: ${{ steps.create_label.outcome == 'success' }} + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + github.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: ${{steps.env_info.outputs.issuenm}}, + labels: ["${{ steps.env_info.outputs.issuetitle }}"] + }) + + update-release-pointers: + runs-on: ubuntu-latest + needs: create-release-branch + env: + URL: ${{ secrets.RELEASE_NOTIFICATON_URL }} + + ## String to match for ImageTag replacement where applicable + ImageTagMatchString: 'imageTag:.*' + + ## End-to-End (E2E) testing - match string and replacement string + e2eTestMatchString: 'enabled: true' + e2eDisableReplacementString: 'enabled: false' + + + ## LodeStar Overall Version String - value obtained at runtime + Versions_LodeStarMatchString: 'lodestar:.*' + + + steps: + - name: Get Environment Info + id: env_info + run: | + ISSUE_TITLE=$(jq -r .client_payload.github.payload.issue.title $GITHUB_EVENT_PATH) + echo ::set-output name=issuetitle::$ISSUE_TITLE + echo ::set-output name=issuenm::$(jq .client_payload.github.payload.issue.number $GITHUB_EVENT_PATH) + echo ::set-output name=comment_url::$(jq .client_payload.github.payload.comment.html_url $GITHUB_EVENT_PATH) + echo ::set-output name=lodestarVersion::"lodestar: ${ISSUE_TITLE}" + + - uses: actions/checkout@v2 + with: + ref: ${{ steps.env_info.outputs.issuetitle }} + + - name: Commit Release Changes + uses: stefanzweifel/git-auto-commit-action@v4 + with: + branch: "${{ steps.env_info.outputs.issuetitle }}" + commit_message: "Merging changes requested from ${{ steps.env_info.outputs.comment_url }}" + + # - name: 'Get Previous tag' + # id: previoustag + # uses: actions-ecosystem/action-get-latest-tag@v1 + + - name: Fetch Previous Release Info + id: previous_release + uses: pozetroninc/github-action-get-latest-release@master + with: + repository: rht-labs/lodestar-deployment + + - name: Generate Release Body + id: release_body + run: | + echo ::set-output name=text::$(git log ${{ steps.previous_release.outputs.release }}..HEAD --pretty=format:"- %h %s by %an" --no-merges) + + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token + with: + tag_name: ${{ steps.env_info.outputs.issuetitle }} + release_name: ${{ steps.env_info.outputs.issuetitle }} + body: ${{ steps.release_body.outputs.text }} + draft: false + prerelease: false + + - name: Create Release Comment + uses: peter-evans/create-or-update-comment@v1 + with: + repository: ${{ github.event.client_payload.github.payload.repository.full_name }} + issue-number: "${{ steps.env_info.outputs.issuenm }}" + body: | + Created release ${{ steps.env_info.outputs.issuetitle }}! +