{
"path": "/posts/deploying-aspnet-mvc-to-github-pages-with-appveyor-part-2",
"site": "at://did:plc:yy3apqjlms24kso7ahn7lbmb/site.standard.publication/3mova7c4nho2b",
"tags": [
"asp.net"
],
"$type": "site.standard.document",
"title": "Deploying from ASP.Net MVC to GitHub Pages using AppVeyor part 2",
"description": "To save time, automating open source projects is key. Using AppVeyor and creating static sites with tools like Wget can help update documentation.",
"publishedAt": "2015-01-07T00:00:00.000Z",
"textContent": "\"Automation, automation, automation.\" Those were and are Tony Blair's priorities for keeping open source projects well maintained.\n\n\n\nOK, that's not quite true... But what is certainly true is that maintaining an open source project takes time. And there's only so much free time that anyone has. For that reason, wherever you can it makes sense to _AUTOMATE_!\n\nLast time we looked at how you can take an essentially static ASP.Net MVC site (in this case my jVUNDemo documentation site) and generate an entirely static version using Wget. This static site has been pushed to GitHub Pages and is serving as the documentation for jQuery Validation Unobtrusive Native (and for bonus points is costing me no money at all).\n\nSo what next? Well, automation clearly! If I make a change to jQuery Validation Unobtrusive Native then AppVeyor already bounds in and performs a continuous integration build for me. It picks up the latest source from GitHub, pulls in my dependencies, performs a build and runs my tests. Lovely.\n\nSo the obvious thing to do is to take this process and plug in the generation of my static site and the publication thereof to GitHub pages. The minute a change is made to my project the documentation should be updated without me having to break sweat. That's the goal.\n\nGitHub Personal Access Token\n\nIn order to complete our chosen mission we're going to need a GitHub Personal Access Token. We're going to use it when we clone, update and push our GitHub Pages branch. To get one we biff over to Settings / Applications in GitHub and click the \"Generate New Token\" button.\n\nThe token I'm using for my project has the following scopes selected:\n\nappveyor.yml\n\nWith our token in hand we turn our attention to AppVeyor build configuration. This is possible using a file called appveyor.yml stored in the root of your repo. You can also use the AppVeyor web UI to do this. However, for the purposes of ease of demonstration I'm using the file approach. The jQuery Validation Unobtrusive Native appveyor.yml looks like this:\n\nThere's a number of things you should notice from the yml file:\n\n- We create 3 environment variables: GithubEmail, GithubUsername and GithubPersonalAccessToken (more on this in a moment).\n- We only build the master branch.\n- We use Chocolatey to install Wget which is used by the makeStatic.ps1 Powershell script.\n- After the tests have completed we run 2 Powershell scripts. First makeStatic.ps1 which builds the static version of our site. This is the exact same script we discussed in the previous post - we're just passing it the build folder this time (one of AppVeyor's environment variables). Second, we run pushStatic.ps1 which publishes the static site to GitHub Pages.\n\nWe pass 4 arguments to pushStatic.ps1: the build folder, my email address, my username and my personal access token. For the sake of security the GithubPersonalAccessToken has been encrypted as indicated by the secure keyword. This is a capability available in AppVeyor here.\n\nThis allows me to mask my personal access token rather than have it available as free text for anyone to grab.\n\npushStatic.ps1\n\nFinally we can turn our attention to how our Powershell script pushStatic.ps1 goes about pushing our changes up to GitHub Pages:\n\nSo what's happening here? Let's break it down:\n\n- Git is configured with the passed in username and email address.\n- A folder is created that sits alongside the build folder called \"gh-pages\".\n- We clone the \"gh-pages\" branch of jQuery Validation Unobtrusive Native into our \"gh-pages\" directory. You'll notice that we are using our GitHub personal access token in the clone URL itself.\n- We delete the contents of the \"gh-pages\" directory leaving it empty.\n- We copy across the contents of the \"static-site\" folder (created by makeStatic.ps1) into the \"gh-pages\".\n- We use git status to check if there are any changes. (This method is completely effective but a little crude to my mind - there's probably better approaches to this.... shout me in the comments if you have a suggestion.)\n- If we have no changes then we do nothing.\n- If we have changes then we stage them, commit them and push them to GitHub Pages. Then we sign off with an allusion to 80's East Coast hip-hop>)... 'Cos that's how we roll.\n\nWith this in place, any changes to the docs will be automatically published out to our \"gh-pages\" branch. Our documentation will always be up to date thanks to the goodness of AppVeyor's Continuous Integration service.",
"canonicalUrl": "https://johnnyreilly.com/posts/deploying-aspnet-mvc-to-github-pages-with-appveyor-part-2"
}