check-and-update #1054
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: check-and-update | |
on: | |
schedule: | |
- cron: "27 1,9,16 * * *" | |
jobs: | |
check-and-update: | |
runs-on: ubuntu-latest | |
steps: | |
- name: checkout | |
uses: actions/checkout@v3 | |
with: | |
ref: "main" | |
fetch-depth: 0 | |
- name: check for update | |
run: ./scripts/check_for_updates.sh | |
id: check | |
- name: download | |
run: ./scripts/download_and_unzip.sh | |
if: steps.check.outputs.updated == 'true' | |
- name: setup go | |
uses: actions/setup-go@v3 | |
with: | |
go-version: ^1.18 | |
id: go | |
if: steps.check.outputs.updated == 'true' | |
- name: convert | |
run: ./scripts/convert.sh | |
if: steps.check.outputs.updated == 'true' | |
- name: clean | |
run: ./scripts/clean.sh | |
if: steps.check.outputs.updated == 'true' | |
- name: create tag dry run | |
id: tag_version_dry | |
uses: mathieudutour/github-tag-action@v6.1 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
dry_run: true | |
if: steps.check.outputs.updated == 'true' | |
- name: version up | |
run: | | |
sed -i -E 's/^var Version = \"(v[0-9]+\.[0-9]+\.[0-9]+)\"/var Version = "${{ steps.tag_version_dry.outputs.new_tag }}"/' main.go | |
sed -i -E 's/^ENV VERSION (v[0-9]+\.[0-9]+\.[0-9]+)/ENV VERSION ${{ steps.tag_version_dry.outputs.new_tag }}/' Dockerfile | |
grep "^var Version" main.go | |
grep "^ENV VERSION" Dockerfile | |
- name: diff | |
id: diff | |
run: | | |
git diff --name-only --exit-code | |
continue-on-error: true | |
if: steps.check.outputs.updated == 'true' | |
- name: commit & push | |
run: | | |
git status -sb | |
git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
git config --local user.name "github-actions[bot]" | |
git add . | |
git commit -m "update zip code data" | |
git push | |
if: steps.check.outputs.updated == 'true' && steps.diff.outcome == 'failure' | |
- name: export commit hash | |
run: | | |
hash=`git rev-parse HEAD` | |
echo "hash=${hash}" >> $GITHUB_OUTPUT | |
id: latest_commit | |
outputs: | |
updated: ${{ steps.check.outputs.updated }} | |
hash: ${{ steps.latest_commit.outputs.hash }} | |
tagging: | |
runs-on: ubuntu-latest | |
needs: check-and-update | |
if: needs.check-and-update.outputs.updated == 'true' | |
steps: | |
- name: checkout | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ needs.check-and-update.outputs.hash }} | |
fetch-depth: 0 | |
- name: create tag and push tag | |
id: tag_version | |
uses: mathieudutour/github-tag-action@v6.1 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
commit_sha: ${{ needs.check-and-update.outputs.hash }} | |
outputs: | |
tag: ${{ steps.tag_version.outputs.new_tag }} | |
changelog: ${{ steps.tag_version.outputs.changelog }} | |
cross-build: | |
runs-on: ubuntu-latest | |
needs: tagging | |
if: needs.check-and-update.outputs.updated == 'true' | |
steps: | |
- name: checkout | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ needs.tagging.outputs.tag }} | |
fetch-depth: 0 | |
- name: cat | |
run: | | |
cat var/last-modified.txt | |
- name: cross build | |
uses: crazy-max/ghaction-xgo@v2 | |
with: | |
xgo_version: latest | |
go_version: 1.18 | |
dest: build | |
prefix: zippia-${{ needs.tagging.outputs.tag }} | |
targets: windows/amd64,linux/amd64,linux/arm64 | |
v: true | |
x: false | |
race: false | |
ldflags: -s -w -extldflags "-static" -X main.Version=${{ needs.tagging.outputs.tag }} | |
buildmode: default | |
trimpath: true | |
if: needs.tagging.outputs.tag | |
- name: chmod & compress | |
run: | | |
( | |
cd build | |
for file in `ls`; do | |
chmod +x $file | |
replaced=`echo $file | sed -E 's/${{ needs.tagging.outputs.tag }}//g' | sed -E "s/^zippia([^.]+)(.exe)?$/zippia\2/"` | |
mv $file $replaced | |
zip -r ${file}.zip $replaced | |
done; | |
) | |
if: needs.tagging.outputs.tag | |
- uses: actions/upload-artifact@v3 | |
with: | |
name: artifacts-by-cross-build | |
path: build/*.zip | |
build-on-mac: | |
runs-on: macos-latest | |
needs: tagging | |
if: needs.check-and-update.outputs.updated == 'true' | |
steps: | |
- name: checkout | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ needs.tagging.outputs.tag }} | |
fetch-depth: 0 | |
- name: setup go | |
uses: actions/setup-go@v2 | |
with: | |
go-version: ^1.18 | |
id: go | |
if: needs.tagging.outputs.tag | |
- name: build | |
run: | | |
go build -ldflags '-s -w -X main.Version=${{ needs.tagging.outputs.tag }}' -trimpath -o build/zippia | |
( | |
cd build | |
zip -r zippia-${{ needs.tagging.outputs.tag }}-darwin-amd64.zip zippia | |
) | |
if: needs.tagging.outputs.tag | |
- uses: actions/upload-artifact@v3 | |
with: | |
name: artifacts-by-mac | |
path: build/*.zip | |
create-releases: | |
runs-on: ubuntu-latest | |
needs: | |
- check-and-update | |
- tagging | |
- cross-build | |
- build-on-mac | |
if: needs.check-and-update.outputs.updated == 'true' | |
steps: | |
- uses: actions/download-artifact@v3 | |
with: | |
name: artifacts-by-cross-build | |
path: build/ | |
if: needs.tagging.outputs.tag | |
- uses: actions/download-artifact@v3 | |
with: | |
name: artifacts-by-mac | |
path: build/ | |
if: needs.tagging.outputs.tag | |
- name: ls | |
run: ls -la build/ | |
- name: Create a GitHub release | |
uses: ncipollo/release-action@v1 | |
with: | |
artifacts: "build/*.zip" | |
tag: ${{ needs.tagging.outputs.tag }} | |
name: Release ${{ needs.tagging.outputs.tag }} | |
body: ${{ needs.tagging.outputs.changelog }} | |
if: needs.tagging.outputs.tag | |
build-and-push-docker-image: | |
runs-on: ubuntu-latest | |
needs: | |
- check-and-update | |
- tagging | |
- create-releases | |
if: needs.check-and-update.outputs.updated == 'true' | |
steps: | |
- name: checkout | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ needs.tagging.outputs.tag }} | |
- name: log-in-to-docherhub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: extract-metadat | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: tetsu040e/zippia | |
tags: | | |
type=semver,pattern={{raw}},value=${{ needs.tagging.outputs.tag }} | |
- name: build-and-push-docker-image | |
uses: docker/build-push-action@v3 | |
with: | |
context: . | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} |