github 自动化集成_如何自动化您的GitHub个人资料自述文件

github 自动化集成

GitHub’s new profile page README feature is bringing some personality to the Myspace pages of the developer Internet.

GitHub的新个人资料页面README功能为开发人员Internet的Myspace页面带来了一些个性。

Though Markdown lends itself best to standard static text content, that’s not stopping creative folks from working to create a next-level README. You can include GIFs and images to add some motion and pizazz (they’re covered in GitHub Flavor Markdown), but I’m thinking of something a little more dynamic.

尽管Markdown最适合标准静态文本内容,但这并不能阻止有创造力的人们创建新的自述文件。 您可以包括GIF和图像以添加一些运动和爵士乐(它们在GitHub Flavor Markdown中已介绍 ),但是我在想一些更动态的东西。

Since it's front-and-center on your GitHub profile, your README is a great opportunity to let folks know what you’re about, what you find important, and to showcase some highlights of your work.

由于自述文件位于GitHub个人资料的中心位置,因此它是一个很好的机会,可以让人们知道您的意思,发现的重要内容并展示您的工作重点。

You might like to show off your latest repositories, tweets, or blog posts. Keeping it up to date doesn’t have to be a pain either, thanks to continuous delivery tools like GitHub Actions.

您可能想要炫耀最新的存储库,tweet或博客文章。 借助GitHub Actions等持续交付工具,保持最新状态也不是一件容易的事。

My current README refreshes itself daily with a link to my latest blog post. Here’s how I built a self-updating README.md with Go and GitHub actions.

我当前的自述文件每天都会刷新自己,并提供指向我最新博客文章的链接。 这是我使用Go和GitHub操作构建自更新README.md

使用Go读写文件 (Reading and writing files with Go)

I’ve been writing a lot of Python lately, but for some things I really like using Go. You could say it’s my go-to language for just-for-func projects. Sorry. Couldn’t stop myself.

最近我一直在写很多Python,但是对于某些事情,我真的很喜欢使用Go。 您可以说这是我针对func项目的首选语言。 抱歉。 无法阻止自己。

To create my README.md, I’m going to get some static content from an existing file, mash it together with some new dynamic content that we’ll generate with Go, then bake the whole thing at 400 degrees until something awesome comes out.

要创建我的README.md,我将从现有文件中获取一些静态内容,将其与我们将通过Go生成的一些新动态内容融合在一起,然后将整个内容烘焙到400度,直到出现很棒的内容。

Here’s how we read in a file called static.md and put it in string form:

这是我们读取名为static.md的文件并将其以string形式放入的方式:

// Unwrap Markdown content
content, err := ioutil.ReadFile("static.md")
if err != nil {
    log.Fatalf("cannot read file: %v", err)
    return err
}

// Make it a string
stringyContent := string(content)

The possibilities for your dynamic content are only limited by your imagination! Here, I’ll use the github.com/mmcdole/gofeed package to read the RSS feed from my blog and get the newest post.

动态内容的可能性仅受您的想象力限制! 在这里,我将使用github.com/mmcdole/gofeed 从我的博客中阅读RSS feed并获得最新的帖子。

fp := gofeed.NewParser()
feed, err := fp.ParseURL("https://victoria.dev/index.xml")
if err != nil {
    log.Fatalf("error getting feed: %v", err)
}
// Get the freshest item
rssItem := feed.Items[0]

To join these bits together and produce stringy goodness, we use fmt.Sprintf() to create a formatted string.

为了将这些位连接在一起并产生fmt.Sprintf() ,我们使用fmt.Sprintf()创建格式化的字符串。

// Whisk together static and dynamic content until stiff peaks form
blog := "Read my latest blog post: **[" + rssItem.Title + "](" + rssItem.Link + ")**"
data := fmt.Sprintf("%s\n%s\n", stringyContent, blog)

Then to create a new file from this mix, we use os.Create(). There are more things to know about deferring file.Close(), but we don’t need to get into those details here. We’ll add file.Sync() to ensure our README gets written.

然后使用此混音创建一个新文件,我们使用os.Create()关于推迟file.Close()还有更多的事情要知道 ,但是我们不需要在这里详细介绍。 我们将添加file.Sync()以确保我们的自述文件被写入。

// Prepare file with a light coating of os
file, err := os.Create("README.md")
if err != nil {
    return err
}
defer file.Close()

// Bake at n bytes per second until golden brown
_, err = io.WriteString(file, data)
if err != nil {
    return err
}
return file.Sync()

View the full code here in my README repository.

在我的自述文件存储库中查看完整的代码。

Mmmm, doesn’t that smell good? 🍪 Let’s make this happen on the daily with a GitHub Action.

嗯,那闻起来不好吗? 🍪让我们每天通过GitHub Action做到这一点。

使用Actions按计划运行Go程序 (Running your Go program on a schedule with Actions)

You can create a GitHub Action workflow that triggers both on a push to your master branch as well as on a daily schedule. Here’s a slice of the .github/workflows/update.yaml that defines this:

您可以创建GitHub Action工作流,该工作流既可以在推送到master分支上触发 ,也可以在每日计划上触发 。 这是定义此内容的.github/workflows/update.yaml

on:
  push:
    branches:
      - master
  schedule:
    - cron: '0 11 * * *'

To run the Go program that rebuilds our README, we first need a copy of our files. We use actions/checkout for that:

要运行重建自述文件的Go程序,我们首先需要文件的副本。 我们为此使用actions/checkout

steps:
    - name: 🍽️ Get working copy
      uses: actions/checkout@master
      with:
        fetch-depth: 1

This step runs our Go program:

此步骤运行我们的Go程序:

- name: 🍳 Shake & bake README
  run: |
    cd ${GITHUB_WORKSPACE}/update/
    go run main.go

Finally, we push the updated files back to our repository. Learn more about the variables shown at Using variables and secrets in a workflow.

最后,我们将更新后的文件推回到存储库中。 了解有关在工作流使用变量和机密中显示的变量的更多信息。

- name: 🚀 Deploy
  run: |
    git config user.name "${GITHUB_ACTOR}"
    git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
    git add .
    git commit -am "Update dynamic content"
    git push --all -f https://${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git

View the full code for this Action workflow here in my README repository.

在我的README存储库中,查看此Action工作流的完整代码。

继续并自动更新您的自述文件 (Go forth and auto-update your README)

Congratulations and welcome to the cool kids’ club! You now know how to build an auto-updating GitHub profile README. You may now go forth and add all sorts of neat dynamic elements to your page – just go easy on the GIFs, okay?

恭喜并欢迎您进入酷酷的儿童俱乐部! 现在,您知道了如何构建自动更新的GitHub个人资料README。 现在,您可以继续向页面添加各种巧妙的动态元素-只需轻松处理GIF,好吗?

翻译自: https://www.freecodecamp.org/news/go-automate-your-github-profile-readme/

github 自动化集成

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值