Guard against initial failure #158
This file contains 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
name: Build | |
on: | |
push: | |
env: | |
SDK_ERROR_MESSAGES_VERSION: "master" | |
PACKAGE_SOURCE: https://nuget.pkg.github.com/tatumio/index.json | |
PUB_PACKAGE_SOURCE: https://api.nuget.org/v3/index.json | |
PROJECT_PATH: ./Tatum/Tatum.csproj | |
DEMO_APP_PATH: ./Tatum.Demo/Tatum.Demo.csproj | |
jobs: | |
metadata: | |
runs-on: ubuntu-latest | |
outputs: | |
current_branch: ${{ steps.branch-name.outputs.current_branch }} | |
package_version: ${{ steps.package-version.outputs.version }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Get branch name | |
id: branch-name | |
uses: tj-actions/branch-names@v6 | |
- name: Get package version | |
id: package-version | |
run: | | |
stat .version > /dev/null && version=$(<.version) | |
if [[ ${{ steps.branch-name.outputs.current_branch }} == "develop" || ${{ steps.branch-name.outputs.current_branch }} == "v3" ]]; then | |
version=$version-alpha${{ github.run_id }} | |
fi | |
echo "version=$version" >> "$GITHUB_OUTPUT" | |
test: | |
timeout-minutes: 20 | |
runs-on: ubuntu-latest | |
needs: [metadata] | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v3 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: 6.0.x | |
- name: Run Tests | |
run: dotnet test | |
env: | |
INTEGRATION_TEST_APIKEY: ${{ secrets.INTEGRATION_TEST_APIKEY }} | |
NOTIFICATION_TEST_APIKEY: ${{ secrets.NOTIFICATION_TEST_APIKEY }} | |
build: | |
runs-on: ubuntu-latest | |
needs: [metadata, test] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- uses: nuget/setup-nuget@v1 | |
- name: Download SDK error messages | |
uses: wei/curl@v1.1.1 | |
with: | |
args: https://raw.githubusercontent.com/tatumio/tatum-sdk-error-mesages/$SDK_ERROR_MESSAGES_VERSION/error-messages.json --output Tatum.Core/Resources/errorMessages.json | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: 6.0.x | |
- name: Create package - ${{ needs.metadata.outputs.package_version }} | |
run: dotnet pack ${{ env.PROJECT_PATH }} --configuration Release -p:NuspecProperties="version=${{ needs.metadata.outputs.package_version }}" --output . -p:TargetFrameworks=netstandard2.0 | |
- name: Upload build artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: Tatum.${{ needs.metadata.outputs.package_version }}.nupkg | |
path: ./Tatum.${{ needs.metadata.outputs.package_version }}.nupkg | |
retention-days: 7 | |
if: | | |
contains(fromJSON('["main", "develop", "v3"]'), needs.metadata.outputs.current_branch) | |
nuget_github: | |
needs: [metadata, build] | |
if: contains(fromJSON('["main", "develop", "v3"]'), needs.metadata.outputs.current_branch) | |
runs-on: ubuntu-latest | |
steps: | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: 6.0.x | |
- uses: actions/download-artifact@v3 | |
with: | |
name: Tatum.${{ needs.metadata.outputs.package_version }}.nupkg | |
- name: Add source | |
run: dotnet nuget add source --username tatumio --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "${{ env.PACKAGE_SOURCE }}" | |
- name: Push | |
run: dotnet nuget push "Tatum.${{ needs.metadata.outputs.package_version }}.nupkg" --skip-duplicate --api-key ${{ secrets.ACTIONS_PACKAGE_SOURCE_PAT }} --source github | |
test_healthcheck: | |
runs-on: ubuntu-latest | |
if: contains(fromJSON('["main", "v3"]'), needs.metadata.outputs.current_branch) | |
needs: [metadata, nuget_github] | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: 6.0.x | |
- name: Add source | |
run: dotnet nuget add source --username tatumio --password ${{ secrets.ACTIONS_PACKAGE_SOURCE_PAT }} --store-password-in-clear-text --name github "${{ env.PACKAGE_SOURCE }}" | |
- name: Switch dependency to nuget package | |
run: | | |
dotnet remove ${{ env.DEMO_APP_PATH }} reference ${{ env.PROJECT_PATH }} | |
dotnet add ${{ env.DEMO_APP_PATH }} package Tatum --no-restore --version ${{ needs.metadata.outputs.package_version }} | |
- name: Build | |
run: dotnet build ${{ env.DEMO_APP_PATH }} | |
- name: Run healtcheck on Demo app | |
run: ./app_hck.sh | |
env: | |
NOTIFICATION_TEST_APIKEY: ${{ secrets.NOTIFICATION_TEST_APIKEY }} | |
release: | |
if: needs.metadata.outputs.current_branch == 'main' | |
runs-on: ubuntu-latest | |
needs: [metadata, build, test_healthcheck] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Git config | |
run: | | |
git config --local user.name github-actions | |
git config --local user.email github-actions@github.com | |
- name: Get latest release | |
id: get_latest_release | |
run: | | |
latest_tag=$(curl -s --max-time 5 https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/latest | jq -r '.tag_name') | |
echo "LATEST_RELEASE_TAG=$latest_tag" >> $GITHUB_ENV | |
- name: Ensure package version is updated | |
run: | | |
[ "${{needs.metadata.outputs.package_version}}" = "${{env.LATEST_RELEASE_TAG}}" ] && echo "Error: Package version is the same as the latest release" && exit 1 || exit 0 | |
- name: Get release notes | |
id: get_release_notes | |
uses: ffurrer2/extract-release-notes@v1 | |
# TAG the repo | |
- name: Create tag ${{ needs.metadata.outputs.package_version }} | |
uses: rickstaa/action-create-tag@v1 | |
with: | |
tag: "${{ needs.metadata.outputs.package_version }}" | |
- name: "Create a GitHub release ${{ needs.metadata.outputs.package_version }}" | |
# Create release using the tag above | |
uses: ncipollo/release-action@v1 | |
with: | |
tag: "${{needs.metadata.outputs.package_version}}" | |
name: "${{needs.metadata.outputs.package_version}}" | |
body: | | |
${{ steps.get_release_notes.outputs.release_notes }} | |
nuget: | |
if: needs.metadata.outputs.current_branch == 'main' | |
runs-on: ubuntu-latest | |
needs: [metadata, build, test_healthcheck] | |
steps: | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: 6.0.x | |
- uses: actions/download-artifact@v3 | |
with: | |
name: Tatum.${{ needs.metadata.outputs.package_version }}.nupkg | |
- name: Push to ${{ steps.set_source.outputs.pkg_src_short_name }} | |
run: dotnet nuget push "./Tatum.${{ needs.metadata.outputs.package_version }}.nupkg" --skip-duplicate --api-key ${{ secrets.NUGET_PUBLISH_KEY }} --source ${{ env.PUB_PACKAGE_SOURCE }} |