|
| 1 | +name: Build and Test |
| 2 | + |
| 3 | +on: [push, pull_request] |
| 4 | + |
| 5 | +jobs: |
| 6 | + build-and-test: |
| 7 | + name: Build and Test |
| 8 | + runs-on: ubuntu-latest |
| 9 | + outputs: |
| 10 | + ksp-version: ${{ steps.set-ksp-version.outputs.ksp-version }} |
| 11 | + release-package-name: ${{ steps.set-release-package-name.outputs.release-package-name }} |
| 12 | + release-changelog: ${{ steps.extract-single-changelog.outputs.changelog-single }} |
| 13 | + steps: |
| 14 | + - name: Checkout code |
| 15 | + uses: actions/checkout@v2 |
| 16 | + with: |
| 17 | + fetch-depth: 100 |
| 18 | + - name: Fetch master |
| 19 | + run: git fetch --depth=100 origin master |
| 20 | + - name: Fetch tags |
| 21 | + run: git fetch --depth=1 --tags origin |
| 22 | + - name: Describe current revision with tags |
| 23 | + id: describe-tags |
| 24 | + run: | |
| 25 | + GIT_TAGISH="$(git describe --tags)" |
| 26 | + echo "${GIT_TAGISH}" |
| 27 | + echo "::set-output name=git-tagish::${GIT_TAGISH}" |
| 28 | + - name: Install Ruby |
| 29 | + uses: ruby/setup-ruby@v1 |
| 30 | + - name: Install NuGet |
| 31 | + uses: nuget/setup-nuget@v1 |
| 32 | + - name: Install Gems |
| 33 | + run: bundle install |
| 34 | + - name: Install NuGet packages |
| 35 | + run: nuget restore |
| 36 | + - name: Set KSP Version |
| 37 | + id: set-ksp-version |
| 38 | + run: | |
| 39 | + KSP_VERSION="$(cat ./KSP_VERSION)" |
| 40 | + echo "KSP Version: ${KSP_VERSION}" |
| 41 | + echo "::set-output name=ksp-version::${KSP_VERSION}" |
| 42 | + - name: Download KSP DLLs |
| 43 | + id: download-ksp-dlls |
| 44 | + run: | |
| 45 | + aws --no-sign-request --region us-east-1 s3 cp s3://blowfish-ksp-dlls/ksp-${{ steps.set-ksp-version.outputs.ksp-version }}.zip '/tmp/KSP_DLLs.zip' |
| 46 | + KSP_DLL_PATH="/opt/ksp/assembly/${{ steps.set-ksp-version.outputs.ksp-version }}" |
| 47 | + echo "::set-output name=ksp-dll-path::${KSP_DLL_PATH}" |
| 48 | + mkdir -p "${KSP_DLL_PATH}" |
| 49 | + unzip '/tmp/KSP_DLLs.zip' -d "${KSP_DLL_PATH}" |
| 50 | + rm '/tmp/KSP_DLLs.zip' |
| 51 | + - name: Run Rubocop |
| 52 | + run: bundle exec rubocop |
| 53 | + - name: Compile Project |
| 54 | + run: msbuild /p:Configuration=Release /p:ReferencePath="${{ steps.download-ksp-dlls.outputs.ksp-dll-path }}" |
| 55 | + - name: Run Unit Tests |
| 56 | + run: mono packages/xunit.runner.console.*/tools/net471/xunit.console.exe B9PartSwitchTests/bin/Release/B9PartSwitchTests.dll |
| 57 | + - name: Extract Changelog |
| 58 | + run: | |
| 59 | + curl 'https://raw.githubusercontent.com/wiki/blowfishpro/B9PartSwitch/Changelog.md' -o "${RUNNER_TEMP}/B9PartSwitch-Changelog-all.md" |
| 60 | + bundle exec extract-changelog -u "$(git describe --tags)" -i "${RUNNER_TEMP}/B9PartSwitch-Changelog-all.md" -o "${RUNNER_TEMP}/B9PartSwitch-Changelog-current.md" |
| 61 | + - name: Extract changelog for current release |
| 62 | + id: extract-single-changelog |
| 63 | + if: startsWith(github.ref, 'refs/tags/v') |
| 64 | + shell: bash |
| 65 | + run: | |
| 66 | + CHANGELOG_SINGLE_CONTENT="$(bundle exec extract-changelog -s "$(git describe --tags)" -i "${RUNNER_TEMP}/B9PartSwitch-Changelog-all.md")" |
| 67 | + echo '--- Changelog for this version: ---' |
| 68 | + echo "${CHANGELOG_SINGLE_CONTENT}" |
| 69 | + echo '--- End changelog ---' |
| 70 | + CHANGELOG_SINGLE_CONTENT="${CHANGELOG_SINGLE_CONTENT//'%'/'%25'}" |
| 71 | + CHANGELOG_SINGLE_CONTENT="${CHANGELOG_SINGLE_CONTENT//$'\n'/'%0A'}" |
| 72 | + CHANGELOG_SINGLE_CONTENT="${CHANGELOG_SINGLE_CONTENT//$'\r'/'%0D'}" |
| 73 | + echo "::set-output name=changelog-single::${CHANGELOG_SINGLE_CONTENT}" |
| 74 | + - name: Create version file |
| 75 | + id: create-version-file |
| 76 | + run: | |
| 77 | + VERSION_FILE="${RUNNER_TEMP}/B9PartSwitch.version" |
| 78 | + bundle exec fill-version "${GITHUB_WORKSPACE}/templates/B9PartSwitch.version.erb" "${VERSION_FILE}" |
| 79 | + echo "::set-output name=version-file::${VERSION_FILE}" |
| 80 | + - name: Assemble Release |
| 81 | + id: assemble-release |
| 82 | + run: | |
| 83 | + RELEASE_DIR="${RUNNER_TEMP}/release" |
| 84 | + echo "Release dir: ${RELEASE_DIR}" |
| 85 | + mkdir -v "${RELEASE_DIR}" |
| 86 | + echo "::set-output name=release-dir::${RELEASE_DIR}" |
| 87 | + cp -v -R "${GITHUB_WORKSPACE}/GameData" "${RELEASE_DIR}" |
| 88 | + cp -v "${GITHUB_WORKSPACE}/README.md" "${RELEASE_DIR}" |
| 89 | + cp -v "${GITHUB_WORKSPACE}/LICENSE" "${RELEASE_DIR}" |
| 90 | + cp -v "${RUNNER_TEMP}/B9PartSwitch-Changelog-current.md" "${RELEASE_DIR}/CHANGELOG.md" |
| 91 | + cp -v "${GITHUB_WORKSPACE}/README.md" "${RELEASE_DIR}/GameData/B9PartSwitch" |
| 92 | + cp -v "${GITHUB_WORKSPACE}/LICENSE" "${RELEASE_DIR}/GameData/B9PartSwitch" |
| 93 | + cp -v "${RUNNER_TEMP}/B9PartSwitch-Changelog-current.md" "${RELEASE_DIR}/GameData/B9PartSwitch/CHANGELOG.md" |
| 94 | + cp -v "${{ steps.create-version-file.outputs.version-file }}" "${RELEASE_DIR}/GameData/B9PartSwitch/B9PartSwitch.version" |
| 95 | + - name: Set release package name |
| 96 | + id: set-release-package-name |
| 97 | + run: echo "::set-output name=release-package-name::B9PartSwitch_${{ steps.describe-tags.outputs.git-tagish }}" |
| 98 | + - name: Upload result as artifact |
| 99 | + uses: actions/upload-artifact@v1 |
| 100 | + with: |
| 101 | + name: ${{ steps.set-release-package-name.outputs.release-package-name }} |
| 102 | + path: ${{ steps.assemble-release.outputs.release-dir }} |
| 103 | + - name: Verify result |
| 104 | + run: bundle exec rake spec |
| 105 | + release: |
| 106 | + name: Release |
| 107 | + needs: build-and-test |
| 108 | + if: startsWith(github.ref, 'refs/tags/v') |
| 109 | + runs-on: ubuntu-latest |
| 110 | + steps: |
| 111 | + - name: Download release package artifact |
| 112 | + id: download-release |
| 113 | + uses: actions/download-artifact@v2 |
| 114 | + with: |
| 115 | + name: ${{ needs.build-and-test.outputs.release-package-name }} |
| 116 | + path: release/${{ needs.build-and-test.outputs.release-package-name }} |
| 117 | + - name: Upload .version file to S3 |
| 118 | + env: |
| 119 | + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 120 | + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 121 | + run: |
| 122 | + aws --region us-east-1 s3 cp "${{ steps.download-release.outputs.download-path }}/GameData/B9PartSwitch/B9PartSwitch.version" "s3://blowfish-ksp-b9partswitch-avc/versions/$(git describe --tags)/B9PartSwitch.version" |
| 123 | + - name: Package release |
| 124 | + id: package-release |
| 125 | + working-directory: ${{ steps.download-release.outputs.download-path }} |
| 126 | + run: | |
| 127 | + RELEASE_FILENAME="${RUNNER_TEMP}/${{ needs.build-and-test.outputs.release-package-name }}.zip" |
| 128 | + echo "Release filename: ${RELEASE_FILENAME}" |
| 129 | + zip -v -r "${RELEASE_FILENAME}" * |
| 130 | + echo "::set-output name=release-package-filename::${RELEASE_FILENAME}" |
| 131 | + - name: Create release |
| 132 | + id: create-release |
| 133 | + uses: actions/create-release@v1 |
| 134 | + env: |
| 135 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 136 | + with: |
| 137 | + prerelease: true |
| 138 | + tag_name: ${{ github.ref }} |
| 139 | + release_name: B9PartSwitch ${{ github.ref }} for KSP ${{ needs.build-and-test.outputs.ksp-version }} |
| 140 | + body: ${{ needs.build-and-test.outputs.release-changelog }} |
| 141 | + - name: Upload package to release |
| 142 | + uses: actions/upload-release-asset@v1 |
| 143 | + env: |
| 144 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 145 | + with: |
| 146 | + upload_url: ${{ steps.create-release.outputs.upload_url }} |
| 147 | + asset_path: ${{ steps.package-release.outputs.release-package-filename }} |
| 148 | + asset_name: ${{ needs.build-and-test.outputs.release-package-name }}.zip |
| 149 | + asset_content_type: application/zip |
| 150 | + - name: Print release url |
| 151 | + run: echo "Release successful! You can view it at ${{ steps.create-release.outputs.html_url }}" |
0 commit comments