|
| 1 | +name: "2. CI/CD publish" |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + |
| 6 | + |
| 7 | +jobs: |
| 8 | + metadata: |
| 9 | + name: "Set CI/CD metadata" |
| 10 | + runs-on: ubuntu-latest |
| 11 | + timeout-minutes: 1 |
| 12 | + outputs: |
| 13 | + build_datetime_london: ${{ steps.variables.outputs.build_datetime_london }} |
| 14 | + build_datetime: ${{ steps.variables.outputs.build_datetime }} |
| 15 | + build_timestamp: ${{ steps.variables.outputs.build_timestamp }} |
| 16 | + build_epoch: ${{ steps.variables.outputs.build_epoch }} |
| 17 | + nodejs_version: ${{ steps.variables.outputs.nodejs_version }} |
| 18 | + python_version: ${{ steps.variables.outputs.python_version }} |
| 19 | + terraform_version: ${{ steps.variables.outputs.terraform_version }} |
| 20 | + version: ${{ steps.variables.outputs.version }} |
| 21 | + is_version_prerelease: ${{ steps.variables.outputs.is_version_prerelease }} |
| 22 | + does_pull_request_exist: ${{ steps.pr_exists.outputs.does_pull_request_exist }} |
| 23 | + pr_number: ${{ steps.pr_exists.outputs.pr_number }} |
| 24 | + steps: |
| 25 | + - name: "Checkout code" |
| 26 | + uses: actions/checkout@v5 |
| 27 | + - name: "Set CI/CD variables" |
| 28 | + id: variables |
| 29 | + run: | |
| 30 | + datetime=$(date -u +'%Y-%m-%dT%H:%M:%S%z') |
| 31 | + BUILD_DATETIME=$datetime make version-create-effective-file dir=. |
| 32 | + version=$(head -n 1 .version 2> /dev/null || echo unknown) |
| 33 | + echo "build_datetime_london=$(TZ=Europe/London date --date=$datetime +'%Y-%m-%dT%H:%M:%S%z')" >> $GITHUB_OUTPUT |
| 34 | + echo "build_datetime=$datetime" >> $GITHUB_OUTPUT |
| 35 | + echo "build_timestamp=$(date --date=$datetime -u +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT |
| 36 | + echo "build_epoch=$(date --date=$datetime -u +'%s')" >> $GITHUB_OUTPUT |
| 37 | + echo "nodejs_version=$(grep "^nodejs\s" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT |
| 38 | + echo "python_version=$(grep "^python\s" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT |
| 39 | + echo "terraform_version=$(grep "^terraform\s" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT |
| 40 | + echo "version=$(echo $version)" >> $GITHUB_OUTPUT |
| 41 | + echo "is_version_prerelease=$(if [[ $version == *-* ]]; then echo "true"; else echo "false"; fi)" >> $GITHUB_OUTPUT |
| 42 | + |
| 43 | + - name: "Check if pull request exists for this branch" |
| 44 | + id: pr_exists |
| 45 | + env: |
| 46 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 47 | + run: | |
| 48 | + branch_name=${GITHUB_HEAD_REF:-$(echo $GITHUB_REF | sed 's#refs/heads/##')} |
| 49 | + echo "Current branch is '$branch_name'" |
| 50 | + |
| 51 | + pr_json=$(gh pr list --head "$branch_name" --state open --json number --limit 1) |
| 52 | + pr_number=$(echo "$pr_json" | jq -r '.[0].number // empty') |
| 53 | + |
| 54 | + if [[ -n "$pr_number" ]]; then |
| 55 | + echo "Pull request exists: #$pr_number" |
| 56 | + echo "does_pull_request_exist=true" >> $GITHUB_OUTPUT |
| 57 | + echo "pr_number=$pr_number" >> $GITHUB_OUTPUT |
| 58 | + else |
| 59 | + echo "Pull request doesn't exist" |
| 60 | + echo "does_pull_request_exist=false" >> $GITHUB_OUTPUT |
| 61 | + echo "pr_number=" >> $GITHUB_OUTPUT |
| 62 | + fi |
| 63 | + |
| 64 | + - name: "List variables" |
| 65 | + run: | |
| 66 | + export BUILD_DATETIME_LONDON="${{ steps.variables.outputs.build_datetime_london }}" |
| 67 | + export BUILD_DATETIME="${{ steps.variables.outputs.build_datetime }}" |
| 68 | + export BUILD_TIMESTAMP="${{ steps.variables.outputs.build_timestamp }}" |
| 69 | + export BUILD_EPOCH="${{ steps.variables.outputs.build_epoch }}" |
| 70 | + export NODEJS_VERSION="${{ steps.variables.outputs.nodejs_version }}" |
| 71 | + export PYTHON_VERSION="${{ steps.variables.outputs.python_version }}" |
| 72 | + export TERRAFORM_VERSION="${{ steps.variables.outputs.terraform_version }}" |
| 73 | + export VERSION="${{ steps.variables.outputs.version }}" |
| 74 | + export DOES_PULL_REQUEST_EXIST="${{ steps.pr_exists.outputs.does_pull_request_exist }}" |
| 75 | + export IS_VERSION_PRERELEASE="${{ steps.variables.outputs.is_version_prerelease }}" |
| 76 | + make list-variables |
| 77 | + |
| 78 | + publish: |
| 79 | + name: "Publish packages" |
| 80 | + runs-on: ubuntu-latest |
| 81 | + timeout-minutes: 10 |
| 82 | + needs: [metadata] |
| 83 | + env: |
| 84 | + build_datetime: "${{ needs.metadata.outputs.build_datetime }}" |
| 85 | + build_timestamp: "${{ needs.metadata.outputs.build_timestamp }}" |
| 86 | + build_epoch: "${{ needs.metadata.outputs.build_epoch }}" |
| 87 | + nodejs_version: "${{ needs.metadata.outputs.nodejs_version }}" |
| 88 | + python_version: "${{ needs.metadata.outputs.python_version }}" |
| 89 | + terraform_version: "${{ needs.metadata.outputs.terraform_version }}" |
| 90 | + version: "${{ needs.metadata.outputs.version }}" |
| 91 | + is_version_prerelease: "${{ needs.metadata.outputs.is_version_prerelease }}" |
| 92 | + |
| 93 | + steps: |
| 94 | + - name: "Checkout code" |
| 95 | + uses: actions/checkout@v5 |
| 96 | + |
| 97 | + - name: "Get artifacts: jekyll docs" |
| 98 | + uses: actions/download-artifact@v5 |
| 99 | + with: |
| 100 | + path: ./artifacts/jekyll-docs-${{ env.version }} |
| 101 | + name: jekyll-docs-${{ env.version }} |
| 102 | + |
| 103 | + - name: "Get artifacts: schema" |
| 104 | + uses: actions/download-artifact@v5 |
| 105 | + with: |
| 106 | + path: ./artifacts/schemas-${{ env.version }} |
| 107 | + name: schemas-${{ env.version }} |
| 108 | + |
| 109 | + |
| 110 | + - name: Draft Release |
| 111 | + env: |
| 112 | + GH_TOKEN: ${{ github.token }} |
| 113 | + GH_REPO: ${{ github.repository }} |
| 114 | + VERSION: ${{ env.version }} |
| 115 | + IS_PRERELEASE: ${{ env.is_version_prerelease }} |
| 116 | + run: | |
| 117 | + PRERELEASE_FLAG="" |
| 118 | + if [ "$IS_PRERELEASE" = "true" ]; then |
| 119 | + PRERELEASE_FLAG="--prerelease" |
| 120 | + fi |
| 121 | + gh release create \ |
| 122 | + "$VERSION" \ |
| 123 | + --draft \ |
| 124 | + --latest \ |
| 125 | + --title "$VERSION" \ |
| 126 | + --notes "Release of $VERSION" \ |
| 127 | + $PRERELEASE_FLAG |
| 128 | + |
| 129 | + - name: "Upload jeykll docs release asset" |
| 130 | + env: |
| 131 | + GH_TOKEN: ${{ github.token }} |
| 132 | + GH_REPO: ${{ github.repository }} |
| 133 | + VERSION: ${{ env.version }} |
| 134 | + run: | |
| 135 | + cp ./artifacts/jekyll-docs-$VERSION/artifact.tar $RUNNER_TEMP/jekyll-docs-$VERSION.tar |
| 136 | + gh release upload \ |
| 137 | + "$VERSION" \ |
| 138 | + $RUNNER_TEMP/jekyll-docs-$VERSION.tar#jekyll-docs-$VERSION |
| 139 | + |
| 140 | + - name: "Upload schema release asset" |
| 141 | + env: |
| 142 | + GH_TOKEN: ${{ github.token }} |
| 143 | + GH_REPO: ${{ github.repository }} |
| 144 | + VERSION: ${{ env.version }} |
| 145 | + run: | |
| 146 | + cp ./artifacts/schemas-$VERSION/artifact.tar $RUNNER_TEMP/schemas-$VERSION.tar |
| 147 | + gh release upload \ |
| 148 | + "$VERSION" \ |
| 149 | + $RUNNER_TEMP/schemas-$VERSION.tar#schemas-$VERSION |
| 150 | + |
| 151 | + |
| 152 | + - name: Publish Release |
| 153 | + env: |
| 154 | + GH_TOKEN: ${{ github.token }} |
| 155 | + GH_REPO: ${{ github.repository }} |
| 156 | + VERSION: ${{ env.version }} |
| 157 | + run: gh release edit "$VERSION" --draft=false |
0 commit comments